Ejemplo n.º 1
0
        public JsonLineProperty SetupLineProperty(DBObject item, JsonBlockSetup jsonBlockSetup)
        {
            var jsonLineProperty = new JsonLineProperty();

            jsonLineProperty.Type = Convert.ToString(item);

            if (item is Line)
            {
                var line = item as Line;

                jsonLineProperty.LinePoints.Add(ConvertAcadPoint3dToPoint2D(line.StartPoint, 1));
                jsonLineProperty.LinePoints.Add(ConvertAcadPoint3dToPoint2D(line.EndPoint, 2));
                jsonLineProperty.Layer       = jsonBlockSetup.RealNameFinder(line.Layer);
                jsonLineProperty.Internal_Id = BlockTableRead.InternalCounter;
            }
            else if (item is Polyline)
            {
                var p = item as Polyline;
                for (var i = 0; i < p.NumberOfVertices; i++)
                {
                    var point = p.GetPoint2dAt(i);
                    jsonLineProperty.LinePoints.Add(ConvertAcadPoint2dToPoint2D(point, i + 1));
                    jsonLineProperty.Layer = jsonBlockSetup.RealNameFinder(p.Layer);
                    //System.Diagnostics.Debug.WriteLine($"\t\tPOLYLINE POINTS: {point}");
                }
                p.Closed = false;
                jsonLineProperty.Internal_Id = BlockTableRead.InternalCounter;
            }
            else if (item is Polyline2d)
            {
                var p2d = item as Polyline2d;
                int i   = 1;
                foreach (Vertex2d polyline in p2d)
                {
                    jsonLineProperty.LinePoints.Add(ConvertAcadVertex2DToPoint2D(polyline, i));
                    jsonLineProperty.Layer = jsonBlockSetup.RealNameFinder(p2d.Layer);
                    i++;
                }
                p2d.Closed = false;
                jsonLineProperty.Internal_Id = BlockTableRead.InternalCounter;
            }
            else if (item is Polyline3d)
            {
                var p3d = item as Polyline3d;
                int i   = 1;
                foreach (Vertex2d polyline in p3d)
                {
                    jsonLineProperty.LinePoints.Add(ConvertAcadVertex2DToPoint2D(polyline, i));
                    jsonLineProperty.Layer = jsonBlockSetup.RealNameFinder(p3d.Layer);
                    i++;
                }
                p3d.Closed = false;
                jsonLineProperty.Internal_Id = BlockTableRead.InternalCounter;
            }
            return(jsonLineProperty);
        }
Ejemplo n.º 2
0
        public void ReadBtrForSeri(Database db, string fileName)
        {
            ExtensionMethod.ExecuteActionOnModelSpace(db, (tr, btrModelSpace) =>
            {
                var jsonLineSetup  = new JsonLineSetup();
                var jsonBlockSetup = new JsonBlockSetup();

                var jsonPID     = new JsonPID();
                InternalCounter = 1;
                foreach (ObjectId objectId in btrModelSpace)
                {
                    using (var item = objectId.GetObject(OpenMode.ForWrite))
                    {
                        if (item is BlockReference)
                        {
                            BlockReference blockReference = item as BlockReference;
                            if (blockReference == null)
                            {
                                continue;
                            }
                            var btrObjectId     = blockReference.DynamicBlockTableRecord; //must be Dynamic to find every blocks
                            var blockDefinition = btrObjectId.GetObject(OpenMode.ForRead) as BlockTableRecord;
                            if (blockDefinition.Name != "PID-PS-FRAME")
                            {
                                jsonPID.Blocks.Add(jsonBlockSetup.SetupBlockProperty(blockDefinition, tr, blockReference));
                                InternalCounter++;
                            }
                        }

                        if (item == null)
                        {
                            continue;
                        }

                        if (item is Line || item is Polyline || item is Polyline2d || item is Polyline3d)
                        {
                            //jsonLineToSerialize.Add(jsonLineSetup.SetupLineProperty(item));
                            jsonPID.Lines.Add(jsonLineSetup.SetupLineProperty(item, jsonBlockSetup));
                            InternalCounter++;
                        }
                    }
                }

                jsonPID.Blocks.Sort();
                jsonPID.Lines.Sort();

                var seralizer = new JsonStringBuilderSerialize();
                seralizer.StringBuilderSerialize(jsonPID, fileName);
            });
        }