Example #1
0
        GetClassesDerivedFrom(RXClass searchClassType, ArrayList derivedClasses, bool allowClassesWithoutDxfName)
        {
            Debug.Assert(derivedClasses != null);

            Dictionary dict = SystemObjects.ClassDictionary;

            if (dict != null)
            {
                IEnumerable enumerable = dict as IEnumerable;
                if (enumerable != null)
                {
                    IEnumerator enumerator = enumerable.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        RXClass rxClass = (RXClass)((DictionaryEntry)enumerator.Current).Value;
                        if (rxClass.IsDerivedFrom(searchClassType))
                        {
                            if (!allowClassesWithoutDxfName && ((rxClass.DxfName == null) || (rxClass.DxfName == string.Empty)))
                            {
                                // skip it
                            }
                            else
                            {
                                if (derivedClasses.Contains(rxClass) == false)
                                {
                                    derivedClasses.Add(rxClass);
                                }
                            }
                        }
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// 将指定的块定义变成块参照添加到指定模型空间
        /// </summary>
        /// <param name="block">块定义</param>
        /// <param name="pt">插入点</param>
        /// <param name="db">数据库</param>
        /// <returns></returns>
        public static ObjectId AddToModelSpace(BlockTableRecord block, Point3d pt, Database db)
        {
            ObjectId blkrfid = new ObjectId();

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                BlockTable       bt         = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord modelspace =
                    trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                BlockReference br = new BlockReference(pt, block.ObjectId); // 通过块定义添加块参照
                blkrfid = modelspace.AppendEntity(br);                      //把块参照添加到块表记录
                trans.AddNewlyCreatedDBObject(br, true);                    // 通过事务添加块参照到数据库
                foreach (ObjectId id in block)
                {
                    if (id.ObjectClass.Equals(RXClass.GetClass(typeof(AttributeDefinition))))
                    {
                        AttributeDefinition ad = trans.GetObject(id, OpenMode.ForRead) as AttributeDefinition;
                        AttributeReference  ar =
                            new AttributeReference(ad.Position, ad.TextString, ad.Tag, new ObjectId());
                        br.AttributeCollection.AppendAttribute(ar);
                    }
                }

                trans.Commit();
            }

            return(blkrfid);
        }
Example #3
0
        private List <T> My_GetEntsInModelSpace <T>(Database db, OpenMode mode, bool openErased) where T : Entity
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            //获取类型T代表的DXF代码名用于构建选择集过滤器
            string dxfname = RXClass.GetClass(typeof(T)).DxfName;

            //构建选择集过滤器
            TypedValue[]    values = { new TypedValue((int)DxfCode.Start,   dxfname),
                                       new TypedValue((int)DxfCode.LayoutName, "Model") };
            SelectionFilter filter = new SelectionFilter(values);
            //选择符合条件的所有实体
            PromptSelectionOptions pso = new PromptSelectionOptions();

            pso.MessageForAdding = "\n请选择要统计的实体";
            PromptSelectionResult entSelected = ed.GetSelection(pso, filter);

            if (entSelected.Status != PromptStatus.OK)
            {
                return(null);
            }
            SelectionSet ss   = entSelected.Value;
            List <T>     ents = new List <T>();

            using (Transaction ts = db.TransactionManager.StartTransaction())
            {
                ents.AddRange(ss.GetObjectIds().Select(id => ts.GetObject(id, mode, openErased)).OfType <T>());
            }
            return(ents);
        }
Example #4
0
        public static void AddAttributeReferences(this BlockReference target, Dictionary <string, string> attValues)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }
            Transaction tr = target.Database.TransactionManager.TopTransaction;

            if (tr == null)
            {
                throw new AcRx.Exception(ErrorStatus.NoActiveTransactions);
            }
            BlockTableRecord btr         = (BlockTableRecord)tr.GetObject(target.BlockTableRecord, OpenMode.ForRead);
            RXClass          attDefClass = RXClass.GetClass(typeof(AttributeDefinition));

            foreach (ObjectId id in btr)
            {
                if (id.ObjectClass != attDefClass)
                {
                    continue;
                }
                AttributeDefinition attDef = (AttributeDefinition)tr.GetObject(id, OpenMode.ForRead);
                AttributeReference  attRef = new AttributeReference();
                attRef.SetAttributeFromBlock(attDef, target.BlockTransform);
                if (attValues != null && attValues.ContainsKey(attDef.Tag.ToUpper()))
                {
                    attRef.TextString = attValues[attDef.Tag.ToUpper()];
                }
                target.AttributeCollection.AppendAttribute(attRef);
                tr.AddNewlyCreatedDBObject(attRef, true);
            }
        }
Example #5
0
        /// <summary>
        /// Entity 분해하기
        /// </summary>
        /// <param name="acEnt"></param>
        /// <returns></returns>
        private List <Entity> BreakEntity(Entity acEnt)
        {
            var acDBObjColl = new DBObjectCollection();

            acEnt.Explode(acDBObjColl);

            #region 분해된 객체
            var acObjs = from a in acDBObjColl.Cast <Entity>().ToList()
                         where a.GetRXClass().DxfName != RXClass.GetClass(typeof(BlockReference)).DxfName
                         select a;

            if (acObjs.Any())
            {
                acXEnt.AddRange(acObjs);
            }
            #endregion

            #region 분해 안된 Block 안의 또다른 Block들
            var BlockObjs = from a in acDBObjColl.Cast <Entity>().ToList()
                            where a.GetRXClass().DxfName == RXClass.GetClass(typeof(BlockReference)).DxfName
                            select a;
            #endregion

            return(BlockObjs.Any() ? BlockObjs.ToList() : new List <Entity>());
        }
        void AddPropertyToNodeCollection(TreeNodeCollection nodes, RXClass objectType, string propertyName)
        {
            List <RXClass> objectTypes = new List <RXClass>();

            objectTypes.Add(objectType);
            AddPropertyToNodeCollection(nodes, objectTypes, propertyName);
        }
Example #7
0
        public static List <BaseStairObject> GetStairList()
        {
            Database db = Application.DocumentManager.MdiActiveDocument.Database;

            List <BaseStairObject> listStairs = new List <BaseStairObject>();
            RXClass         rxClass           = RXClass.GetClass(typeof(Solid3d));
            BaseStairObject bso;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTableRecord btRecord = (BlockTableRecord)tr.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForRead);
                foreach (ObjectId id in btRecord)
                {
                    if (id.ObjectClass.IsDerivedFrom(rxClass))
                    {
                        Solid3d sol = (Solid3d)tr.GetObject(id, OpenMode.ForRead);
                        bso = GetStairPropertiesFromSolid(sol);
                        if (bso != null)
                        {
                            listStairs.Add(bso);
                        }
                    }
                    ;
                }
                tr.Commit();
            }
            return(listStairs);
        }
Example #8
0
        /// <summary>
        /// 获取模型空间中类型为T的所有实体
        /// </summary>
        /// <typeparam name="T">实体的类型</typeparam>
        /// <param name="db">数据库对象</param>
        /// <param name="mode">实体打开方式</param>
        /// <param name="openErased">是否打开已删除的实体</param>
        /// <returns>返回模型空间中类型为T的实体</returns>
        public static List <T> GetEntsInModelSpace <T>(this Database db, OpenMode mode, bool openErased) where T : Entity
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            //声明一个List类的变量,用于返回类型为T为的实体列表
            List <T> ents = new List <T>();
            //获取类型T代表的DXF代码名用于构建选择集过滤器
            string dxfname = RXClass.GetClass(typeof(T)).DxfName;

            //构建选择集过滤器
            TypedValue[]    values = { new TypedValue((int)DxfCode.Start,   dxfname),
                                       new TypedValue((int)DxfCode.LayoutName, "Model") };
            SelectionFilter filter = new SelectionFilter(values);
            //选择符合条件的所有实体
            PromptSelectionResult entSelected = ed.SelectAll(filter);

            if (entSelected.Status == PromptStatus.OK)
            {
                //循环遍历符合条件的实体
                foreach (var id in entSelected.Value.GetObjectIds())
                {
                    //将实体强制转化为T类型的对象
                    //不能将实体直接转化成泛型T,必须首先转换成object类
                    T t = (T)(object)id.GetObject(mode, openErased);
                    ents.Add(t);//将实体添加到返回列表中
                }
            }
            return(ents);//返回类型为T为的实体列表
        }
Example #9
0
        static General()
        {
            List <string> bimUsers;

            try
            {
                bimUsers = GetBimUsers();
            }
            catch
            {
                bimUsers = _bimUsers;
            }

            try
            {
                IsBimUser      = bimUsers.Any(u => u.EqualsIgnoreCase(Environment.UserName)) || IsBimUserByUserData();
                ClassAttDef    = RXObject.GetClass(typeof(AttributeDefinition));
                ClassBlRef     = RXObject.GetClass(typeof(BlockReference));
                ClassDBDic     = RXObject.GetClass(typeof(DBDictionary));
                ClassDbTextRX  = RXObject.GetClass(typeof(DBText));
                ClassDimension = RXObject.GetClass(typeof(Dimension));
                ClassHatch     = RXObject.GetClass(typeof(Hatch));
                ClassMLeaderRX = RXObject.GetClass(typeof(MLeader));
                ClassMTextRX   = RXObject.GetClass(typeof(MText));
                ClassPolyline  = RXObject.GetClass(typeof(Polyline));
                ClassRecord    = RXObject.GetClass(typeof(Xrecord));
                ClassRegion    = RXObject.GetClass(typeof(Region));
                ClassVport     = RXObject.GetClass(typeof(Viewport));
            }
            catch
            {
                //
            }
        }
Example #10
0
 public void OverruleStart()
 {
     ObjectOverrule.AddOverrule(
         RXClass.GetClass(typeof(Line)),
         LinePipeDrawOverrule.theOverrule,
         true
         );
     ObjectOverrule.AddOverrule(
         RXClass.GetClass(typeof(Circle)),
         CirclePipeDrawOverrule.theOverrule,
         true
         );
     ObjectOverrule.AddOverrule(
         RXClass.GetClass(typeof(Line)),
         LinePipeTransformOverrule.theOverrule,
         true
         );
     ObjectOverrule.AddOverrule(
         RXClass.GetClass(typeof(Circle)),
         CirclePipeTransformOverrule.theOverrule,
         true
         );
     ObjectOverrule.AddOverrule(
         RXClass.GetClass(typeof(Entity)),
         CopyOverrule.theOverrule,
         true
         );
     Overrule(true);
 }
Example #11
0
        public static IEnumerable <T> GetObjects <T>(this BlockTableRecord btr, OpenMode mode, bool openErased, bool forceOpenOnLockedLayers)
            where T : Entity
        {
            BlockTableRecord   blockTableRecords  = (openErased ? btr.IncludingErased : btr);
            TransactionManager transactionManager = btr.Database.TransactionManager;

            if (typeof(T) != typeof(Entity))
            {
                RXClass @class = RXObject.GetClass(typeof(T));
                foreach (ObjectId objectId in blockTableRecords)
                {
                    if (!(objectId.ObjectClass == @class) && !objectId.ObjectClass.IsDerivedFrom(@class))
                    {
                        continue;
                    }
                    yield return((T)transactionManager.GetObject(objectId, mode, openErased, forceOpenOnLockedLayers));
                }
                @class = null;
            }
            else
            {
                foreach (ObjectId objectId1 in blockTableRecords)
                {
                    yield return((T)transactionManager.GetObject(objectId1, mode, openErased, forceOpenOnLockedLayers));
                }
            }
        }
Example #12
0
        getEntityatPoint(Point3d pnt3d, List <Type> types, string layer, double offset = 0.0)
        {
            int k = types.Count;

            TypedValue[] TVs = new TypedValue[k + 3];

            TVs.SetValue(new TypedValue((int)DxfCode.Operator, "<OR"), 0);

            for (int i = 0; i < types.Count; i++)
            {
                TVs.SetValue(new TypedValue((int)DxfCode.Start, RXClass.GetClass(types[i]).DxfName), i + 1);
            }

            TVs.SetValue(new TypedValue((int)DxfCode.Operator, "OR>"), k + 1);
            TVs.SetValue(new TypedValue((int)DxfCode.LayerName, layer), k + 2);

            SelectionFilter FILTER = new SelectionFilter(TVs);

            Point3d pnt3d1 = new Point3d(pnt3d.X - offset, pnt3d.Y - offset, 0.0);
            Point3d pnt3d2 = new Point3d(pnt3d.X + offset, pnt3d.Y + offset, 0.0);

            PromptSelectionResult PSR = BaseObjs._editor.SelectCrossingWindow(pnt3d1, pnt3d2, FILTER);

            if (PSR.Status == PromptStatus.OK)
            {
                return(PSR.Value.GetObjectIds());
            }
            return(null);
        }
Example #13
0
        /// <summary>
        /// Loops through all entities of the given type in modelspace.
        /// </summary>
        /// <typeparam name="T">Entity type</typeparam>
        /// <param name="database"></param>
        /// <param name="action"></param>
        public static void ForEach <T>(this Database database, Action <T> action) where T : Entity
        {
            try
            {
                RXClass ent_type = RXClass.GetClass(typeof(T));

                using (Transaction tr = database.TransactionManager.StartOpenCloseTransaction())
                {
                    var blocktable = tr.GetObject <BlockTable>(database.BlockTableId, OpenMode.ForRead);
                    var modelspace = tr.GetObject <BlockTableRecord>(blocktable[BlockTableRecord.ModelSpace], OpenMode.ForRead);

                    foreach (ObjectId id in modelspace)
                    {
                        if (id.ObjectClass.IsDerivedFrom(ent_type))
                        {
                            T entity = tr.GetObject <T>(id, OpenMode.ForRead);
                            action(entity);
                        }
                    }
                }
            }
            catch (Autodesk.AutoCAD.Runtime.Exception)
            {
                throw;
            }
            catch (System.Exception)
            {
                throw;
            }
        }
Example #14
0
 // Gets the display name of an object type.
 public static string GetDisplayName(RXClass classObject)
 {
     using (RXObject rawObject = classObject.Create())
     {
         if (classObject.IsDerivedFrom(RXObject.GetClass(typeof(AecDbObject))))
         {
             AecDbObject dbObject = (AecDbObject)rawObject;
             return(dbObject.DisplayName);
         }
         else if (classObject.IsDerivedFrom(RXObject.GetClass(typeof(AecEntity))))
         {
             AecEntity entity = (AecEntity)rawObject;
             return(entity.DisplayName);
         }
         else if (classObject.IsDerivedFrom(RXObject.GetClass(typeof(DBObject))))
         {
             string dxfName = classObject.DxfName;
             if (dxfName == null)
             {
                 return(classObject.Name);
             }
             else
             {
                 return(dxfName);
             }
         }
     }
     throw new ArgumentException("wrong class type");
 }
Example #15
0
        private void listObjectType_Format(object sender, ListControlConvertEventArgs e)
        {
            KeyValuePair <RXClass, List <ObjectId> > pair = (KeyValuePair <RXClass, List <ObjectId> >)e.ListItem;
            RXClass objectType = pair.Key;

            e.Value = ScheduleSample.GetDisplayName(objectType) + "(" + pair.Value.Count.ToString() + ")";
        }
        /// <summary>
        /// 获取用户选择的类型为T的所有实体
        /// </summary>
        /// <typeparam name="T">实体的类型</typeparam>
        /// <param name="db">数据库对象</param>
        /// <param name="mode">实体的打开方式</param>
        /// <param name="openErased">是否打开已删除的实体</param>
        /// <returns>返回类型为T的实体</returns>
        public static List <T> GetSelection <T>(this Database db, OpenMode mode = OpenMode.ForRead, bool openErased = false) where T : Entity
        {
            var result = new List <T>();

            using (var trans = db.TransactionManager.StartOpenCloseTransaction())
            {
                string dxfname = RXClass.GetClass(typeof(T)).DxfName;

                var ed = Application.DocumentManager.MdiActiveDocument.Editor;

                TypedValue[] values = { new TypedValue((int)DxfCode.Start, dxfname) };

                var filter = new SelectionFilter(values);

                var entSelected = ed.GetSelection(filter);

                if (entSelected.Status == PromptStatus.OK)
                {
                    foreach (var id in entSelected.Value.GetObjectIds())
                    {
                        T t = (T)(object)trans.GetObject(id, mode, openErased);

                        result.Add(t);
                    }
                }

                trans.Commit();
            }

            return(result);
        }
Example #17
0
 public static void ViewXData()
 {
     while (true)
     {
         ObjectId id = Interaction.GetEntity("\n选择实体");
         if (id == ObjectId.Null)
         {
             break;
         }
         DBObject obj = id.QOpenForRead();
         using (System.IO.StringWriter sw = new System.IO.StringWriter())
         {
             sw.WriteLine(RXClass.GetClass(obj.GetType()).DxfName);
             var xdata = obj.XData;
             if (xdata != null)
             {
                 TypedValue[] data = obj.XData.AsArray();
                 foreach (TypedValue value in data)
                 {
                     sw.WriteLine(value.ToString());
                 }
             }
             else
             {
                 sw.WriteLine("无扩展数据。");
             }
             Gui.TextReport("XData", sw.ToString(), 300, 300, true);
             //CppImport.RunCommand(false, "textscr");
         }
     }
 }
Example #18
0
        private string GetPolylineIdsAsJSON()
        {
            var     pList   = new List <long>();
            RXClass rxClass = RXClass.GetClass(typeof(Polyline));
            var     db      = BoundDocument.Database;

            using (var tr = db.TransactionManager.StartTransaction())
            {
                var btr = (BlockTableRecord)tr.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForRead);
                var ids =
                    from ObjectId id in btr
                    where id.ObjectClass.IsDerivedFrom(rxClass)
                    select id;

                foreach (var id in ids)
                {
                    using (var pLine = (Polyline)tr.GetObject(id, OpenMode.ForRead))
                    {
                        pList.Add(pLine.Handle.Value);
                    }
                }

                tr.Commit();
            }

            return(JsonConvert.SerializeObject(pList));
        }
Example #19
0
        public static void RemoveProxiesFromDictionary(
            ObjectId dictId, Transaction tr)
        {
            using (ObjectIdCollection ids = new ObjectIdCollection())
            {
                DBDictionary dict =
                    (DBDictionary)tr.GetObject(dictId, OpenMode.ForRead);

                foreach (DBDictionaryEntry entry in dict)
                {
                    RXClass c1 = entry.Value.ObjectClass;
                    RXClass c2 = RXClass.GetClass(typeof(ProxyObject));

                    if (entry.Value.ObjectClass.Name == "AcDbZombieObject")
                    {
                        ids.Add(entry.Value);
                    }
                    else if (entry.Value.ObjectClass ==
                             RXClass.GetClass(typeof(DBDictionary)))
                    {
                        RemoveProxiesFromDictionary(entry.Value, tr);
                    }
                }

                if (ids.Count > 0)
                {
                    dict.UpgradeOpen();

                    foreach (ObjectId id in ids)
                    {
                        RemoveEntry2(dict, id, tr);
                    }
                }
            }
        }
Example #20
0
        public static List <LineSegment3d> getLines(ObjectId[] ids)
        {
            List <LineSegment3d> ll = new List <LineSegment3d>();

            try
            {
                PLDictionary plDic = new PLDictionary();
                // Get the current document and database
                Document acDoc   = Application.DocumentManager.MdiActiveDocument;
                Database acCurDb = acDoc.Database;
                Editor   ed      = acDoc.Editor;
                // Start a transaction
                using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
                {
                    for (int i = 0; i < ids.Length; i++)
                    {
                        if (ids[i].ObjectClass != RXClass.GetClass(typeof(Autodesk.AutoCAD.DatabaseServices.Line)))
                        {
                            continue;
                        }
                        Autodesk.AutoCAD.DatabaseServices.Line line = acTrans.GetObject(ids[i], OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Line;

                        ll.Add(new LineSegment3d(line.StartPoint, line.EndPoint));
                    }
                    ll = ll.Distinct(new My.CompareLineSegment3d()).ToList();// as

                    acTrans.Commit();
                }
            }
            catch (System.Exception ex)
            {
            }
            return(ll);
        }
Example #21
0
        checkForEntityatPoint(Point3d pnt3d, ObjectId idObj, Type type)
        {
            bool match = false;

            TypedValue[] TVs = new TypedValue[1];
            TVs.SetValue(new TypedValue((int)DxfCode.Start, RXClass.GetClass(type).DxfName), 0);
            SelectionFilter FILTER = new SelectionFilter(TVs);

            PromptSelectionResult PSR = BaseObjs._editor.SelectCrossingWindow(pnt3d, pnt3d, FILTER);

            if (PSR.Status == PromptStatus.OK)
            {
                ObjectId[] ids = PSR.Value.GetObjectIds();

                foreach (ObjectId id in ids)
                {
                    if (id == idObj)
                    {
                        match = true;
                        break;
                    }
                }
            }
            return(match);
        }
Example #22
0
        private SelectionSet SelectBlocks()
        {
            RXClass Rxclass = RXClass.GetClass(typeof(BlockReference));

            TypedValue[] tvs = new TypedValue[]
            {
                new TypedValue(Convert.ToInt32(DxfCode.Operator), "<or"),
                new TypedValue(Convert.ToInt32(DxfCode.Start), "INSERT"),           // 블럭
                new TypedValue(Convert.ToInt32(DxfCode.Operator), "or>"),
            };

            SelectionFilter oSf = new SelectionFilter(tvs);

            PromptSelectionResult acPSR = AC.Editor.GetSelection(oSf);

            AC.Editor.WriteMessage("Block 객체 선택");

            if (acPSR.Status != PromptStatus.OK)
            {
                AC.Editor.WriteMessage("\nError in getting selections");
                return(acPSR.Value);
            }

            AC.Doc.GetAcadDocument();

            return(acPSR.Value);
        }
Example #23
0
        getEntityatPoint(Point3d pnt3d, Type type, string layer, double offset = 0.0)
        {
            List <ObjectId> ids = new List <ObjectId>();

            TypedValue[] tvs = new TypedValue[2];

            tvs.SetValue(new TypedValue((int)DxfCode.Start, RXClass.GetClass(type).DxfName), 0);
            tvs.SetValue(new TypedValue((int)DxfCode.LayerName, layer), 1);

            SelectionFilter filter = new SelectionFilter(tvs);
            Point3d         pnt3d1 = new Point3d(pnt3d.X - offset, pnt3d.Y - offset, 0.0);
            Point3d         pnt3d2 = new Point3d(pnt3d.X + offset, pnt3d.Y + offset, 0.0);

            //Draw.addLine(pnt3d1, pnt3d2);

            PromptSelectionResult psr = BaseObjs._editor.SelectCrossingWindow(pnt3d2, pnt3d1, filter);

            if (psr.Status == PromptStatus.OK)
            {
                ObjectId[] idss = psr.Value.GetObjectIds();
                foreach (ObjectId id in idss)
                {
                    ids.Add(id);
                }
            }
            return(ids);
        }
Example #24
0
        public static List <ObjectId> getBlockRefs()
        {
            List <ObjectId> ids = new List <ObjectId>();

            using (var tr = BaseObjs.startTransactionDb())
            {
                var bt =
                    (BlockTable)tr.GetObject(
                        BaseObjs._db.BlockTableId, OpenMode.ForRead);
                var ms =
                    (BlockTableRecord)tr.GetObject(
                        bt[BlockTableRecord.ModelSpace], OpenMode.ForRead);

                RXClass theClass = RXObject.GetClass(typeof(BlockReference));

                foreach (ObjectId id in ms)
                {
                    if (id.ObjectClass.IsDerivedFrom(theClass))
                    {
                        var br =
                            (BlockReference)tr.GetObject(
                                id, OpenMode.ForRead);

                        if (br.Name.ToUpper() == "GRADETAG" || br.Name.ToUpper() == "FLTAG")
                        {
                            ids.Add(br.ObjectId);
                        }
                    }
                }
            }
            return(ids);
        }
        public static void Detach()

        {
            RXClass rxc = Entity.GetClass(typeof(Entity));

            Application.RemoveObjectContextMenuExtension(rxc, cme);
        }
Example #26
0
 ForEach <T>(Action <T> action) where T : Entity
 {
     try
     {
         using (var tr = BaseObjs.startTransactionDb())
         {
             var     blockTable = (BlockTable)tr.GetObject(BaseObjs._db.BlockTableId, OpenMode.ForRead);
             var     modelSpace = (BlockTableRecord)tr.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForRead);
             RXClass theClass   = RXObject.GetClass(typeof(T));
             foreach (ObjectId id in modelSpace)
             {
                 if (id.ObjectClass.IsDerivedFrom(theClass))
                 {
                     try
                     {
                         var ent = (T)tr.GetObject(id, OpenMode.ForRead);
                         action(ent);
                     }
                     catch (System.Exception ex)
                     {
                         BaseObjs.writeDebug(ex.Message + " LdrText_Misc.cs: line: 37");
                     }
                 }
             }
             tr.Commit();
         }
     }
     catch (System.Exception ex)
     {
         BaseObjs.writeDebug(ex.Message + " LdrText_Misc.cs: line: 46");
     }
 }
Example #27
0
        /// <summary>
        /// Loops through all entities of the given type in modelspace.
        /// </summary>
        /// <typeparam name="T">Entity type</typeparam>
        /// <param name="doc"></param>
        /// <param name="action"></param>
        public static void ForEach <T>(this Document doc, Action <T> action) where T : Entity
        {
            Database database = doc.Database;

            try
            {
                RXClass ent_type = RXClass.GetClass(typeof(T));
                Common.UsingModelSpace(doc, (tr, ms) =>
                {
                    Transaction t = tr.Transaction;
                    // Loop through the entities in modelspace
                    foreach (ObjectId id in ms)
                    {
                        // Look for entities of the correct type
                        if (id.ObjectClass.IsDerivedFrom(ent_type))
                        {
                            T entity = t.GetObject <T>(id, OpenMode.ForRead);
                            action(entity);
                        }
                    }
                });
            }
            catch (Autodesk.AutoCAD.Runtime.Exception)
            {
                throw;
            }
            catch (System.Exception)
            {
                throw;
            }
        }
        public List <ObjectId> GetPrimitives()
        {
            List <ObjectId> objCollection = new List <ObjectId>();

            using (Transaction t = targetDB.TransactionManager.StartTransaction())
            {
                for (long i = targetDB.BlockTableId.Handle.Value; i < targetDB.Handseed.Value; i++)
                {
                    ObjectId id = ObjectId.Null;
                    Handle   h  = new Handle(i);
                    targetDB.TryGetObjectId(h, out id);
                    if (!id.ObjectClass.IsDerivedFrom(RXClass.GetClass(typeof(Dimension))))
                    {
                        continue;
                    }
                    if (id.IsErased)
                    {
                        continue;
                    }
                    if (!id.IsValid)
                    {
                        continue;
                    }

                    var op = id.GetType();
                    var k  = id.ObjectClass;
                    objCollection.Add(id);
                }
            }
            return(objCollection);
        }
Example #29
0
        public static void ForEachInAllBlockTableRecords <T>(this Database database, Action <T> action) where T : Entity
        {
            using (var tr = database.TransactionManager.StartTransaction())
            {
                // Get the block table for the current database
                var blockTable = (BlockTable)tr.GetObject(database.BlockTableId, OpenMode.ForRead);

                foreach (ObjectId id in blockTable)
                {
                    // Get the model space block table record
                    var blockTableRecord = (BlockTableRecord)tr.GetObject(id, OpenMode.ForRead);
                    // get theClassType
                    RXClass theClass = RXObject.GetClass(typeof(T));

                    // Loop through the entities in model space
                    foreach (ObjectId objectId in blockTableRecord)
                    {
                        // Look for entities of the correct type
                        if (objectId.ObjectClass.IsDerivedFrom(theClass))
                        {
                            var entity =
                                (T)tr.GetObject(
                                    objectId, OpenMode.ForWrite);

                            action(entity);
                        }
                    }
                }
                tr.Commit();
            }
        }
Example #30
0
 /// <summary>
 /// Initializes a new _instance of the <see cref="DbObjectEnumerator{T}"/> class.
 /// </summary>
 /// <param name="enumerator">The enumerator to wrap.</param>
 /// <param name="transaction">The current transaction.</param>
 /// <param name="openMode">The open mode.</param>
 public DbObjectEnumerator(IEnumerator <ObjectId> enumerator, Transaction transaction, OpenMode openMode)
 {
     _enumerator  = enumerator;
     _transaction = transaction;
     _open_mode   = openMode;
     _ent_type    = RXObject.GetClass(typeof(T));
 }
Example #31
0
 public virtual void ApplyPartialUndo(DwgFiler undoFiler, RXClass classObj)
 {
     createInstance();
     BaseDBObject.ApplyPartialUndo(undoFiler, classObj);
     tr.Dispose();
 }
Example #32
0
 public IntPtr X(RXClass protocolClass)
 {
     createInstance();
     IntPtr X = BaseRXObject.X(protocolClass);
     tr.Dispose();
     return X;
 }