当前位置:   article > 正文

过滤选择集

objectidcollection 如何用

 /// <summary>
        /// 过滤选择集合
        /// 调用方法如: ObjectIdCollection EntityCollection = GetSelection();  
        /// </summary>
        /// <returns>对象集合</returns>
        public static ObjectIdCollection GetSelection()
        {
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;
            Entity entity = null;
            DBObjectCollection entityCollection = new DBObjectCollection();

            // 建立选择的过滤器内容
            TypedValue[] values = new TypedValue[]
            {
                new TypedValue((int)DxfCode.Start,"Text")
            };
            SelectionFilter filter = new SelectionFilter(values);
            PromptSelectionResult optSel = ed.GetSelection(filter);

            if (optSel.Status == PromptStatus.OK)
            {
                using (Transaction transaction = db.TransactionManager.StartTransaction())
                {
                    SelectionSet SS = optSel.Value;
                    foreach (ObjectId id in SS.GetObjectIds())
                    {
                        entity = (Entity)transaction.GetObject(id, OpenMode.ForWrite, true);
                        if (entity != null)
                            entityCollection.Add(entity);
                    }
                    transaction.Commit();
                }
            }

            ObjectIdCollection ids = new ObjectIdCollection();
            foreach (Entity ent in entityCollection)
            {
                ObjectId id = ent.ObjectId;
                ids.Add(id);
            }
            return ids;
        }

转载于:https://www.cnblogs.com/swtool/p/3828989.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/111798
推荐阅读
相关标签
  

闽ICP备14008679号