CAD.net二次开发心得体会二---------选择

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zhengxiaotaozz/article/details/85088642

文档的选择用户交互需要用到editor;

Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;

//选择【框选】元素

 PromptSelectionOptions selectionOpts = new PromptSelectionOptions();
                selectionOpts.MessageForAdding = "\n请选择需要统计的元素";
         PromptSelectionResult  selectionRes = ed.GetSelection(selectionOpts);

Transaction tr = doc.TransactionManager.StartTransaction();

if (selectionRes.Status == PromptStatus.OK)
            {

 ObjectId[] objIds = selectionRes.Value.GetObjectIds();

 foreach (ObjectId objId in objIds)
                    {
                        Entity ent = (Entity)tr.GetObject(objId, OpenMode.ForRead);

}

}

//清空选择集

 ed.SetImpliedSelection(new ObjectId[0]);

//判断选择的操作

selectionRes.Status

猜你喜欢

转载自blog.csdn.net/zhengxiaotaozz/article/details/85088642