示例#1
0
        static List <ElevationBox> GetElevationBoxes(Transaction transaction)
        {
            var boxes  = new List <ObjectId>();
            var labels = new List <ObjectId>();

            foreach (var objectId in ModelSpace.From(transaction))
            {
                if (IsElevationBoxPolyline(transaction, objectId))
                {
                    boxes.Add(objectId);
                }
                else if (IsElevationBoxLabel(transaction, objectId))
                {
                    labels.Add(objectId);
                }
            }

            var elevationBoxes = BuildElevationBoxesFrom(transaction, boxes, labels);
            var floorTags      = FloorTag.GetFloorTags();

            foreach (var box in elevationBoxes)
            {
                foreach (var floorTag in floorTags)
                {
                    if (box.IsInside(floorTag.Position))
                    {
                        box.FloorTag = floorTag;
                    }
                }
            }

            return(elevationBoxes);
        }
示例#2
0
        public void InsertAt(Point3d position, string model, bool sideWall = false, double angle = 0.0)
        {
            BlockTableRecord record = Define(sideWall);

            var blockRef = new BlockReference(position, Define(sideWall).Id)
            {
                Layer      = Layer,
                ColorIndex = ColorIndices.ByLayer,
                Rotation   = angle,
            };

            ModelSpace.From(transaction).AppendEntity(blockRef);
            transaction.AddNewlyCreatedDBObject(blockRef, true);

            foreach (ObjectId id in record)
            {
                using (var def = id.GetObject(OpenMode.ForRead) as AttributeDefinition)
                {
                    if ((def != null) && (!def.Constant) &&
                        def.Tag.ToUpper() == "MODEL")
                    {
                        using (var ar = new AttributeReference())
                        {
                            ar.SetAttributeFromBlock(def, blockRef.BlockTransform);
                            ar.TextString = $"{model}-{coverage}";
                            ar.Rotation   = 0;

                            blockRef.AttributeCollection.AppendAttribute(ar);
                            transaction.AddNewlyCreatedDBObject(ar, true);
                        }
                    }
                }
            }
        }
示例#3
0
        public static JobData Load()
        {
            using (var trans = ModelSpace.StartTransaction())
            {
                foreach (var objectId in ModelSpace.From(trans))
                {
                    if (IsJobDataBlock(trans, objectId))
                    {
                        var data = new JobData
                        {
                            CalculatedByCompany        = AttributeReader.TextString(trans, objectId, "CALCULATED_BY_COMPANY"),
                            JobNumber                  = AttributeReader.TextString(trans, objectId, "LEAD_NUMBER"),
                            JobName                    = AttributeReader.TextString(trans, objectId, "JOB_NAME"),
                            JobSiteAddress             = AttributeReader.TextString(trans, objectId, "SITE_LOCATION"),
                            SupplyStaticPressure       = AttributeReader.TextString(trans, objectId, "STATIC_PRESSURE"),
                            SupplyResidualPressure     = AttributeReader.TextString(trans, objectId, "RESIDUAL_PRESSURE"),
                            SupplyAvailableFlow        = AttributeReader.TextString(trans, objectId, "AVAILABLE_FLOW"),
                            SupplyElevation            = AttributeReader.TextString(trans, objectId, "METER_ELEVATION"),
                            SupplyPipeLength           = AttributeReader.TextString(trans, objectId, "METER_PIPE_LENGTH"),
                            SupplyPipeInternalDiameter = AttributeReader.TextString(trans, objectId, "METER_PIPE_INTERNAL_DIAMETER"),
                        };

                        return(data);
                    }
                }
            }

            return(null);
        }
示例#4
0
        void InsertAt(Point3d position)
        {
            var labelBlockDef = new BlockReference(position, Define().Id)
            {
                Layer      = "Floor Connectors",
                ColorIndex = ColorIndices.ByLayer
            };

            ModelSpace.From(transaction).AppendEntity(labelBlockDef);
            transaction.AddNewlyCreatedDBObject(labelBlockDef, true);

            transaction.Commit();
        }
示例#5
0
        static List <ObjectId> GetFloorTagIds(Transaction transaction)
        {
            var floorTags = new List <ObjectId>();

            foreach (var objectId in ModelSpace.From(transaction))
            {
                if (IsFloorTagLabel(transaction, objectId))
                {
                    floorTags.Add(objectId);
                }
            }

            return(floorTags);
        }
示例#6
0
        static List <ObjectId> GetRiserLabelIds(Transaction transaction)
        {
            var labels = new List <ObjectId>();

            foreach (var objectId in ModelSpace.From(transaction))
            {
                if (IsRiserLabel(transaction, objectId))
                {
                    labels.Add(objectId);
                }
            }

            return(labels);
        }
示例#7
0
        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);
            }
        }
示例#8
0
        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);
            }
        }