分享
 
 
 

DOTNETARX(一个用于.net开发AutoCAD程序的类库)实例教学(续)

王朝c#·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

本来已写好中文的,但不知怎么搞的,给弄丢了。先把英文的给发上来,等过段时间我再发中文的。

The following functions is provieded in DOTNETARX 2.1.

AddBlockTableRecordIn DOTNETARX,you can add the symbol table record using the AddSymbolTableRecord() function.But the BlockTableRecord is different from the other symbol table records.So,you must use the AddBlockTableRecord() function to add the BlockTableRecord.AddBlockTableRecord() function has two forms.The first one takes the Entity array as its argument (which represents the entities that have not added into the AutoCAD database).If you want to add the entities on the screen into the Block Table Record,you will have to use the second one.It takes the ObjectId of the entities as its argument.

The following example show you how to use AddBlockTableRecord() to create Block Table Records.

void Test()

{

Lines line=new Lines(new Point3d(0,0,0),new Point3d(50,50,0));

Circles circle=new Circles(new Point3d(50,50,0),25);

BlockTableRecord btr1=new BlockTableRecord();//Creates a new block table record named block1

btr1.Name="block1";

btr1.Origin=circle.Center;

Tools.AddBlockTableRecord(btr1,new Entity[]{line,circle});

//Adds the line and circle to block1,then adds block1 to the block table of AutoCAD database.

PromptSelectionResult res=Tools.Editor.GetSelection();//Selects objects on the screen.

ObjectIdCollection ids=new ObjectIdCollection(res.Value.GetObjectIds());

//Gets the ObjectIds of the Selected objects.

BlockTableRecord btr2=new BlockTableRecord();//Creates a new block table record named block2

btr2.Name="block2";

btr2.Origin=new Point3d(0,0,0);

Tools.AddBlockTableRecord(btr2,ids);

//Adds the selected objects to block2,then adds block2 to the block table of AutoCAD database.

}

CoordFromPixelToWorld() and CoordFromWorldToPixel()There's no first class .NET API to convert pixel to world coordinates and back.Special thanks to Albert Szilvasy on Autodesk discussion group providing the way to solve this problem. The following example shows you how to use CoordFromPixelToWorld() and CoordFromWorldToPixel() function to convert pixel to world coordinates and back. Note:Inorder to use the two functions,you must add the System.Drawing.dll assembly to your project. void Test()

{

Editor ed=Tools.Editor;

Point3d pt1=ed.GetPoint("\nPlease select a point:").Value;

System.Drawing.Point pix1;//You must add the System.Drawing.dll in the reference of your project.

Tools.CoordFromWorldToPixel(0,ref pt1,out pix1);

ed.WriteMessage("\npixel coordinate is"+pix1.ToString()+",world coordinate is"+pt1.ToString());

System.Drawing.Point pix2=new System.Drawing.Point(100,100);

Point3d pt2;

Tools.CoordFromPixelToWorld(0,pix2,out pt2);

ed.WriteMessage("\npixel coordinate is"+pix2.ToString()+",world coordinate is"+pt2.ToString());

}

GetBoundingBox() In the .NET API,the GeomExtents property of an entity can get the corner points of a box that encloses the 3D extents of the entity.But for DBText and MText,the GeomExtents property always returns the point (0,0,0) for the minpoint of the box.So,DOTNETARX provides the GetBoundingBox() function to let you get the correct corner points of an entity including the DBText and the MText object.The return value of GetBoundingBox() is a Point3d array,[0] is the minimum point of the object's bounding box,[1] is the maximum point of the object's bounding box. The following example shows you how to use GetBoundingBox(). void Test()

{

Editor ed=Tools.Editor;

ObjectId id=ed.GetEntity("Please select an entity on the screen:\n").ObjectId;

//Gets the ObjectId of a selected entity.

Point3d[] pts=Tools.GetBoundingBox(id);//Gets the the two points of a box enclosing the selected entity.

Lines line=new Lines(pts[0],pts[1]);//Creates a line to see the output.

Tools.AddEntity(line);

}

Sendcommand and RegenSendcommand() function sends a command string to the current document for processing.

There is no Regen function in .NET API,so I add the Regen() function in DOTNETARX.

The following example sends a command for evaluation to the AutoCAD command line of a particular drawing. Create a Circle in the active drawing and zoom to display the entire circle.

void Test()

{

Tools.SendCommand("_Circle","2,2,0","4");//You don't need the character "\n" for the Return action.

Tools.SendCommand("_zoom","a");

Tools.Regen(Tools.RegenType.AllViewPorts);//Refresh view

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有