Ejemplo n.º 1
3
        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");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Convert a Nucleus point object to a netDXF one
        /// </summary>
        /// <param name="pt"></param>
        /// <returns></returns>
        public static nDE.Point Convert(Point pt)
        {
            var result = new nDE.Point(Convert(pt.Position));

            SetAttributes(result, pt.Attributes);
            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Fügt Entity Objekte in einer bereits vorhandenen DXF Datei hinzu.
        /// </summary>
        /// <param name="dxf_path"> Pfad der DXF Datei, wo hinzugefügt werden soll</param>
        /// <param name="listObj"> Liste der hinzuzufügenden Entity Objekte</param>
        static public void JoinToDxF(string dxf_path, ElementManager.workpiece workPiece, params EntityObject[] listObj)
        {
            DxfDocument doc;

            if (File.Exists(dxf_path))
            {
                FileInfo file = new FileInfo(dxf_path);
                if (file.Extension == ".dxf")
                {
                    doc = DxfDocument.Load(dxf_path);
                    foreach (EntityObject item in listObj)
                    {
                        item.Layer = new netDxf.Tables.Layer(workPiece.werkzeugName);

                        doc.AddEntity(item);
                    }
                    netDxf.Entities.Point newPt = new netDxf.Entities.Point(workPiece.height, workPiece.width, workPiece.depth);
                    doc.AddEntity(newPt);
                    doc.Save(dxf_path);
                }
                else
                {
                    throw new Exception(" Error NTB_DXF_200003 : The file you gave is not a dxf file");
                }
            }
            else
            {
                throw new Exception(" Error NTB_DXF_200004 : The path you entered is not corrrect");
            }
        }
Ejemplo n.º 4
0
        public void saveDxfFromListListPoints(string savePath, List <List <System.Drawing.Point> > listListPoints)
        {
            ListAddedElements_as_List_Of_Point = listListPoints;
            dxf_File = new DxfDocument(netDxf.Header.DxfVersion.AutoCad2013);

            listToPolyline          = ToPolyLine2(ListAddedElements_as_List_Of_Point);
            ListAddedElements_as_PL = new List <List <shapes.Polyline> >();
            ListAddedElements_as_PL.Add(listToPolyline);
            allLists_LwPolyline = ToLwPolyline2(ListAddedElements_as_PL);


            foreach (List <LwPolyline> List_LwPL in allLists_LwPolyline)
            {
                foreach (LwPolyline LwPL in List_LwPL)
                {
                    LwPL.Layer = new netDxf.Tables.Layer(Werkzeug);
                    dxf_File.AddEntity(LwPL);
                }
            }

            netDxf.Entities.Point newPt = new netDxf.Entities.Point(Width, Height, Depth);
            dxf_File.AddEntity(newPt);

            dxf_File.Save(savePath);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Fügt Arbeitseigenschaften in einer bereits vorhandenen DXF Datei hinzu.
 /// </summary>
 /// <param name="dxf_path">Pfad des DXF Documents, wo es hingespeichert werden soll</param>
 /// <param name="doc">DXF Document wo es hinzugefügt werden soll</param>
 /// <param name="workPiece">Entsprechende Arbeitseigenschaften</param>
 static public void JoinToDxF(string dxf_path, ref DxfDocument doc, ElementManager.workpiece workPiece)
 {
     foreach (LwPolyline item in doc.LwPolylines)
     {
         item.Layer = new netDxf.Tables.Layer(workPiece.werkzeugName);
     }
     netDxf.Entities.Point newPt = new netDxf.Entities.Point(workPiece.height, workPiece.width, workPiece.depth);
     doc.AddEntity(newPt);
     doc.Save(dxf_path);
 }
Ejemplo n.º 6
0
		/*Draw Point*/
		public static void DrawPoint(netDxf.Entities.Point xPoint, Canvas mainCanvas)
		{
			double size = 15.0;
			AciColor myColor = xPoint.getColor();
			Canvas canvas1 = DrawUtils.GetPoint(TypeConverter.ToMediaColor(myColor.ToColor()), size, 0);
			getMaxPt(xPoint.Position);
			Canvas.SetLeft(canvas1, xPoint.Position.X - size);
			Canvas.SetTop(canvas1, mainCanvas.Height - (xPoint.Position.Y + size));
			mainCanvas.Children.Add(canvas1);

		}
Ejemplo n.º 7
0
        /// <summary>
        /// Fügt Entity Objekte in einer bereits vorhandenen DXF Datei hinzu.
        /// </summary>
        /// <param name="dxf_path">Pfad des DXF Documents, wo es hingespeichert werden soll</param>
        /// <param name="doc">DXF Document wo es hinzugefügt werden soll</param>
        /// <param name="workPiece">Entsprechende Arbeitseigenschaften</param>
        /// <param name="listObj">Liste der hinzuzufügenden Entity Objekte</param>
        static public void JoinToDxF(string dxf_path, ref DxfDocument doc, ElementManager.workpiece workPiece, params EntityObject[] listObj)
        {
            foreach (EntityObject item in listObj)
            {
                item.Layer = new netDxf.Tables.Layer(workPiece.werkzeugName);

                doc.AddEntity(item);
            }
            netDxf.Entities.Point newPt = new netDxf.Entities.Point(workPiece.height, workPiece.width, workPiece.depth);
            doc.AddEntity(newPt);
            doc.Save(dxf_path);
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Convert a Nucleus point cloud to a set of netDXF points
 /// </summary>
 /// <param name="cloud"></param>
 /// <param name="result"></param>
 /// <returns></returns>
 public static IList <nDE.Point> Convert(Cloud cloud, IList <nDE.Point> result = null)
 {
     if (result == null)
     {
         result = new List <nDE.Point>();
     }
     foreach (Vertex v in cloud.Vertices)
     {
         var pt = new nDE.Point(Convert(v.Position));
         SetAttributes(pt, cloud.Attributes);
         result.Add(pt);
     }
     return(result);
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Erstellt die letzendliche DXF Datei und speichert die ab
        /// </summary>
        /// <param name="File_path_saving"> Der Pfad , wo gespeichert wird</param>
        public void Set_Dxf_File(string File_path_saving)
        {
            dxf_File = new DxfDocument(netDxf.Header.DxfVersion.AutoCad2013);

            ListAddedElements_as_PLS = ToPolylineSegment(ListAddedElements);
            ListAddedElements_as_PL  = ConvertPolyLineSegmentsToPolyline(ListAddedElements_as_PLS);
            allLists_LwPolyline      = ToLwPolyline2(ListAddedElements_as_PL);

            foreach (List <LwPolyline> list_LwPL in allLists_LwPolyline)
            {
                foreach (LwPolyline LwPL in list_LwPL)
                {
                    LwPL.Layer = new netDxf.Tables.Layer(Werkzeug);
                    dxf_File.AddEntity(LwPL);
                }
            }

            netDxf.Entities.Point newPt = new netDxf.Entities.Point(Width, Height, Depth);
            dxf_File.AddEntity(newPt);

            dxf_File.Save(File_path_saving);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Creates a new Point that is a copy of the current instance.
        /// </summary>
        /// <returns>A new Point that is a copy of this instance.</returns>
        public override object Clone()
        {
            Point entity = new Point
            {
                //EntityObject properties
                Layer = (Layer)this.layer.Clone(),
                LineType = (LineType)this.lineType.Clone(),
                Color = (AciColor)this.color.Clone(),
                Lineweight = (Lineweight)this.lineweight.Clone(),
                Transparency = (Transparency)this.transparency.Clone(),
                LineTypeScale = this.lineTypeScale,
                Normal = this.normal,
                //Point properties
                Position = this.position,
                Rotation = this.rotation,
                Thickness = this.thickness
            };

            foreach (XData data in this.XData.Values)
                entity.XData.Add((XData)data.Clone());

            return entity;

        }
Ejemplo n.º 11
0
 /// <summary>
 /// Convert a netDXF point to a Nucleus cloud.
 /// NOTE: This may be modified if ever a Nucleus single point
 /// equivalent is introduced.
 /// </summary>
 /// <param name="point"></param>
 /// <returns></returns>
 public static Point Convert(nDE.Point point)
 {
     return(new Point(Convert(point.Position), ExtractAttributes(point)));
 }
Ejemplo n.º 12
0
        private Point ReadPoint()
        {
            Vector3 location = Vector3.Zero;
            Vector3 normal = Vector3.UnitZ;
            double thickness = 0.0;
            double rotation = 0.0;
            List<XData> xData = new List<XData>();

            this.chunk.Next();
            while (this.chunk.Code != 0)
            {
                switch (this.chunk.Code)
                {
                    case 10:
                        location.X = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 20:
                        location.Y = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 30:
                        location.Z = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 39:
                        thickness = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 210:
                        normal.X = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 220:
                        normal.Y = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 230:
                        normal.Z = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 50:
                        rotation = 360.0 - this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 1001:
                        string appId = this.DecodeEncodedNonAsciiCharacters(this.chunk.ReadString());
                        XData data = this.ReadXDataRecord(appId);
                        xData.Add(data);
                        break;
                    default:
                        if (this.chunk.Code >= 1000 && this.chunk.Code <= 1071)
                            throw new DxfInvalidCodeValueEntityException(this.chunk.Code, this.chunk.ReadString(),
                                "The extended data of an entity must start with the application registry code.");
                        this.chunk.Next();
                        break;
                }
            }

            Point entity = new Point
            {
                Position = location,
                Thickness = thickness,
                Rotation = rotation,
                Normal = normal
            };

            entity.XData.AddRange(xData);

            return entity;
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Erstellt die letzendliche DXF Datei und speichert die ab
        /// </summary>
        /// <param name="File_path_saving"> Der Pfad , wo gespeichert wird</param>
        public void Set_Dxf_File(string File_path_saving)
        {
            dxf_File = new DxfDocument(netDxf.Header.DxfVersion.AutoCad2013);
            switch (input)
            {
                #region Erste Möglichkeit von Eingabeparametern : hinzugefügte Elemente
            case Inputs.AddedElements:
                ListAddedElements_as_PLS = ToPolylineSegment(ListAddedElements);
                ListAddedElements_as_PL  = ToPolyLine(ListAddedElements_as_PLS);
                allLists_LwPolyline      = ToLwPolyline2(ListAddedElements_as_PL);

                foreach (List <LwPolyline> list_LwPL in allLists_LwPolyline)
                {
                    foreach (LwPolyline LwPL in list_LwPL)
                    {
                        LwPL.Layer = new netDxf.Tables.Layer(Werkzeug);
                        dxf_File.AddEntity(LwPL);
                    }
                }
                break;
                #endregion

                #region zweite Möglichkeit von Eingabeparametern : Polylinien
            case Inputs.AddedElements_asPL:
                allLists_LwPolyline = ToLwPolyline2(ListAddedElements_as_PL);

                foreach (List <LwPolyline> list_LwPL in allLists_LwPolyline)
                {
                    foreach (LwPolyline LwPL in list_LwPL)
                    {
                        LwPL.Layer = new netDxf.Tables.Layer(Werkzeug);
                        dxf_File.AddEntity(LwPL);
                    }
                }
                break;
                #endregion

                #region dritte Möglichkeit von Eingabeparametern : Liste Polyline Segmente
            case Inputs.AddedElements_asPLS:
                ListAddedElements_as_PL = ToPolyLine(ListAddedElements_as_PLS);
                allLists_LwPolyline     = ToLwPolyline2(ListAddedElements_as_PL);

                foreach (List <LwPolyline> list_LwPL in allLists_LwPolyline)
                {
                    foreach (LwPolyline LwPL in list_LwPL)
                    {
                        LwPL.Layer = new netDxf.Tables.Layer(Werkzeug);
                        dxf_File.AddEntity(LwPL);
                    }
                }
                break;
                #endregion

                #region vierte Möglichkeit von Eingabeparametern : LwPolylinien
            case Inputs.LwPolyline:
                foreach (LwPolyline LwPL in listToLwPolyline)
                {
                    LwPL.Layer = new netDxf.Tables.Layer(Werkzeug);
                    dxf_File.AddEntity(LwPL);
                }
                break;
                #endregion

                #region fünfte Möglichkeit von Eingabeparametern : pathgeometry
            case Inputs.Pathgeometry:
                PolyLineSegments = TryParseToPolySegment(pathGeo);
                listToLwPolyline = TryToLwPolyline(PolyLineSegments);
                foreach (LwPolyline LwPL in listToLwPolyline)
                {
                    LwPL.Layer = new netDxf.Tables.Layer(Werkzeug);
                    dxf_File.AddEntity(LwPL);
                }
                break;
                #endregion

                #region sechste Möglichkeit von Eingabeparametern : List of Points
            case Inputs.ListOfPoints:

                listToPolyline          = ToPolyLine2(ListAddedElements_as_List_Of_Point);
                ListAddedElements_as_PL = new List <List <sh.Polyline> >();
                ListAddedElements_as_PL.Add(listToPolyline);
                allLists_LwPolyline = ToLwPolyline2(ListAddedElements_as_PL);
                foreach (List <LwPolyline> List_LwPL in allLists_LwPolyline)
                {
                    foreach (LwPolyline LwPL in List_LwPL)
                    {
                        LwPL.Layer = new netDxf.Tables.Layer(Werkzeug);
                        dxf_File.AddEntity(LwPL);
                    }
                }
                break;



                #endregion

                #region siebte Möglichkeit von Eingabeparametern : keine
            case Inputs.nothing:
                throw new Exception("Error NTB_DXF_200002: NTB_DXF_  object has been not defined");
                break;
                #endregion
            }
            netDxf.Entities.Point newPt = new netDxf.Entities.Point(Height, Width, Depth);
            dxf_File.AddEntity(newPt);

            dxf_File.Save(File_path_saving);
        }