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); }
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(); } }
/// <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); }