public static void RemoveTextStyle(string styleName) { Document document = Active.Document; Database database = document.Database; try { TextStyleTable textStyleTable = GetTextStyleTable(); using (Transaction transaction = database.TransactionManager.StartTransaction()) { foreach (ObjectId textStyleTableRecordId in textStyleTable) { TextStyleTableRecord textStyleTableRecord = transaction.GetObject <TextStyleTableRecord>(textStyleTableRecordId, OpenMode.ForRead); if (textStyleTableRecord.Name == styleName) { textStyleTableRecord.UpgradeOpen(); textStyleTableRecord.Erase(); } } transaction.Commit(); }//using } catch (Exception ex) { Active.WriteMessage(ex.Message); throw; } }
public static void ProcessFont(Document doc) { if (!doc.IsActive) { throw new Exception("只能处理活动状态的Document"); } doc.Editor.WriteMessage("\n正在处理字体。\n"); DateTime start = DateTime.Now; Database db = doc.Database; using (DocumentLock m_DocumentLock = Application.DocumentManager.MdiActiveDocument.LockDocument()) { using (Transaction tr = db.TransactionManager.StartTransaction()) { TextStyleTable tst = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable; foreach (var oid in tst) { TextStyleTableRecord record = (TextStyleTableRecord)oid.GetObject(OpenMode.ForRead); if (record.FileName != "@mc_symbol") { doc.UserData[record.Name] = true; record.UpgradeOpen(); record.FileName = "@mc_symbol"; record.BigFontFileName = "@mc_bigfont"; record.XScale = record.XScale * WIDTH_SCALE; } else { doc.UserData[record.Name] = false; } } // 替换模型空间的实体的文本样式 BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable; BlockTableRecord modelSpace = tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; Redraw(doc, modelSpace); // 替换块定义的文本样式 foreach (ObjectId id in bt) { var btr = (BlockTableRecord)tr.GetObject(id, OpenMode.ForRead); if (!(btr.IsLayout || btr.IsAnonymous || btr.IsFromExternalReference || btr.IsFromOverlayReference)) { Redraw(doc, btr); // 刷新块引用 foreach (ObjectId brId in btr.GetBlockReferenceIds(true, true)) { var br = (BlockReference)tr.GetObject(brId, OpenMode.ForRead); br.RecordGraphicsModified(true); } if (btr.IsDynamicBlock) { foreach (ObjectId btrId in btr.GetAnonymousBlockIds()) { var anonymousBtr = (BlockTableRecord)tr.GetObject(btrId, OpenMode.ForRead); foreach (ObjectId brId in anonymousBtr.GetBlockReferenceIds(true, true)) { var br = (BlockReference)tr.GetObject(brId, OpenMode.ForRead); br.RecordGraphicsModified(true); } } } } } tr.Commit(); } } doc.Editor.WriteMessage("\n处理字体成功,用时{0:f2}s。\n", (DateTime.Now - start).TotalSeconds); }
getPntLabelStyle(string name) { switch (name) { case "BOT": name = "BOT"; break; case "CP": name = "CP"; break; case "CPNT-JOIN": case "CPNT-MISC": case "CPNT-ON": case "CPNT-ST": case "CPNT-TRANS": name = "CPNT"; break; case "SPNT": name = "SPNT"; break; case "UTL-MISC": case "UTL-SD": case "UTL-SEW": case "UTL-WAT": name = "UTL"; break; case "EXIST": name = "EXIST"; break; } LabelStyle ls = null; try { using (Transaction tr = BaseObjs.startTransactionDb()) { Layer.manageLayers(name); Layer.manageLayers(string.Format("{0}-LABEL", name)); if (name == "SPNT") { Layer.manageLayer(string.Format("{0}-LABEL", name), layerOff: false, layerFrozen: false); } else { Layer.manageLayer(string.Format("{0}-LABEL", name), layerOff: false, layerFrozen: true); } LabelStyleCollection labelStyles = BaseObjs._civDoc.Styles.LabelStyles.PointLabelStyles.LabelStyles; if (labelStyles.Contains(name)) { ls = (LabelStyle)tr.GetObject(labelStyles[name], OpenMode.ForRead); if (!ls.Properties.Label.Layer.Value.Contains("-LABEL")) { ls.UpgradeOpen(); ls.Properties.Label.Layer.Value = string.Format("{0}-LABEL", name); } } else { TextStyleTableRecord tstr = Txt.getTextStyleTableRecord("L100"); if (tstr == null) { tstr = Txt.addTextStyleTableRecord("L100"); } else { tstr.UpgradeOpen(); tstr.FileName = "ROMANS"; tstr.XScale = 0.8; } CivilDocument civDoc = BaseObjs._civDoc; ObjectId id = civDoc.Styles.LabelStyles.PointLabelStyles.LabelStyles.Add(name); ls = (LabelStyle)tr.GetObject(id, OpenMode.ForWrite); ls.Properties.DraggedStateComponents.DisplayType.Value = Autodesk.Civil.LabelContentDisplayType.StackedText; ls.Properties.Label.Layer.Value = string.Format("{0}-LABEL", name); removeAllComponents(id); addLocationZcomponent(ls); addDescriptionComponent(ls); addPointNumberComponent(ls); } tr.Commit(); } } catch (System.Exception ex) { BaseObjs.writeDebug(string.Format("{0} Pnt_Style.cs: line: 172", ex.Message)); } return(ls.ObjectId); }