600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > vs-cad二次开发-C#-拖动类-右键选项卡

vs-cad二次开发-C#-拖动类-右键选项卡

时间:2018-08-15 23:04:02

相关推荐

vs-cad二次开发-C#-拖动类-右键选项卡

工具类

class CircleJig : EntityJig{private Point3d m_CenterPt;private double m_Radius = 100.0;public CircleJig(Vector3d normal): base(new Circle()){((Circle)Entity).Center = m_CenterPt;((Circle)Entity).Normal = normal;((Circle)Entity).Radius = m_Radius;}protected override bool Update(){((Circle)Entity).Center = m_CenterPt;((Circle)Entity).Radius = m_Radius;return true;}protected override SamplerStatus Sampler(JigPrompts prompts){JigPromptPointOptions optJig = new JigPromptPointOptions("\n请指定圆的圆心或用右键修改半径");optJig.Keywords.Add("100");optJig.Keywords.Add("200");optJig.Keywords.Add("300");optJig.UserInputControls = UserInputControls.Accept3dCoordinates;PromptPointResult resJig = prompts.AcquirePoint(optJig);Point3d curPt = resJig.Value;if (resJig.Status == PromptStatus.Cancel){return SamplerStatus.Cancel;}if (resJig.Status == PromptStatus.Keyword){switch (resJig.StringResult){case "100":m_Radius = 100;return SamplerStatus.NoChange;case "200":m_Radius = 200;return SamplerStatus.NoChange;case "300":m_Radius = 300;return SamplerStatus.NoChange;}}if (m_CenterPt != curPt){m_CenterPt = curPt;return SamplerStatus.OK;}else{return SamplerStatus.NoChange;}}public Entity getEntity(){return Entity;}}

调用

[CommandMethod("shiyann")]public void shiyann(){Database db = HostApplicationServices.WorkingDatabase;Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;Matrix3d mt = ed.CurrentUserCoordinateSystem;Vector3d normal = mt.CoordinateSystem3d.Zaxis;CircleJig circleJig = new CircleJig(normal);for (;;){PromptResult resJig = ed.Drag(circleJig);if (resJig.Status == PromptStatus.Cancel){return;}if (resJig.Status == PromptStatus.OK){Entity en = circleJig.getEntity();addToModelSpace(db,en);break;}}}

其它工具

public ObjectId addToModelSpace(Database db, Entity ent){//调用时-方法参数列表填写文字写入文字写入位置,以及要写的文字,如果sx与sy有值则采用文字位置为中间点对齐方式ObjectId entId;using (Transaction trans = db.TransactionManager.StartTransaction()){BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);entId = btr.AppendEntity(ent);trans.AddNewlyCreatedDBObject(ent, true);mit();}return entId;}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。