- 积分
- 11621
- 明经币
- 个
- 注册时间
- 2004-10-17
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
本帖最后由 xgr 于 2019-6-4 08:51 编辑
NET可以直接调用CAD2015的命令,但是在按钮的点击事件里调用cad2015命令却出现错误。
成功调用代码:
- [CommandMethod("Test")]
- public static void Test()
- {
- Document doc = Application.DocumentManager.MdiActiveDocument;
- Database db = doc.Database;
- Editor ed = doc.Editor;
- PromptEntityOptions peo = new PromptEntityOptions("\nSelect a curve: ");
- peo.SetRejectMessage("Only a curve.");
- peo.AddAllowedClass(typeof(Curve), false);
- PromptEntityResult per = ed.GetEntity(peo);
- if (per.Status != PromptStatus.OK) return;
- ObjectId curveId = per.ObjectId;
- PromptPointResult ppr = ed.GetPoint("\nBreak point on curve:");
- if (ppr.Status != PromptStatus.OK) return;
- Point3d breakPoint = ppr.Value;
- ed.Command("_.break", curveId, "_first", breakPoint, breakPoint);
-
- using (Transaction tr = db.TransactionManager.StartTransaction())
- {
- ObjectId id = Autodesk.AutoCAD.Internal.Utils.EntLast();
- Entity ent = (Entity) tr.GetObject(id, OpenMode.ForWrite);
- ent.Color = Color.FromColorIndex(ColorMethod.ByAci, 1);
- tr.Commit();
- }
- }
窗口一按钮点击事件,一样的代码
- private void button2_Click(object sender, EventArgs e)
- {
- Document doc = Application.DocumentManager.MdiActiveDocument;
- Database db = doc.Database;
- Editor ed = doc.Editor;
- PromptEntityOptions peo = new PromptEntityOptions("\nSelect a curve: ");
- peo.SetRejectMessage("Only a curve.");
- peo.AddAllowedClass(typeof(Curve), false);
- PromptEntityResult per = ed.GetEntity(peo);
- if (per.Status != PromptStatus.OK) return;
- ObjectId curveId = per.ObjectId;
- PromptPointResult ppr = ed.GetPoint("\nBreak point on curve:");
- if (ppr.Status != PromptStatus.OK) return;
- Point3d breakPoint = ppr.Value;
- ed.Command("_.break", curveId, "_first", breakPoint, breakPoint);
- using (Transaction tr = db.TransactionManager.StartTransaction())
- {
- ObjectId id = Autodesk.AutoCAD.Internal.Utils.EntLast();
- Entity ent = (Entity)tr.GetObject(id, OpenMode.ForWrite);
- ent.Color = Color.FromColorIndex(ColorMethod.ByAci, 1);
- tr.Commit();
- }
- }
结果报错:
************* 异常文本 **************
Autodesk.AutoCAD.Runtime.Exception: eInvalidInput
在 Autodesk.AutoCAD.EditorInput.Editor.Command(Object[] parameter)
|
|