예제 #1
4
        private static void WriteDxfFile()
        {
            DxfDocument dxf = new DxfDocument();

            //arc
            Arc arc = new Arc(new Vector3(10, 10, 0), 10, 45, 135);
            arc.Layer = new Layer("arc");
            arc.Layer.Color.Index = 1;
            dxf.AddEntity(arc);

            //xData sample
            XData xdata = new XData(new ApplicationRegistry("netDxf"));
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.String, "extended data with netDxf"));
            xdata.XDataRecord.Add(XDataRecord.OpenControlString);
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.WorldSpacePositionX, 0));
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.WorldSpacePositionY, 0));
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.WorldSpacePositionZ, 0));
            xdata.XDataRecord.Add(XDataRecord.CloseControlString);

            XData xdata2 = new XData(new ApplicationRegistry("other application"));
            xdata2.XDataRecord.Add(new XDataRecord(XDataCode.String, "extended data with netDxf"));
            xdata2.XDataRecord.Add(XDataRecord.OpenControlString);
            xdata2.XDataRecord.Add(new XDataRecord(XDataCode.String, "string record"));
            xdata2.XDataRecord.Add(new XDataRecord(XDataCode.Real, 15.5));
            xdata2.XDataRecord.Add(new XDataRecord(XDataCode.Int32, 350));
            xdata2.XDataRecord.Add(XDataRecord.CloseControlString);

            //circle
            Vector3 extrusion = new Vector3(1, 1, 1);
            Vector3 centerWCS = new Vector3(1, 1, 1);
            Vector3 centerOCS = MathHelper.Transform(centerWCS,
                                                        extrusion,
                                                        CoordinateSystem.World,
                                                        CoordinateSystem.Object);

            Circle circle = new Circle(centerOCS, 5);
            circle.Layer = new Layer("circle with spaces");
            circle.Layer.Color=AciColor.Yellow;
            circle.LineType = LineType.Dashed;
            circle.Normal = extrusion;
            circle.XData.Add(xdata);
            circle.XData.Add(xdata2);

            dxf.AddEntity(circle);

            //points
            Point point1 = new Point(new Vector3(-3, -3, 0));
            point1.Layer = new Layer("point");
            point1.Color = new AciColor(30);
            Point point2 = new Point(new Vector3(1, 1, 1));
            point2.Layer = point1.Layer;
            point2.Layer.Color.Index = 9;
            point2.Normal = new Vector3(1, 1, 1);
            dxf.AddEntity(point1);
            dxf.AddEntity(point2);

            //3dface
            Face3d face3D = new Face3d(new Vector3(-5, -5, 5),
                                        new Vector3(5, -5, 5),
                                        new Vector3(5, 5, 5),
                                        new Vector3(-5, 5, 5));
            face3D.Layer = new Layer("3dface");
            face3D.Layer.Color.Index = 3;
            dxf.AddEntity(face3D);
            
            //polyline
            LwPolylineVertex polyVertex;
            List<LwPolylineVertex> polyVertexes = new List<LwPolylineVertex>();
            polyVertex = new LwPolylineVertex(new Vector2(-50, -50));
            polyVertex.StartWidth = 2;
            polyVertexes.Add(polyVertex);
            polyVertex = new LwPolylineVertex(new Vector2(50, -50));
            polyVertex.StartWidth = 1;
            polyVertexes.Add(polyVertex);
            polyVertex = new LwPolylineVertex(new Vector2(50, 50));
            polyVertex.Bulge = 1;
            polyVertexes.Add(polyVertex);
            polyVertex = new LwPolylineVertex(new Vector2(-50, 50));
            polyVertexes.Add(polyVertex);
            LwPolyline polyline2d = new LwPolyline(polyVertexes, true);
            polyline2d.Layer = new Layer("polyline2d");
            polyline2d.Layer.Color.Index = 5;
            polyline2d.Normal = new Vector3(1, 1, 1);
            polyline2d.Elevation = 100.0f;
            dxf.AddEntity(polyline2d);

            //lightweight polyline
            LwPolylineVertex lwVertex;
            List<LwPolylineVertex> lwVertexes = new List<LwPolylineVertex>();
            lwVertex = new LwPolylineVertex(new Vector2(-25, -25));
            lwVertex.StartWidth = 2;
            lwVertexes.Add(lwVertex);
            lwVertex = new LwPolylineVertex(new Vector2(25, -25));
            lwVertex.StartWidth = 1;
            lwVertexes.Add(lwVertex);
            lwVertex = new LwPolylineVertex(new Vector2(25, 25));
            lwVertex.Bulge = 1;
            lwVertexes.Add(lwVertex);
            lwVertex = new LwPolylineVertex(new Vector2(-25, 25));
            lwVertexes.Add(lwVertex);
            LwPolyline lwPolyline = new LwPolyline(lwVertexes, true);
            lwPolyline.Layer = new Layer("lwpolyline");
            lwPolyline.Layer.Color.Index = 5;
            lwPolyline.Normal = new Vector3(1, 1, 1);
            lwPolyline.Elevation = 100.0f;
            dxf.AddEntity(lwPolyline);

            // polyfaceMesh
            List<PolyfaceMeshVertex> meshVertexes = new List<PolyfaceMeshVertex>
                                                    {
                                                        new PolyfaceMeshVertex(0, 0, 0),
                                                        new PolyfaceMeshVertex(10, 0, 0),
                                                        new PolyfaceMeshVertex(10, 10, 0),
                                                        new PolyfaceMeshVertex(5, 15, 0),
                                                        new PolyfaceMeshVertex(0, 10, 0)
                                                    };
            List<PolyfaceMeshFace> faces = new List<PolyfaceMeshFace>
                                                {
                                                    new PolyfaceMeshFace(new short[] {1, 2, -3}),
                                                    new PolyfaceMeshFace(new short[] {-1, 3, -4}),
                                                    new PolyfaceMeshFace(new short[] {-1, 4, 5})
                                                };

            PolyfaceMesh mesh = new PolyfaceMesh(meshVertexes, faces);
            mesh.Layer = new Layer("polyfacemesh");
            mesh.Layer.Color.Index = 104;
            dxf.AddEntity(mesh);

            //line
            Line line = new Line(new Vector3(0, 0, 0), new Vector3(10, 10, 10));
            line.Layer = new Layer("line");
            line.Layer.Color.Index = 6;
            dxf.AddEntity(line);

            //3d polyline
            PolylineVertex vertex;
            List<PolylineVertex> vertexes = new List<PolylineVertex>();
            vertex = new PolylineVertex(new Vector3(-50, -50, 0));
            vertexes.Add(vertex);
            vertex = new PolylineVertex(new Vector3(50, -50, 10));
            vertexes.Add(vertex);
            vertex = new PolylineVertex(new Vector3(50, 50, 25));
            vertexes.Add(vertex);
            vertex = new PolylineVertex(new Vector3(-50, 50, 50));
            vertexes.Add(vertex);
            Polyline polyline = new Polyline(vertexes, true);
            polyline.Layer = new Layer("polyline3d");
            polyline.Layer.Color.Index = 24;
            dxf.AddEntity(polyline);

            //block definition
            Block block = new Block("TestBlock");
            block.Entities.Add(new Line(new Vector3(-5, -5, 5), new Vector3(5, 5, 5)));
            block.Entities.Add(new Line(new Vector3(5, -5, 5), new Vector3(-5, 5, 5)));
           
            //insert
            Insert insert = new Insert(block, new Vector3(5, 5, 5));
            insert.Layer = new Layer("insert");
            insert.Layer.Color.Index = 4;
            dxf.AddEntity(insert);

            //text
            TextStyle style=new TextStyle("True type font","Arial.ttf");
            Text text = new Text("Hello world!", Vector3.Zero, 10.0f,style);
            text.Layer = new Layer("text");
            text.Layer.Color.Index = 8;
            text.Alignment = TextAlignment.TopRight;
            dxf.AddEntity(text);

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2010;
            dxf.Save("AutoCad2010.dxf");
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save("AutoCad2007.dxf");
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2004;
            dxf.Save("AutoCad2004.dxf");
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2000;
            dxf.Save("AutoCad2000.dxf");
            dxf = DxfDocument.Load("AutoCad2000.dxf");
            dxf.Save("AutoCad2000 result.dxf");
        }
예제 #2
1
        public static void ModifyingXData()
        {
            Line line = new Line(Vector2.Zero, Vector2.UnitX);

            ApplicationRegistry appReg = new ApplicationRegistry("netDxf");
            XData xdata = new XData(appReg);
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.String, "Length"));
            line.XData.Add(xdata);

            DxfDocument doc = new DxfDocument();
            doc.AddEntity(line);

            // modifying existing extended data
            line.XData[appReg.Name].XDataRecord.Add(new XDataRecord(XDataCode.Real, Vector3.Distance(line.StartPoint, line.EndPoint)));

            // adding new extended data entry to an existing entity
            ApplicationRegistry appReg2 = new ApplicationRegistry("newXData");
            XData xdata2 = new XData(appReg2);
            xdata2.XDataRecord.Add(new XDataRecord(XDataCode.String, "XData entries"));
            line.XData.Add(xdata2);

            Debug.Assert(ReferenceEquals(line.XData[appReg2.Name].ApplicationRegistry, doc.ApplicationRegistries[appReg2.Name]));

            // deleting existing extended data
            line.XData.Remove(appReg.Name);

            // we can also change the name of the application registry name
            doc.ApplicationRegistries["newXData"].Name = "netDxfRenamed";

            doc.Save("xData.dxf");

            doc = DxfDocument.Load("xData.dxf");
        }
예제 #3
0
        private void HatchPatternXData(Hatch hatch)
        {
            if (hatch.XData.ContainsKey(ApplicationRegistry.Default.Name))
            {
                XData xdataEntry = hatch.XData[ApplicationRegistry.Default.Name];
                xdataEntry.XDataRecord.Clear();
                xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.RealX, hatch.Pattern.Origin.X));
                xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.RealY, hatch.Pattern.Origin.Y));
                xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.RealZ, 0.0));
            }
            else
            {
                XData xdataEntry = new XData(new ApplicationRegistry(ApplicationRegistry.Default.Name));
                xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.RealX, hatch.Pattern.Origin.X));
                xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.RealY, hatch.Pattern.Origin.Y));
                xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.RealZ, 0.0));
                hatch.XData.Add(xdataEntry.ApplicationRegistry.Name, xdataEntry);
            }

            if (!(hatch.Pattern is HatchGradientPattern))
            {
                return;
            }

            HatchGradientPattern grad = (HatchGradientPattern)hatch.Pattern;

            if (hatch.XData.ContainsKey("GradientColor1ACI"))
            {
                XData       xdataEntry = hatch.XData["GradientColor1ACI"];
                XDataRecord record     = new XDataRecord(XDataCode.Integer, grad.Color1.Index);
                xdataEntry.XDataRecord.Clear();
                xdataEntry.XDataRecord.Add(record);
            }
            else
            {
                XData xdataEntry = new XData(new ApplicationRegistry("GradientColor1ACI"));
                xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Integer, grad.Color1.Index));
                hatch.XData.Add(xdataEntry.ApplicationRegistry.Name, xdataEntry);
            }

            if (hatch.XData.ContainsKey("GradientColor2ACI"))
            {
                XData       xdataEntry = hatch.XData["GradientColor2ACI"];
                XDataRecord record     = new XDataRecord(XDataCode.Integer, grad.Color2.Index);
                xdataEntry.XDataRecord.Clear();
                xdataEntry.XDataRecord.Add(record);
            }
            else
            {
                XData xdataEntry = new XData(new ApplicationRegistry("GradientColor2ACI"));
                xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Integer, grad.Color2.Index));
                hatch.XData.Add(xdataEntry.ApplicationRegistry.Name, xdataEntry);
            }
        }
예제 #4
0
        /// <summary>
        /// Creates a new XData that is a copy of the current instance.
        /// </summary>
        /// <returns>A new XData that is a copy of this instance.</returns>
        public object Clone()
        {
            XData xdata = new XData((ApplicationRegistry)this.appReg.Clone());

            foreach (XDataRecord record in this.xData)
            {
                xdata.XDataRecord.Add(new XDataRecord(record.Code, record.Value));
            }

            return(xdata);
        }
예제 #5
0
        private static void WritePolyline3d()
        {
            DxfDocument dxf = new DxfDocument();

            List<PolylineVertex> vertexes = new List<PolylineVertex>{
                                                                        new PolylineVertex(0, 0, 0), 
                                                                        new PolylineVertex(10, 0, 10), 
                                                                        new PolylineVertex(10, 10, 20), 
                                                                        new PolylineVertex(0, 10, 30)
                                                                        };

            Polyline poly = new Polyline(vertexes, true);

            XData xdata = new XData(new ApplicationRegistry("netDxf"));
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.String, "extended data with netDxf"));
            xdata.XDataRecord.Add(XDataRecord.OpenControlString);
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.String, "netDxf polyline3d"));
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.Int16, poly.Vertexes.Count));
            xdata.XDataRecord.Add(XDataRecord.CloseControlString);

            poly.XData.Add(xdata);

            dxf.AddEntity(poly);

            dxf.Save("polyline.dxf");           
        }
예제 #6
0
        private static void HatchTestLinesBoundary()
        {
            DxfDocument dxf = new DxfDocument();

            Line line1 = new Line(new Vector3(-10,-10,0),new Vector3(10,-10,0));
            Line line2 = new Line(new Vector3(10, -10, 0), new Vector3(10, 10, 0));
            Line line3 = new Line(new Vector3(10, 10, 0), new Vector3(-10, 10, 0));
            Line line4 = new Line(new Vector3(-10, 10, 0), new Vector3(-10, -10, 0));


            List<HatchBoundaryPath> boundary = new List<HatchBoundaryPath>{
                                                                            new HatchBoundaryPath(new List<EntityObject>{line1, line2, line3, line4})
                                                                            };
            Hatch hatch = new Hatch(HatchPattern.Line, boundary, true);
            hatch.Layer = new Layer("hatch")
            {
                Color = AciColor.Red,
                LineType = LineType.Dashed
            };
            hatch.Elevation = 52;
            hatch.Pattern.Angle = 45;
            hatch.Pattern.Scale = 10;
            hatch.Normal = new Vector3(1, 1, 1);

            XData xdata = new XData(new ApplicationRegistry("netDxf"));
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.String, "extended data with netDxf"));
            xdata.XDataRecord.Add(XDataRecord.OpenControlString);
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.String, "netDxf hatch"));
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.Distance, hatch.Pattern.Scale));
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.Real, hatch.Pattern.Angle));
            xdata.XDataRecord.Add(XDataRecord.CloseControlString);

            hatch.XData.Add(xdata);

            //dxf.AddEntity(line1);
            //dxf.AddEntity(line2);
            //dxf.AddEntity(line3);
            //dxf.AddEntity(line4);
            dxf.AddEntity(hatch);
            dxf.AddEntity(hatch.CreateBoundary(true));

            dxf.Save("hatchTest.dxf");
        }
예제 #7
0
        private static void WriteMText()
        {
            DxfDocument dxf = new DxfDocument();

            //xData sample
            XData xdata = new XData(new ApplicationRegistry("netDxf"));
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.String, "extended data with netDxf"));
            xdata.XDataRecord.Add(XDataRecord.OpenControlString);
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.WorldSpacePositionX, 0));
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.WorldSpacePositionY, 0));
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.WorldSpacePositionZ, 0));
            xdata.XDataRecord.Add(XDataRecord.CloseControlString);

            //text
            TextStyle style = new TextStyle("Times.ttf");
            //TextStyle style = TextStyle.Default;
            MText mText = new MText(new Vector3(3,2,0), 1.0f, 100.0f, style);
            mText.Layer = new Layer("Multiline Text");
            //mText.Layer.Color.Index = 8;
            mText.Rotation = 0;
            mText.LineSpacingFactor = 1.0;
            mText.ParagraphHeightFactor = 1.0;

            //mText.AttachmentPoint = MTextAttachmentPoint.TopCenter;
            //mText.Write("Hello World!");
            //mText.Write(" we keep writting on the same line.");
            //mText.WriteLine("This text is in a new line");

            //mText.Write("Hello World! ");
            //for (int i = 0; i < 50; i++)
            //{
            //    mText.Write("1234567890");
            //}
            //mText.Write(" This text is over the limit of the 250 character chunk");
            //mText.NewParagraph();
            //mText.Write("This is a text in a new paragraph");
            //mText.Write(" and we continue writing in the previous paragraph");
            //mText.NewParagraph();
            MTextFormattingOptions options = new MTextFormattingOptions(mText.Style);
            options.Bold = true;
            mText.Write("Bold text in mText.Style", options);
            mText.EndParagraph();
            options.Italic = true;
            mText.Write("Bold and italic text in mText.Style", options);
            mText.EndParagraph();
            options.Bold = false;
            options.FontName = "Arial";
            options.Color = AciColor.Blue;
            mText.ParagraphHeightFactor = 2;
            mText.Write("Italic text in Arial", options);
            mText.EndParagraph();
            options.Italic = false;
            options.Color = null; // back to the default text color
            mText.Write("Normal text in Arial with the default paragraph height factor", options);
            mText.EndParagraph();
            mText.ParagraphHeightFactor = 1;
            mText.Write("No formatted text uses mText.Style");
            mText.Write(" and the text continues in the same paragraph.");
            mText.EndParagraph();

            //options.HeightPercentage = 2.5;
            //options.Color = AciColor.Red;
            //options.Overstrike = true;
            //options.Underline = true;
            //options.FontFile = "times.ttf";
            //options.ObliqueAngle = 15;
            //options.CharacterSpacePercentage = 2.35;
            //options.WidthFactor = 1.8;
            
            //for unknown reasons the aligment doesn't seem to change anything
            //mText.Write("Formatted text", options);
            //options.Aligment = MTextFormattingOptions.TextAligment.Center;
            //mText.Write("Center", options);
            //options.Aligment = MTextFormattingOptions.TextAligment.Top;
            //mText.Write("Top", options);
            //options.Aligment = MTextFormattingOptions.TextAligment.Bottom;
            //mText.Write("Bottom", options);

            mText.XData.Add(xdata);
            
            dxf.AddEntity(mText);

            dxf.Save("MText sample.dxf");

        }
예제 #8
0
        private static void BlockAttributes()
        {
            DxfDocument dxf = new DxfDocument( );
            Block block = new Block("BlockWithAttributes");
            block.Layer = new Layer("BlockSample");

            AttributeDefinition attdef = new AttributeDefinition("NewAttribute");
            attdef.Text = "InfoText";
            attdef.BasePoint = new Vector3d(1, 1, 1);
            attdef.Style.IsVertical = true;
            attdef.Rotation = 45;

            block.Attributes.Add(attdef.Id, attdef);
            block.Entities.Add(new Line(new Vector3d(-5, -5, 0), new Vector3d(5, 5, 0)));
            block.Entities.Add(new Line(new Vector3d(5, -5, 0), new Vector3d(-5, 5, 0)));

            Insert insert = new Insert(block, new Vector3d(5, 5, 5));
            insert.Layer = new Layer("insert");
            insert.Rotation = 45;
            insert.Layer.Color.Index = 4;
            insert.Attributes[0].Value = 24;

            Insert insert2 = new Insert(block, new Vector3d(-5, -5, -5));
            insert2.Attributes[0].Value = 34;

            XData xdata1 = new XData(new ApplicationRegistry("netDxf"));
            xdata1.XDataRecord.Add(new XDataRecord(XDataCode.String, "extended data with netDxf"));
            xdata1.XDataRecord.Add(XDataRecord.OpenControlString);
            xdata1.XDataRecord.Add(new XDataRecord(XDataCode.WorldSpacePositionX, 0));
            xdata1.XDataRecord.Add(new XDataRecord(XDataCode.WorldSpacePositionY, 0));
            xdata1.XDataRecord.Add(new XDataRecord(XDataCode.WorldSpacePositionZ, 0));
            xdata1.XDataRecord.Add(XDataRecord.CloseControlString);

            XData xdata2 = new XData(new ApplicationRegistry("other application"));
            xdata2.XDataRecord.Add(new XDataRecord(XDataCode.String, "extended data with netDxf"));
            xdata2.XDataRecord.Add(XDataRecord.OpenControlString);
            xdata2.XDataRecord.Add(new XDataRecord(XDataCode.String, "string record"));
            xdata2.XDataRecord.Add(new XDataRecord(XDataCode.Real, 15.5));
            xdata2.XDataRecord.Add(new XDataRecord(XDataCode.Long, 350));
            xdata2.XDataRecord.Add(XDataRecord.CloseControlString);

            insert.XData = new Dictionary<ApplicationRegistry, XData>
                             {
                                 {xdata1.ApplicationRegistry, xdata1},
                             };
            dxf.AddEntity(insert);
            dxf.AddEntity(insert2);

            Circle circle = new Circle(Vector3d.Zero, 5);
            circle.Layer = new Layer("circle");
            circle.Layer.Color.Index = 2;
            circle.XData = new Dictionary<ApplicationRegistry, XData>
                             {
                                 {xdata2.ApplicationRegistry, xdata2},
                             };
            dxf.AddEntity(circle);

            dxf.Save("Block with attributes.dxf", DxfVersion.AutoCad2000);
            dxf.Load("Block with attributes.dxf");
            dxf.Save("Block with attributes result.dxf", DxfVersion.AutoCad2000); // both results must be equal only the handles might be different
        }
예제 #9
0
        private XData ReadXDataRecord(string appId, ref CodeValuePair code)
        {
            XData xData = new XData(this.appIds[appId]);
            code = this.ReadCodePair();

            while (code.Code >= 1000 && code.Code <= 1071)
            {
                if (code.Code == XDataCode.AppReg)
                    break;

                XDataRecord xDataRecord = new XDataRecord(code.Code, code.Value);
                xData.XDataRecord.Add(xDataRecord);
                code = this.ReadCodePair();
            }

            return xData;
        }
예제 #10
0
        private static void WriteImage()
        {
            ImageDefinition imageDefinition = new ImageDefinition("img\\image01.jpg");
            Image image = new Image(imageDefinition, Vector3.Zero, 10, 10);

            XData xdata1 = new XData(new ApplicationRegistry("netDxf"));
            xdata1.XDataRecord.Add(new XDataRecord(XDataCode.String, "xData image position"));
            xdata1.XDataRecord.Add(XDataRecord.OpenControlString);
            xdata1.XDataRecord.Add(new XDataRecord(XDataCode.WorldSpacePositionX, image.Position.X));
            xdata1.XDataRecord.Add(new XDataRecord(XDataCode.WorldSpacePositionY, image.Position.Y));
            xdata1.XDataRecord.Add(new XDataRecord(XDataCode.WorldSpacePositionZ, image.Position.Z));
            xdata1.XDataRecord.Add(XDataRecord.CloseControlString);
            image.XData.Add(xdata1);

            //image.Normal = new Vector3(1, 1, 1);
            //image.Rotation = 30;

            // you can pass a name that must be unique for the image definiton, by default it will use the file name without the extension
            ImageDefinition imageDef2 = new ImageDefinition("img\\image02.jpg", "MyImage");
            Image image2 = new Image(imageDef2, new Vector3(0, 150, 0), 10, 10);
            Image image3 = new Image(imageDef2, new Vector3(150, 150, 0), 10, 10);

            // clipping boundary definition in local coordinates
            ClippingBoundary clip = new ClippingBoundary(100, 100, 500, 300);
            image.ClippingBoundary = clip;
            // set to null to restore the default clipping boundary (full image)
            image.ClippingBoundary = null;

            // images can be part of a block definition
            Block block = new Block("ImageBlock");
            block.Entities.Add(image2);
            block.Entities.Add(image3);
            Insert insert = new Insert(block, new Vector3(0, 100, 0));

            DxfDocument dxf = new DxfDocument();

            dxf.AddEntity(image);
            //dxf.AddEntity(image2);
            //dxf.AddEntity(image3);
            dxf.AddEntity(insert);

            dxf.Save("image.dxf");
            dxf = DxfDocument.Load("image.dxf");
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2010;
            dxf.Save("test.dxf");

            //dxf.RemoveEntity(image2);
            //dxf.Save("image2.dxf");
            //dxf.RemoveEntity(image3);
            //dxf.RemoveEntity(image);
            //dxf.Save("image3.dxf");

        }
예제 #11
0
        private static void ApplicationRegistries()
        {
            DxfDocument dxf = new DxfDocument();
            // add a new application registry to the document (optional), if not present it will be added when the entity is passed to the document
            ApplicationRegistry newAppReg = dxf.ApplicationRegistries.Add(new ApplicationRegistry("NewAppReg"));

            Line line = new Line(Vector2.Zero, 100 * Vector2.UnitX);
            XData xdata = new XData(newAppReg);
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.String, "string of the new application registry"));
            line.XData.Add(xdata);

            dxf.AddEntity(line);
            dxf.Save("ApplicationRegistryTest.dxf");

            // gets the complete application registries present in the document
            ICollection<ApplicationRegistry> appRegs = dxf.ApplicationRegistries.Items;

            // get an application registry by name
            //ApplicationRegistry netDxfAppReg = dxf.ApplicationRegistries[appRegs[dxf.ApplicationRegistries.Count - 1].Name];
        }
예제 #12
0
        private static void AppRegUsesAndRemove()
        {
            DxfDocument dxf = new DxfDocument();

            List<PolylineVertex> vertexes = new List<PolylineVertex>{
                                                                        new PolylineVertex(0, 0, 0), 
                                                                        new PolylineVertex(10, 0, 10), 
                                                                        new PolylineVertex(10, 10, 20), 
                                                                        new PolylineVertex(0, 10, 30)
                                                                        };

            Polyline poly = new Polyline(vertexes, true);

            XData xdata1 = new XData(new ApplicationRegistry("netDxf"));
            xdata1.XDataRecord.Add(new XDataRecord(XDataCode.String, "extended data with netDxf"));

            poly.XData.Add(xdata1);

            dxf.AddEntity(poly);

            Line line = new Line(new Vector2(10, 5), new Vector2(-10, -5));

            ApplicationRegistry myAppReg = new ApplicationRegistry("MyAppReg");
            XData xdata2 = new XData(myAppReg);
            xdata2.XDataRecord.Add(new XDataRecord(XDataCode.Distance, Vector3.Distance(line.StartPoint, line.EndPoint)));
            line.XData.Add(xdata2);

            dxf.AddEntity(line);

            Circle circle = new Circle(Vector3.Zero, 15);
            XData xdata3 = new XData(myAppReg);
            xdata3.XDataRecord.Add(new XDataRecord(XDataCode.Real, circle.Radius));
            circle.XData.Add(xdata3);

            dxf.AddEntity(circle);

            dxf.Save("appreg.dxf");

            DxfDocument dxf2 = DxfDocument.Load("appreg.dxf");

            // will return false the "MyAppReg" is in use
            bool ok;
            ok = dxf.ApplicationRegistries.Remove(myAppReg.Name);
            dxf.RemoveEntity(line);
            dxf.RemoveEntity(circle);
            // "MyAppReg" is not used anymore
            IList<DxfObject> uses = dxf.ApplicationRegistries.GetReferences(myAppReg.Name);
            // it is safe to delete it
            ok = dxf.ApplicationRegistries.Remove(myAppReg.Name);
            
            // we can even make a full cleanup
            dxf.ApplicationRegistries.Clear();

            dxf.Save("appreg2.dxf");


        }
예제 #13
0
        private static void BlockWithAttributes()
        {
            DxfDocument dxf = new DxfDocument();
            Block block = new Block("BlockWithAttributes");
            block.Layer = new Layer("BlockSample");
            // It is possible to change the block position, even though it is recommended to keep it at Vector3.Zero,
            // since the block geometry is expressed in local coordinates of the block.
            // The block position defines the base point when inserting an Insert entity.
            block.Origin = new Vector3(10, 5, 0);

            // create an attribute definition, the attDef tag must be unique as it is the way to identify the attribute.
            // even thought AutoCad allows multiple attribute definition in block definitions, it is not recommended
            AttributeDefinition attdef = new AttributeDefinition("NewAttribute");
            // this is the text prompt shown to introduce the attribute value when a new Insert entity is inserted into the drawing
            attdef.Prompt = "InfoText";
            // optionally we can set a default value for new Insert entities
            attdef.Value = 0;
            // the attribute definition position is in local coordinates to the Insert entity to which it belongs
            attdef.Position = new Vector3(1, 1, 0);

            // modifying directly the text style might not get the desired results. Create one or get one from the text style table, modify it and assign it to the attribute text style.
            // one thing to note, if there is already a text style with the assigned name, the existing one in the text style table will override the new one.
            //attdef.Style.IsVertical = true;

            TextStyle txt = new TextStyle("MyStyle", "Arial.ttf");
            txt.IsVertical = true;
            attdef.Style = txt;
            attdef.WidthFactor = 2;
            // not all alignment options are available for TTF fonts 
            attdef.Alignment = TextAlignment.MiddleCenter;
            attdef.Rotation = 90;

            // remember, netDxf does not allow adding attribute definitions with the same tag, even thought AutoCad allows this behavior, it is not recommended in anyway.
            // internally attributes and their associated attribute definitions are handled through dictionaries,
            // and the tags work as ids to easily identify the information stored in the attribute value.
            // When reading a file the attributes or attribute definitions with duplicate tags will be automatically removed.
            // This is subject to change on public demand, it is possible to reimplement this behavior with simple collections to allow for duplicate tags.
            block.AttributeDefinitions.Add(attdef);

            // The entities list defines the actual geometry of the block, they are expressed in th block local coordinates
            Line line1 = new Line(new Vector3(-5, -5, 0), new Vector3(5, 5, 0));
            Line line2 = new Line(new Vector3(5, -5, 0), new Vector3(-5, 5, 0));
            block.Entities.Add(line1);
            block.Entities.Add(line2);

            // You can check the entity ownership with:
            Block line1Owner = line1.Owner;
            Block line2Owner = line2.Owner;
            // in this example line1Oner = line2Owner = block
            // As explained in the PaperSpace() sample, the layout associated with a common block will always be null
            Layout associatedLayout = line1.Owner.Record.Layout;
            // associatedLayout = null

            // create an Insert entity with the block definition, during the initialization the Insert attributes list will be created with the default attdef properties
            Insert insert1 = new Insert(block)
            {
                Position = new Vector3(5, 5, 5),
                Normal = new Vector3(1, 1, 1),
                Rotation = 45
            };

            // When the insert position, rotation, normal and/or scale are modified we need to transform the attributes.
            // It is not recommended to manually change the attribute position and orientation and let the Insert entity handle the transformations to maintain them in the same local position.
            // In this particular case we have changed the position, normal and rotation.
            insert1.TransformAttributes();
            
            // Once the insert has been created we can modify the attributes properties, the list cannot be modified only the items stored in it
            insert1.Attributes[0].Value = 24;

            // Modifying directly the layer might not get the desired results. Create one or get one from the layers table, modify it and assign it to the insert
            // One thing to note, if there is already a layer with the same name, the existing one in the layers table will override the new one, when the entity is added to the document.
            Layer layer = new Layer("MyInsertLayer");
            layer.Color.Index = 4;

            // optionally we can add the new layer to the document, if not the new layer will be added to the Layers collection when the insert entity is added to the document
            // in case a new layer is found in the list the add method will return the layer already stored in the list
            // this behavior is similar for all TableObject elements, all table object names must be unique (case insensitive)
            layer = dxf.Layers.Add(layer);

            // assign the new layer to the insert
            insert1.Layer = layer;

            // add the entity to the document
            dxf.AddEntity(insert1);

            // create a second insert entity
            // the constructor will automatically reposition the insert2 attributes to the insert local position
            Insert insert2 = new Insert(block, new Vector3(10, 5, 0));

            // as before now we can change the insert2 attribute value
            insert2.Attributes[0].Value = 34;

            // additionally we can insert extended data information
            XData xdata1 = new XData(new ApplicationRegistry("netDxf"));
            xdata1.XDataRecord.Add(new XDataRecord(XDataCode.String, "extended data with netDxf"));
            xdata1.XDataRecord.Add(XDataRecord.OpenControlString);
            xdata1.XDataRecord.Add(new XDataRecord(XDataCode.WorldSpacePositionX, 0.0));
            xdata1.XDataRecord.Add(new XDataRecord(XDataCode.WorldSpacePositionY, 0.0));
            xdata1.XDataRecord.Add(new XDataRecord(XDataCode.WorldSpacePositionZ, 0.0));
            xdata1.XDataRecord.Add(XDataRecord.CloseControlString);

            insert2.XData.Add(xdata1);
            dxf.AddEntity(insert2);

            // all entities support this feature
            XData xdata2 = new XData(new ApplicationRegistry("MyApplication1"));
            xdata2.XDataRecord.Add(new XDataRecord(XDataCode.String, "extended data with netDxf"));
            xdata2.XDataRecord.Add(XDataRecord.OpenControlString);
            xdata2.XDataRecord.Add(new XDataRecord(XDataCode.String, "string record"));
            xdata2.XDataRecord.Add(new XDataRecord(XDataCode.Real, 15.5));
            xdata2.XDataRecord.Add(new XDataRecord(XDataCode.Int32, 350));
            xdata2.XDataRecord.Add(XDataRecord.CloseControlString);

            // multiple extended data entries might be added
            XData xdata3 = new XData(new ApplicationRegistry("MyApplication2"));
            xdata3.XDataRecord.Add(new XDataRecord(XDataCode.String, "extended data with netDxf"));
            xdata3.XDataRecord.Add(XDataRecord.OpenControlString);
            xdata3.XDataRecord.Add(new XDataRecord(XDataCode.String, "string record"));
            xdata3.XDataRecord.Add(new XDataRecord(XDataCode.Real, 15.5));
            xdata3.XDataRecord.Add(new XDataRecord(XDataCode.Int32, 350));
            xdata3.XDataRecord.Add(XDataRecord.CloseControlString);

            Circle circle = new Circle(Vector3.Zero, 5);
            circle.Layer = new Layer("MyCircleLayer");
            // AutoCad 2000 does not support true colors, in that case an approximated color index will be used instead
            circle.Layer.Color = new AciColor(Color.MediumSlateBlue);
            circle.XData.Add(xdata2);
            circle.XData.Add(xdata3);

            dxf.AddEntity(circle);

            dxf.Save("BlockWithAttributes.dxf");
            DxfDocument dxfLoad = DxfDocument.Load("BlockWithAttributes.dxf");
        }
예제 #14
0
        private static void MeshEntity()
        {
            DxfDocument dxf = new DxfDocument();

            // construct a simple cube (see the AutoCad documentation for more information about creating meshes)

            // the mesh data is always defined at level 0 (no subdivision)
            // 8 vertices
            List<Vector3> vertexes = new List<Vector3>
                                            {
                                                new Vector3(-5, -5, -5),
                                                new Vector3(5, -5, -5),
                                                new Vector3(5, 5, -5),
                                                new Vector3(-5, 5, -5),
                                                new Vector3(-5, -5, 5),
                                                new Vector3(5, -5, 5),
                                                new Vector3(5, 5, 5),
                                                new Vector3(-5, 5, 5)
                                            };

            //6 faces
            List<int[]> faces = new List<int[]>
                                                {
                                                    new[] {0, 3, 2, 1},
                                                    new[] {0, 1, 5, 4},
                                                    new[] {1, 2, 6, 5},
                                                    new[] {2, 3, 7, 6},
                                                    new[] {0, 4, 7, 3},
                                                    new[] {4, 5, 6, 7}
                                                };

            

            // the list of edges is optional and only really needed when applying creases values to them
            // crease negative values will sharpen the edge independently of the subdivision level. Any negative crease value will be reseted as -1.
            // by default edge creases are set to 0.0 (no edge sharpening)
            List<MeshEdge> edges = new List<MeshEdge>
            {
                new MeshEdge(0, 1),
                new MeshEdge(1, 2),
                new MeshEdge(2, 3),
                new MeshEdge(3, 0),
                new MeshEdge(4, 5, -1.0),
                new MeshEdge(5, 6, -1.0),
                new MeshEdge(6, 7, -1.0),
                new MeshEdge(7, 4, -1.0),
                new MeshEdge(0, 4),
                new MeshEdge(1, 5),
                new MeshEdge(2, 6),
                new MeshEdge(3, 7)

            };
            Mesh mesh = new Mesh(vertexes, faces, edges);
            mesh.SubdivisionLevel = 3;

            ApplicationRegistry newAppReg = dxf.ApplicationRegistries.Add(new ApplicationRegistry("netDxf"));

            XData xdata = new XData(newAppReg);
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.String, "xdata string sample"));
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.Int32, 50000));
            mesh.XData.Add(xdata);

            dxf.AddEntity(mesh);

            dxf.Save("mesh.dxf");

            dxf = DxfDocument.Load("mesh.dxf");

        }
예제 #15
0
        private static void BinaryChunkXData()
        {
            Line line = new Line(Vector2.Zero, Vector2.UnitX);

            ApplicationRegistry appId = new ApplicationRegistry("TestBinaryChunk");

            // the extended data binary data (code 1004) is stored in a different way depending if the dxf file is text or binary.
            // in text based files as a string of hexadecimal digits, two per binary byte,
            // while in binary files the data is stored in chunks of 127 bytes, preceding a byte that defines the number of bytes in the chunk
            byte[] data = new byte[325];

            // fill up the array with some random data
            Random rnd = new Random();
            rnd.NextBytes(data);

            XData xdata = new XData(appId);

            // the XDataRecord will store the binary data as a byte array and not as a string as it use to be
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.BinaryData, data));
            line.XData.Add(xdata);

            DxfDocument dxf = new DxfDocument();
            dxf.AddEntity(line);

            dxf.Save("BinaryChunkXData.dxf");
            dxf.Save("BinaryChunkXData binary.dxf", true);

            // some testing
            DxfDocument test = DxfDocument.Load("BinaryChunkXData binary.dxf");
            Line lineTest = test.Lines[0];
            XDataRecord recordTest = lineTest.XData[appId.Name].XDataRecord[0];
            Debug.Assert(recordTest.Code == XDataCode.BinaryData);
            byte[] dataText = (byte[]) recordTest.Value;

            byte[] compare = new byte[127];
            Array.Copy(data, compare, 127);

            for (int i = 0; i < 127; i++)
            {
                Console.WriteLine(dataText[i] == compare[i]);
            }

            // this is the string as it is saved in text based dxf files
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < dataText.Length; i++)
            {
                sb.Append(String.Format("{0:X2}", data[i]));
            }
            Console.WriteLine(sb.ToString());

            Console.WriteLine();
            Console.WriteLine("Press a key to continue...");
            Console.ReadKey();
        }
예제 #16
0
 public static void XDataInformation()
 {
     Line line = new Line(Vector2.Zero, Vector2.UnitY);
     XData xdata = new XData(new ApplicationRegistry("a"));
     //xdata.XDataRecord.Add(XDataRecord.OpenControlString);
     xdata.XDataRecord.Add(XDataRecord.CloseControlString);
     //xdata.XDataRecord.Add(new XDataRecord(XDataCode.String, "a"));
     //xdata.XDataRecord.Add(new XDataRecord(XDataCode.Int32, 1));
     //xdata.XDataRecord.Add(new XDataRecord(XDataCode.Real, 1.1));
     //xdata.XDataRecord.Add(new XDataRecord(XDataCode.WorldDirectionX, 1.2));
     line.XData.Add(xdata);
     DxfDocument dwg = new DxfDocument();
     dwg.AddEntity(line);
     dwg.Save("Xdata.dxf");
 }
예제 #17
0
        private static void LinearDimensionDrawing()
        {
            DxfDocument dxf = new DxfDocument();
            
            Vector3 p1 = new Vector3(0, 0, 0);
            Vector3 p2 = new Vector3(5, 5, 0);
            Line line = new Line(p1, p2);

            dxf.AddEntity(line);

            DimensionStyle myStyle = new DimensionStyle("MyStyle");
            myStyle.DIMPOST = "<>mm";
            myStyle.DIMDEC = 2;
            double offset = 7;
            LinearDimension dimX = new LinearDimension(line, offset,0.0, myStyle);
            dimX.Rotation += 30.0;
            LinearDimension dimY = new LinearDimension(line, offset, 90.0, myStyle);
            dimY.Rotation += 30.0;

            XData xdata = new XData(new ApplicationRegistry("other application"));
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.String, "extended data with netDxf"));
            xdata.XDataRecord.Add(XDataRecord.OpenControlString);
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.String, "Linear Dimension"));
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.Real, 15.5));
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.Int32, 350));
            xdata.XDataRecord.Add(XDataRecord.CloseControlString);
            dimX.XData.Add(xdata);
            dimY.XData.Add(xdata);
            dxf.AddEntity(dimX);
            dxf.AddEntity(dimY);
            dxf.Save("linear dimension.dxf");
            // dxf = DxfDocument.Load("linear dimension.dxf");
        }
예제 #18
0
        private static void AlignedDimensionDrawing()
        {
            DxfDocument dxf = new DxfDocument();
            double offset = -0.9;
            Vector3 p1 = new Vector3(1, 2, 0);
            Vector3 p2 = new Vector3(2, 6, 0);
            Line line1 = new Line(p1, p2);
            Vector3 l1;
            Vector3 l2;
            MathHelper.OffsetLine(line1.StartPoint, line1.EndPoint, line1.Normal, offset, out l1, out l2);

            DimensionStyle myStyle = new DimensionStyle("MyStyle");
            myStyle.DIMPOST = "<>mm";
            AlignedDimension dim1 = new AlignedDimension(p1, p2, offset, myStyle);

            Vector3 p3 = p1 + new Vector3(4, 0, 0);
            Vector3 p4 = p2 + new Vector3(4, 0, 0);
            Line line2 = new Line(p3, p4);
            AlignedDimension dim2 = new AlignedDimension(p3, p4, -offset, myStyle);


            Vector2 perp = Vector2.Perpendicular(new Vector2(p2.X, p2.Y) - new Vector2(p1.X, p1.Y));
            //dim.Normal = -new Vector3(perp.X, perp.Y, 0.0) ;

            XData xdata = new XData(new ApplicationRegistry("other application"));
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.String, "extended data with netDxf"));
            xdata.XDataRecord.Add(XDataRecord.OpenControlString);
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.String, "Aligned Dimension"));
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.Real, 15.5));
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.Int32, 350));
            xdata.XDataRecord.Add(XDataRecord.CloseControlString);
            dim1.XData.Add(xdata);

            //dxf.AddEntity(line1);
            //dxf.AddEntity(line2);
            //dxf.AddEntity(dim1);
            //dxf.AddEntity(dim2);



            Block block = new Block("DimensionBlock");
            block.Entities.Add(line1);
            block.Entities.Add(line2);
            block.Entities.Add(dim1);
            block.Entities.Add(dim2);
            Insert insert = new Insert(block);
            dxf.AddEntity(insert);

            dxf.Save("aligned dimension.dxf");

            dxf = DxfDocument.Load("aligned dimension.dxf");

        }
예제 #19
0
파일: XData.cs 프로젝트: Core2D/netdxf
        /// <summary>
        /// Creates a new XData that is a copy of the current instance.
        /// </summary>
        /// <returns>A new XData that is a copy of this instance.</returns>
        public object Clone()
        {
            XData xdata = new XData((ApplicationRegistry) this.appReg.Clone());
            foreach (XDataRecord record in this.xData)
                xdata.XDataRecord.Add(new XDataRecord(record.Code, record.Value));

            return xdata;
        }
예제 #20
0
        private static void WriteDxfFile()
        {
            DxfDocument dxf = new DxfDocument();

            //arc
            Arc arc = new Arc(new Vector3d(10, 10, 0), 10, 45, 135);
            arc.Layer = new Layer("arc");
            arc.Layer.Color.Index = 1;
            dxf.AddEntity(arc);

            //xData sample
            XData xdata = new XData(new ApplicationRegistry("netDxf"));
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.String, "extended data with netDxf"));
            xdata.XDataRecord.Add(XDataRecord.OpenControlString);
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.WorldSpacePositionX, 0));
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.WorldSpacePositionY, 0));
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.WorldSpacePositionZ, 0));
            xdata.XDataRecord.Add(XDataRecord.CloseControlString);

            XData xdata2 = new XData(new ApplicationRegistry("other application"));
            xdata2.XDataRecord.Add(new XDataRecord(XDataCode.String, "extended data with netDxf"));
            xdata2.XDataRecord.Add(XDataRecord.OpenControlString);
            xdata2.XDataRecord.Add(new XDataRecord(XDataCode.String, "string record"));
            xdata2.XDataRecord.Add(new XDataRecord(XDataCode.Real, 15.5));
            xdata2.XDataRecord.Add(new XDataRecord(XDataCode.Long, 350));
            xdata2.XDataRecord.Add(XDataRecord.CloseControlString);

            //circle
            Vector3d extrusion = new Vector3d(1, 1, 1);
            Vector3d centerWCS = new Vector3d(1, 1, 1);
            Vector3d centerOCS = MathHelper.Transform(centerWCS,
                                                      extrusion,
                                                      MathHelper.CoordinateSystem.World,
                                                      MathHelper.CoordinateSystem.Object);

            Circle circle = new Circle(centerOCS, 5);
            circle.Layer = new Layer("circle with spaces");
            circle.Layer.Color=AciColor.Yellow;
            circle.LineType = LineType.Dashed;
            circle.Normal = extrusion;
            circle.XData=new Dictionary<ApplicationRegistry, XData>
                             {
                                 {xdata.ApplicationRegistry, xdata},
                                 {xdata2.ApplicationRegistry, xdata2}
                             };

            dxf.AddEntity(circle);

            //points
            Point point1 = new Point(new Vector3d(-3, -3, 0));
            point1.Layer = new Layer("point");
            point1.Color = new AciColor(30);
            Point point2 = new Point(new Vector3d(1, 1, 1));
            point2.Layer = point1.Layer;
            point2.Layer.Color.Index = 9;
            point2.Normal = new Vector3d(1, 1, 1);
            dxf.AddEntity(point1);
            dxf.AddEntity(point2);

            //3dface
            Face3d face3D = new Face3d(new Vector3d(-5, -5, 5),
                                       new Vector3d(5, -5, 5),
                                       new Vector3d(5, 5, 5),
                                       new Vector3d(-5, 5, 5));
            face3D.Layer = new Layer("3dface");
            face3D.Layer.Color.Index = 3;
            dxf.AddEntity(face3D);

            //polyline
            PolylineVertex polyVertex;
            List<PolylineVertex> polyVertexes = new List<PolylineVertex>();
            polyVertex = new PolylineVertex(new Vector2d(-50, -50));
            polyVertex.BeginThickness = 2;
            polyVertexes.Add(polyVertex);
            polyVertex = new PolylineVertex(new Vector2d(50, -50));
            polyVertex.BeginThickness = 1;
            polyVertexes.Add(polyVertex);
            polyVertex = new PolylineVertex(new Vector2d(50, 50));
            polyVertex.Bulge = 1;
            polyVertexes.Add(polyVertex);
            polyVertex = new PolylineVertex(new Vector2d(-50, 50));
            polyVertexes.Add(polyVertex);
            Polyline polyline2d = new Polyline(polyVertexes, true);
            polyline2d.Layer = new Layer("polyline2d");
            polyline2d.Layer.Color.Index = 5;
            polyline2d.Normal = new Vector3d(1, 1, 1);
            polyline2d.Elevation = 100.0;
            dxf.AddEntity(polyline2d);

            //lightweight polyline
            LightWeightPolylineVertex lwVertex;
            List<LightWeightPolylineVertex> lwVertexes = new List<LightWeightPolylineVertex>();
            lwVertex = new LightWeightPolylineVertex(new Vector2d(-25, -25));
            lwVertex.BeginThickness = 2;
            lwVertexes.Add(lwVertex);
            lwVertex = new LightWeightPolylineVertex(new Vector2d(25, -25));
            lwVertex.BeginThickness = 1;
            lwVertexes.Add(lwVertex);
            lwVertex = new LightWeightPolylineVertex(new Vector2d(25, 25));
            lwVertex.Bulge = 1;
            lwVertexes.Add(lwVertex);
            lwVertex = new LightWeightPolylineVertex(new Vector2d(-25, 25));
            lwVertexes.Add(lwVertex);
            LightWeightPolyline lwPolyline = new LightWeightPolyline(lwVertexes, true);
            lwPolyline.Layer = new Layer("lwpolyline");
            lwPolyline.Layer.Color.Index = 5;
            lwPolyline.Normal = new Vector3d(1, 1, 1);
            lwPolyline.Elevation = 100.0;
            dxf.AddEntity(lwPolyline);

            //line
            Line line = new Line(new Vector3d(0, 0, 0), new Vector3d(10, 10, 10));
            line.Layer = new Layer("line");
            line.Layer.Color.Index = 6;
            dxf.AddEntity(line);

            //3d polyline
            Polyline3dVertex vertex;
            List<Polyline3dVertex> vertexes = new List<Polyline3dVertex>();
            vertex = new Polyline3dVertex(new Vector3d(-50, -50, 0));
            vertexes.Add(vertex);
            vertex = new Polyline3dVertex(new Vector3d(50, -50, 10));
            vertexes.Add(vertex);
            vertex = new Polyline3dVertex(new Vector3d(50, 50, 25));
            vertexes.Add(vertex);
            vertex = new Polyline3dVertex(new Vector3d(-50, 50, 50));
            vertexes.Add(vertex);
            Polyline3d polyline = new Polyline3d(vertexes, true);
            polyline.Layer = new Layer("polyline3d");
            polyline.Layer.Color.Index = 24;
            dxf.AddEntity(polyline);

            //block definition
            Block block = new Block("TestBlock");
            block.Entities.Add(new Line(new Vector3d(-5, -5, 5), new Vector3d(5, 5, 5)));
            block.Entities.Add(new Line(new Vector3d(5, -5, 5), new Vector3d(-5, 5, 5)));

            //insert
            Insert insert = new Insert(block, new Vector3d(5, 5, 5));
            insert.Layer = new Layer("insert");
            insert.Layer.Color.Index = 4;
            dxf.AddEntity(insert);

            //text
            TextStyle style=new TextStyle("True type font","Arial.ttf");
            Text text = new Text("Hello world!", Vector3d.Zero, 10.0f,style);
            text.Layer = new Layer("text");
            text.Layer.Color.Index = 8;
            text.Alignment = TextAlignment.TopRight;
            dxf.AddEntity(text);

            dxf.Save("AutoCad2007.dxf", DxfVersion.AutoCad2007);
            dxf.Save("AutoCad2004.dxf", DxfVersion.AutoCad2004);
            dxf.Save("AutoCad2000.dxf", DxfVersion.AutoCad2000);
            dxf.Save("AutoCad12.dxf", DxfVersion.AutoCad12);
        }