public void GetAlignmentLabelStyle() { CivilDocument civilDoc = CivilApplication.ActiveDocument; using (Transaction trans = Active.Database.TransactionManager.StartTransaction()) { // Get the desired Lable Styles collection LabelStyleCollection lblStyleColl = civilDoc.Styles.LabelStyles.AlignmentLabelStyles.GeometryPointLabelStyles; try { Active.Editor.WriteMessage("\n{0} Labelstyles found.", lblStyleColl.Count); foreach (ObjectId item in lblStyleColl) { LabelStyle style = (LabelStyle)trans.GetObject(item, OpenMode.ForRead); Active.Editor.WriteMessage("\n Expression Name : " + style.Name); } trans.Commit(); } catch (Autodesk.AutoCAD.Runtime.Exception ex) { Active.Editor.WriteMessage("\n Exception message :" + ex.Message); } } }
getPntLabelStyle(string name) { LabelStyle LS = null; ObjectId id = ObjectId.Null; try { using (Transaction tr = BaseObjs.startTransactionDb()) { LabelStyleCollection labelStyles = BaseObjs._civDoc.Styles.LabelStyles.PointLabelStyles.LabelStyles; if (labelStyles.Contains(name)) { LS = (LabelStyle)tr.GetObject(labelStyles[name], OpenMode.ForRead); return(LS.ObjectId); } else { Base_Tools45.Layer.manageLayers(name); TextStyleTableRecord TStr = Base_Tools45.Txt.getTextStyleTableRecord("L100"); if (TStr == null) { TStr = Base_Tools45.Txt.addTextStyleTableRecord("L100"); } TStr.FileName = "ROMANS"; TStr.XScale = 0.8; CivilDocument civDoc = CivilApplication.ActiveDocument; id = civDoc.Styles.LabelStyles.PointLabelStyles.LabelStyles.Add(name); LS = (LabelStyle)tr.GetObject(id, OpenMode.ForWrite); LS.AddComponent("PointNumber", LabelStyleComponentType.Text); ObjectIdCollection ids = LS.GetComponents(LabelStyleComponentType.Text); LabelStyleTextComponent lstc1 = (LabelStyleTextComponent)tr.GetObject(ids[0], OpenMode.ForWrite); lstc1.General.Visible.Value = true; LS.Properties.DraggedStateComponents.DisplayType.Value = Autodesk.Civil.LabelContentDisplayType.StackedText; tr.Commit(); } } } catch (System.Exception ex) { BaseObjs.writeDebug(string.Format("{0} Pnts.cs: line: 133", ex.Message)); } return(id); }
upgradePntLabelStyle(string nameLabelStyle, string nameFontFile = "Romans.shx", double xscale = 0.8) { LabelStyle ls = null; try { using (Transaction tr = BaseObjs.startTransactionDb()) { LabelStyleCollection labelStyles = BaseObjs._civDoc.Styles.LabelStyles.PointLabelStyles.LabelStyles; if (labelStyles.Contains(nameLabelStyle)) { labelStyles.Remove(nameLabelStyle); } //Layer.manageLayers(name); TextStyleTableRecord TStr = Txt.getTextStyleTableRecord("L100"); if (TStr == null) { TStr = Txt.addTextStyleTableRecord("L100"); } TStr.FileName = nameFontFile; TStr.XScale = xscale; CivilDocument civDoc = BaseObjs._civDoc; ObjectId id = civDoc.Styles.LabelStyles.PointLabelStyles.LabelStyles.Add(nameLabelStyle); ls = (LabelStyle)tr.GetObject(id, OpenMode.ForWrite); ls.Properties.DraggedStateComponents.DisplayType.Value = Autodesk.Civil.LabelContentDisplayType.StackedText; addLocationZcomponent(ls); addPointNumberComponent(ls); addDescriptionComponent(ls); tr.Commit(); } } catch (System.Exception ex) { BaseObjs.writeDebug(string.Format("{0} Pnt_Style.cs: line: 254", ex.Message)); } return(ls.ObjectId); }
checkPntLabelStyles() { try { using (Transaction tr0 = BaseObjs.startTransactionDb()) { LabelStyleCollection ids = _pointLabelStyles; Dictionary <string, ObjectId> stylesWith = new Dictionary <string, ObjectId>(); Dictionary <string, ObjectId> stylesWithout = new Dictionary <string, ObjectId>(); int k = ids.Count; using (Transaction tr1 = BaseObjs.startTransactionDb()) { for (int i = 0; i < k; i++) { LabelStyle ls = (LabelStyle)tr1.GetObject(ids[i], OpenMode.ForRead); if (ls.Name.ToUpper().Contains("-LABEL")) { stylesWith.Add(ls.Name, ls.ObjectId); } else { stylesWithout.Add(ls.Name, ls.ObjectId); } } tr1.Commit(); } k = ids.Count; for (int i = k - 1; i > -1; i--) { LabelStyle ls = (LabelStyle)tr0.GetObject(ids[i], OpenMode.ForWrite); if (ls.Name.ToUpper().Contains("-LABEL")) { string name = ls.Name.Replace("-LABEL", ""); if (!stylesWithout.ContainsKey(name)) { //avoid duplicate naming ls.Name = name; } else { if (!ls.IsUsed) { ids.Remove(ls.Name); } else { ids.Remove(name); } } } if (ls.CreateBy.Contains("Autodesk")) { try { if (!ls.IsUsed) { ids.Remove(i); } } catch (System.Exception ex) { BaseObjs.writeDebug(string.Format("{0} Pnt_Style.cs: line: 85", ex.Message)); } } } tr0.Commit(); } } catch (System.Exception ex) { BaseObjs.writeDebug(string.Format("{0} Pnt_Style.cs: line: 94", ex.Message)); } }
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); }
internal static List <Autodesk.AutoCAD.DatabaseServices.DBObject> GetLabelStylesAsDBObjects(Autodesk.AutoCAD.DynamoNodes.Document document, LabelStyleCollection labelStyleCollection) { List <Autodesk.AutoCAD.DatabaseServices.DBObject> dbObjectsList = new List <Autodesk.AutoCAD.DatabaseServices.DBObject>(); Database db = document.AcDocument.Database; foreach (Autodesk.AutoCAD.DatabaseServices.ObjectId labelStyle in labelStyleCollection) { using (Transaction trans = db.TransactionManager.StartTransaction()) { Autodesk.AutoCAD.DatabaseServices.DBObject dbObject = trans.GetObject(labelStyle, OpenMode.ForRead); dbObjectsList.Add(dbObject); trans.Commit(); } } return(dbObjectsList); }
internal static Autodesk.AutoCAD.DatabaseServices.DBObject DBObjectByName(Autodesk.AutoCAD.DynamoNodes.Document document, LabelStyleCollection labelStyleRoot, string labelStyleName) { Autodesk.AutoCAD.DatabaseServices.DBObject retLabels; Database db = document.AcDocument.Database; using (Transaction trans = db.TransactionManager.StartTransaction()) { retLabels = trans.GetObject(labelStyleRoot[labelStyleName], OpenMode.ForRead); trans.Commit(); } return(retLabels); }