コード例 #1
0
ファイル: DWGUtility.cs プロジェクト: tevfikoguz/RebarPos
        // Returns all text styles
        public static Dictionary <string, ObjectId> GetTextStyles()
        {
            Dictionary <string, ObjectId> list = new Dictionary <string, ObjectId>();

            Database db = HostApplicationServices.WorkingDatabase;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                try
                {
                    TextStyleTable        table = (TextStyleTable)tr.GetObject(db.TextStyleTableId, OpenMode.ForRead);
                    SymbolTableEnumerator it    = table.GetEnumerator();
                    while (it.MoveNext())
                    {
                        ObjectId             id    = it.Current;
                        TextStyleTableRecord style = (TextStyleTableRecord)tr.GetObject(id, OpenMode.ForRead);
                        list.Add(style.Name, id);
                    }
                }
                catch (System.Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show("Error: " + ex.Message, "RebarPos", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                }
            }

            return(list);
        }
コード例 #2
0
        public static ObjectId CreateLayer(string name, short color, bool isOff, bool isFrozen, ref bool isNewlyCreated)
        {
            if (!DBManager.ValidateName(name))
            {
                return(ObjectId.Null);
            }
            Database workingDatabase = HostApplicationServices.WorkingDatabase;

            using (Transaction transaction = workingDatabase.TransactionManager.StartTransaction())
            {
                LayerTable layerTable = (LayerTable)transaction.GetObject(workingDatabase.LayerTableId, (OpenMode)0, true);
                ObjectId   objectId;
                if (!layerTable.Has(name))
                {
                    LayerTableRecord layerTableRecord = new LayerTableRecord();
                    layerTableRecord.Name     = (name);
                    layerTableRecord.Color    = (Autodesk.AutoCAD.Colors.Color.FromColorIndex(ColorMethod.ByAci, color));
                    layerTableRecord.IsFrozen = (isFrozen);
                    layerTableRecord.IsOff    = isOff;
                    layerTable.UpgradeOpen();
                    objectId = layerTable.Add(layerTableRecord);
                    transaction.AddNewlyCreatedDBObject(layerTableRecord, true);
                    transaction.Commit();
                    isNewlyCreated = true;
                    ObjectId result = objectId;
                    return(result);
                }
                isNewlyCreated = false;
                objectId       = layerTable[name];
                if (!objectId.IsErased)
                {
                    ObjectId result = objectId;
                    return(result);
                }
                using (SymbolTableEnumerator enumerator = layerTable.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        ObjectId current = enumerator.Current;
                        if (!current.IsErased)
                        {
                            LayerTableRecord layerTableRecord2 = (LayerTableRecord)transaction.GetObject(current, (OpenMode)0, false);
                            if (string.Compare(layerTableRecord2.Name, name, true) == 0)
                            {
                                ObjectId result = current;
                                return(result);
                            }
                        }
                    }
                }
            }
            return(ObjectId.Null);
        }
コード例 #3
0
        public static ObjectId CreateLayer(string name, Color color, bool isFrozen, ref bool isNewlyCreated, Database db)
        {
            if (!DBManager.ValidateName(name))
            {
                return(ObjectId.Null);
            }

            using (Transaction transaction = db.TransactionManager.StartTransaction())
            {
                LayerTable layerTable = (LayerTable)transaction.GetObject(db.LayerTableId, (OpenMode)0, true);
                ObjectId   objectId;
                if (!layerTable.Has(name))
                {
                    LayerTableRecord layerTableRecord = new LayerTableRecord();
                    layerTableRecord.Name     = (name);
                    layerTableRecord.Color    = color;
                    layerTableRecord.IsFrozen = (isFrozen);
                    layerTable.UpgradeOpen();
                    objectId = layerTable.Add(layerTableRecord);
                    transaction.AddNewlyCreatedDBObject(layerTableRecord, true);
                    transaction.Commit();
                    isNewlyCreated = true;
                    ObjectId result = objectId;
                    return(result);
                }
                isNewlyCreated = false;
                objectId       = layerTable[name];
                if (!objectId.IsErased)
                {
                    ObjectId result = objectId;
                    return(result);
                }
                using (SymbolTableEnumerator enumerator = layerTable.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        ObjectId current = enumerator.Current;
                        if (!current.IsErased)
                        {
                            LayerTableRecord layerTableRecord2 = (LayerTableRecord)transaction.GetObject(current, (OpenMode)0, false);
                            if (string.Compare(layerTableRecord2.Name, name, true) == 0)
                            {
                                ObjectId result = current;
                                return(result);
                            }
                        }
                    }
                }
            }
            return(ObjectId.Null);
        }
コード例 #4
0
        private List <string> BuildBlockNameList()
        {
            List <string> list = new List <string>();

            list.Add(AfaStrings.AnyValue);
            Document document = AfaDocData.ActiveDocData.Document;
            Database database = document.Database;

            try
            {
                using (document.LockDocument((DocumentLockMode)20, null, null, false))
                {
                    var transactionManager = database.TransactionManager;
                    using (Transaction transaction = transactionManager.StartTransaction())
                    {
                        BlockTable blockTable = (BlockTable)transaction.TransactionManager.GetObject(database.BlockTableId, 0, false);
                        using (SymbolTableEnumerator enumerator = blockTable.GetEnumerator())
                        {
                            while (enumerator.MoveNext())
                            {
                                ObjectId         current          = enumerator.Current;
                                BlockTableRecord blockTableRecord = (BlockTableRecord)transaction.TransactionManager.GetObject(current, 0, false);
                                if (!blockTableRecord.IsErased && !blockTableRecord.IsAnonymous && !blockTableRecord.Name.StartsWith("*"))
                                {
                                    list.Add(blockTableRecord.Name);
                                }
                            }
                        }
                        transaction.Commit();
                    }
                }
            }
            catch
            {
            }
            list.Add("Select from entity...");
            return(list);
        }
コード例 #5
0
        private List <string> BuildLayerList()
        {
            List <string> list = new List <string>();

            list.Add("*");
            Document document = AfaDocData.ActiveDocData.Document;
            Database database = document.Database;

            try
            {
                using (document.LockDocument((DocumentLockMode)20, null, null, false))
                {
                    var transactionManager = database.TransactionManager;
                    using (Transaction transaction = transactionManager.StartTransaction())
                    {
                        LayerTable layerTable = (LayerTable)transaction.TransactionManager.GetObject(database.LayerTableId, 0, false);
                        using (SymbolTableEnumerator enumerator = layerTable.GetEnumerator())
                        {
                            while (enumerator.MoveNext())
                            {
                                ObjectId         current          = enumerator.Current;
                                LayerTableRecord layerTableRecord = (LayerTableRecord)transaction.TransactionManager.GetObject(current, 0, false);
                                if (!layerTableRecord.IsHidden)
                                {
                                    list.Add(layerTableRecord.Name);
                                }
                            }
                        }
                        transaction.Commit();
                    }
                }
            }
            catch
            {
            }
            list.Add("Select from entity...");
            return(list);
        }
コード例 #6
0
        private static IEnumerable <TResult> GetSymbolTableRecords <TResult, TSymbolTableRecord>(Database db, ObjectId symbolTableId, Func <TSymbolTableRecord, bool> predicate, Func <TSymbolTableRecord, TResult> selector) where TSymbolTableRecord : SymbolTableRecord
        {
            List <TResult> list = new List <TResult>();

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                SymbolTable           table = (SymbolTable)tr.GetObject(symbolTableId, OpenMode.ForRead);
                SymbolTableEnumerator it    = table.GetEnumerator();
                while (it.MoveNext())
                {
                    ObjectId           id    = it.Current;
                    TSymbolTableRecord block = (TSymbolTableRecord)tr.GetObject(id, OpenMode.ForRead);
                    if (predicate(block))
                    {
                        list.Add(selector(block));
                    }
                }

                tr.Commit();
            }

            return(list);
        }
コード例 #7
0
        public void SPlineToLine()
        {
            int    num;
            int    num4;
            object obj;

            try
            {
IL_01:
                ProjectData.ClearProjectError();
                num = -2;
IL_09:
                int num2 = 2;
                Document mdiActiveDocument = Application.DocumentManager.MdiActiveDocument;
IL_16:
                num2 = 3;
                Database database = mdiActiveDocument.Database;
IL_1F:
                num2 = 4;
                using (Transaction transaction = database.TransactionManager.StartTransaction())
                {
                    BlockTable            blockTable = (BlockTable)transaction.GetObject(database.BlockTableId, 1);
                    SymbolTableEnumerator enumerator = blockTable.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        ObjectId                   objectId         = enumerator.Current;
                        BlockTableRecord           blockTableRecord = (BlockTableRecord)transaction.GetObject(objectId, 1);
                        BlockTableRecordEnumerator enumerator2      = blockTableRecord.GetEnumerator();
                        while (enumerator2.MoveNext())
                        {
                            ObjectId objectId2 = enumerator2.Current;
                            Entity   entity    = (Entity)transaction.GetObject(objectId2, 1);
                            if (entity is Spline)
                            {
                                Spline spline = (Spline)entity;
                                Line   e      = new Line(spline.StartPoint, spline.EndPoint);
                                CAD.AddEnt(e);
                                spline.Erase();
                            }
                        }
                        if (enumerator2 != null)
                        {
                            enumerator2.Dispose();
                        }
                    }
                    if (enumerator != null)
                    {
                        enumerator.Dispose();
                    }
                    transaction.Commit();
                }
IL_11B:
                goto IL_187;
IL_11D:
                int num3 = num4 + 1;
                num4     = 0;
                @switch(ICSharpCode.Decompiler.ILAst.ILLabel[], num3);
IL_141:
                goto IL_17C;
IL_143:
                num4 = num2;
                if (num <= -2)
                {
                    goto IL_11D;
                }
                @switch(ICSharpCode.Decompiler.ILAst.ILLabel[], num);
                IL_159 :;
            }
            catch when(endfilter(obj is Exception & num != 0 & num4 == 0))
            {
                Exception ex = (Exception)obj2;

                goto IL_143;
            }
IL_17C:
            throw ProjectData.CreateProjectError(-2146828237);
IL_187:
            if (num4 != 0)
            {
                ProjectData.ClearProjectError();
            }
        }
コード例 #8
0
        public void TcTZZX()
        {
            int    num;
            int    num4;
            object obj;

            try
            {
IL_01:
                ProjectData.ClearProjectError();
                num = -2;
IL_09:
                int num2 = 2;
                Document mdiActiveDocument = Application.DocumentManager.MdiActiveDocument;
IL_16:
                num2 = 3;
                Database database = mdiActiveDocument.Database;
IL_1F:
                num2 = 4;
                using (Transaction transaction = database.TransactionManager.StartTransaction())
                {
                    LinetypeTable linetypeTable = (LinetypeTable)transaction.GetObject(database.LinetypeTableId, 0);
                    if (!linetypeTable.Has("Dote"))
                    {
                        database.LoadLineTypeFile("Dote", "acad.lin");
                    }
                    transaction.Commit();
                }
IL_7F:
                num2 = 6;
                CAD.CreateLayer("Dote", 0, "Dote", 9, false, true);
IL_96:
                num2 = 7;
                using (Transaction transaction2 = database.TransactionManager.StartTransaction())
                {
                    LayerTable            layerTable = (LayerTable)transaction2.GetObject(database.LayerTableId, 0);
                    SymbolTableEnumerator enumerator = layerTable.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        ObjectId         objectId         = enumerator.Current;
                        LayerTableRecord layerTableRecord = (LayerTableRecord)transaction2.GetObject(objectId, 1);
                        if (Operators.CompareString(layerTableRecord.Name.ToUpper(), "DOTE", false) == 0)
                        {
                            layerTableRecord.Color = Color.FromColorIndex(192, 252);
                        }
                        layerTableRecord.LineWeight = 9;
                    }
                    if (enumerator != null)
                    {
                        enumerator.Dispose();
                    }
                    transaction2.Commit();
                }
IL_14F:
                goto IL_1C7;
IL_151:
                int num3 = num4 + 1;
                num4     = 0;
                @switch(ICSharpCode.Decompiler.ILAst.ILLabel[], num3);
IL_181:
                goto IL_1BC;
IL_183:
                num4 = num2;
                if (num <= -2)
                {
                    goto IL_151;
                }
                @switch(ICSharpCode.Decompiler.ILAst.ILLabel[], num);
                IL_199 :;
            }
            catch when(endfilter(obj is Exception & num != 0 & num4 == 0))
            {
                Exception ex = (Exception)obj2;

                goto IL_183;
            }
IL_1BC:
            throw ProjectData.CreateProjectError(-2146828237);
IL_1C7:
            if (num4 != 0)
            {
                ProjectData.ClearProjectError();
            }
        }
コード例 #9
0
ファイル: TeighaText.cs プロジェクト: ian-quinn/manicotti
        /// <summary>
        /// Retreive all text data from dwg file and store them in CADModels
        /// @CreatBridgeForRevit2018
        /// </summary>
        public static List <CADTextModel> GetCADText(string dwgPath)
        {
            List <CADTextModel> listCADModels = new List <CADTextModel>();

            using (new Services())
            {
                using (Database database = new Database(false, false))
                {
                    database.ReadDwgFile(dwgPath, FileShare.Read, true, "");
                    using (var trans = database.TransactionManager.StartTransaction())
                    {
                        using (BlockTable table = (BlockTable)database.BlockTableId.GetObject(OpenMode.ForRead))
                        {
                            using (SymbolTableEnumerator enumerator = table.GetEnumerator())
                            {
                                StringBuilder sb = new StringBuilder();
                                while (enumerator.MoveNext())
                                {
                                    using (BlockTableRecord record = (BlockTableRecord)enumerator.Current.GetObject(OpenMode.ForRead))
                                    {
                                        foreach (ObjectId id in record)
                                        {
                                            Entity       entity = (Entity)id.GetObject(OpenMode.ForRead, false, false);
                                            CADTextModel model  = new CADTextModel();
                                            switch (entity.GetRXClass().Name)
                                            {
                                            case "AcDbText":
                                                DBText text = (DBText)entity;
                                                model.Location = ConverCADPointToRevitPoint(text.Position);
                                                model.Text     = text.TextString;
                                                Debug.Print(model.Text);
                                                model.Angel = text.Rotation;
                                                model.Layer = text.Layer;
                                                listCADModels.Add(model);
                                                break;

                                            case "AcDbMText":
                                                MText mText = (MText)entity;
                                                model.Location = ConverCADPointToRevitPoint(mText.Location);
                                                model.Text     = mText.Text;
                                                model.Angel    = mText.Rotation;
                                                model.Layer    = mText.Layer;
                                                listCADModels.Add(model);
                                                break;

                                            case "AcDbBlockReference":
                                                BlockReference      br     = (BlockReference)entity;
                                                AttributeCollection attcol = br.AttributeCollection;
                                                foreach (ObjectId attId in attcol)
                                                {
                                                    AttributeReference attRef = (AttributeReference)trans.GetObject(attId, OpenMode.ForRead);
                                                    if (IsLabel(attRef.TextString))
                                                    {
                                                        model.Text     = attRef.TextString;
                                                        model.Location = ConverCADPointToRevitPoint(br.Position);
                                                        model.Angel    = br.Rotation;
                                                        model.Layer    = br.Layer;
                                                        listCADModels.Add(model);
                                                    }
                                                }
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(listCADModels);
        }