public static int Run() { var labeler = new Labeler( new LabelSpecs { Tag = "HEADNUMBER", BlockName = "HeadLabel", Layer = "HeadLabels", LayerColorIndex = ColorIndices.Blue }); using (var trans = ModelSpace.StartTransaction()) { foreach (var objectId in ModelSpace.From(trans)) { if (IsLabel(trans, objectId)) { var block = trans.GetObject(objectId, OpenMode.ForWrite) as BlockReference; block.Erase(true); } } trans.Commit(); } using (var trans = ModelSpace.StartTransaction()) { int headNumber = 1; foreach (var objectId in ModelSpace.From(trans)) { if (IsHead(trans, objectId)) { var block = trans.GetObject(objectId, OpenMode.ForRead) as BlockReference; labeler.CreateLabel($"H.{headNumber++}", block.Position); } } trans.Commit(); return(headNumber); } }
public static int LabelAllPipes() { var pipeLabeler = new Labeler( new LabelSpecs { Tag = "PIPENUMBER", BlockName = "PipeLabel", Layer = "PipeLabels", LayerColorIndex = ColorIndices.Blue, TextHeight = 4.0, XOffset = 0.0, YOffset = 0.0, HorizontalMode = TextHorizontalMode.TextCenter }); int pipeNumber = 1; Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(" LabelAllPipes starting..."); var ids = new List <ObjectId>(); using (var trans = ModelSpace.StartTransaction()) { foreach (ObjectId id in ModelSpace.From(trans)) { ids.Add(id); } } using (var trans = ModelSpace.StartTransaction()) { Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(" Finding labels..."); foreach (ObjectId objectId in ids) { if (IsLabel(trans, objectId)) { Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage($" label found, erase block..."); var block = trans.GetObject(objectId, OpenMode.ForWrite) as BlockReference; var blkrefClass = RXObject.GetClass(typeof(BlockReference)); if (block != null && objectId.ObjectClass == blkrefClass) { block.Erase(true); } Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage($" label found, erase DBTtext..."); var text = trans.GetObject(objectId, OpenMode.ForWrite) as DBText; if (text != null) { text.Erase(true); } } } Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(" Finding pipes..."); foreach (ObjectId objectId in ids) { var vertices = new List <Point3d>(); if (IsPipe(trans, objectId)) { var polyline = trans.GetObject(objectId, OpenMode.ForRead) as Polyline; Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage($" Adding {polyline.NumberOfVertices} vertices..."); for (int i = 0; i < polyline.NumberOfVertices; i++) { vertices.Add(polyline.GetPoint3dAt(i)); } pipeNumber++; } Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage($" Creating label: p{pipeNumber}..."); for (int i = 1; i < vertices.Count; i++) { pipeLabeler.CreateLabel( text: $"P{pipeNumber}", position: Midpoint(vertices[i], vertices[i - 1])); } } trans.Commit(); return(pipeNumber); } }
public static void Insert(Point3d point) { var boxes = ElevationBox.InsideElevationBoxes(point); if (boxes.Count == 0) { Editor().WriteMessage("\nError! You must insert a riser inside an elevation box."); return; } if (boxes.Count(b => b.FloorTag != null) != 1) { Editor().WriteMessage("\nError! You must insert a floor tag on each floor."); return; } var floorTag = boxes.Select(b => b.FloorTag).Single(); var offset = new Point3d( x: point.X - floorTag.Position.X, y: point.Y - floorTag.Position.Y, 0); var allFloorTags = FloorTag.GetFloorTags(); if (allFloorTags.Count > 10) { Editor().WriteMessage("\nError! LoopCAD cannot handle more than ten floors."); return; } var selectedFloorTags = new List <FloorTag>() { floorTag }; if (allFloorTags.Count > 1) { var pko = new PromptKeywordOptions(""); foreach (var ft in allFloorTags) { if (ft.Name != floorTag.Name) { pko.Keywords.Add($"{allFloorTags.IndexOf(ft)}: {ft.Name}"); } } pko.Message = "\nChoose floor to run riser pipe to "; pko.AllowNone = false; PromptResult result = Editor().GetKeywords(pko); if (result.Status == PromptStatus.OK) { int floorIndex = int.Parse(result.StringResult[0].ToString()); selectedFloorTags.Add(allFloorTags[floorIndex]); } } if (selectedFloorTags.Count != 2) { Editor().WriteMessage("Error! The riser could not be inserted on two floors."); return; } char suffix = (char)((byte)RiserLabel.HighestSuffix() + 1); int number = RiserLabel.HighestNumber() + 1; foreach (var ft in selectedFloorTags) { // This point will be disposed, so clone it var newPoint = new Point3d( x: ft.Position.X + offset.X, y: ft.Position.Y + offset.Y, z: ft.Position.Z + offset.Z); Riser.Insert(newPoint); var labeler = new Labeler( new LabelSpecs { Tag = RiserLabel.TagName, BlockName = RiserLabel.BlockName, Layer = RiserLabel.LayerName, LayerColorIndex = ColorIndices.Cyan, TextHeight = 8.0, XOffset = 15.0, }); labeler.CreateLabel($"R.{number}.{suffix}", position: newPoint); // Number increments, but suffix is shared between the // upper and lower riser, and used to match them. number++; } }