예제 #1
1
        static void doDXF(List<PolylineVertex> vertexes, double[] x)
        {
            // create a dxf for those who want to "see" the calibration
            netDxf.DxfDocument dxf = new netDxf.DxfDocument();

            Polyline polyline = new Polyline(vertexes, true);
            polyline.Layer = new Layer("polyline");
            polyline.Layer.Color.Index = 24;
            dxf.AddEntity(polyline);

            var pnt = new Point(new netDxf.Vector3(-(float) x[0], -(float) x[1], -(float) x[2]));
            pnt.Layer = new Layer("new offset");
            pnt.Layer.Color.Index = 21;
            dxf.AddEntity(pnt);

            dxf.Save(Settings.GetUserDataDirectory() + "magoffset.dxf");

            log.Info("dxf Done " + DateTime.Now);
        }
예제 #2
0
        static void Main(string[] args)
        {
            var tol = 1e-8;
            var R   = 100;

            var dxf     = new netDxf.DxfDocument();
            var ang     = 0d;
            var angStep = 10d.ToRad();
            var angElev = 20d.ToRad();

            var o = Vector3D.Zero;
            var p = new Vector3D(R, 0, 0);

            Circle3D circ = null;

            while (ang < 2 * PI)
            {
                var l     = new Line3D(o, p.RotateAboutZAxis(ang));
                var l_ent = l.DxfEntity;
                l_ent.Color = netDxf.AciColor.Cyan;
                dxf.AddEntity(l_ent);

                var arcCS   = new CoordinateSystem3D(o, l.V, Vector3D.ZAxis);
                var arc     = new Arc3D(tol, arcCS, R, 0, angElev);
                var arc_ent = arc.DxfEntity;
                arc_ent.Color = netDxf.AciColor.Yellow;
                dxf.AddEntity(arc_ent);

                var arc2CS = new CoordinateSystem3D(l.To - R * Vector3D.ZAxis,
                                                    Vector3D.ZAxis, Vector3D.Zero - l.To);
                var arc2     = new Arc3D(tol, arc2CS, R, 0, PI / 2);
                var arc2_ent = arc2.DxfEntity;
                arc2_ent.Color = netDxf.AciColor.Green;
                dxf.AddEntity(arc2_ent);

                if (circ == null)
                {
                    circ = new Circle3D(tol,
                                        CoordinateSystem3D.WCS.Move(Vector3D.ZAxis * arc.To.Z),
                                        arc.To.Distance2D(Vector3D.Zero));
                    var circ_ent = circ.DxfEntity;
                    circ_ent.Color = netDxf.AciColor.Yellow;
                    dxf.AddEntity(circ_ent);
                }

                ang += angStep;
            }

            dxf.Viewport.ShowGrid = false;
            dxf.Save("output.dxf", isBinary: true);
        }
예제 #3
0
        /// <summary>
        /// Renders the model in dxf to the returned stream.
        /// </summary>
        /// <param name="model">The model to render</param>
        public Stream Render(Model model)
        {
            var doc     = new netDxf.DxfDocument(netDxf.Header.DxfVersion.AutoCad2018);
            var context = new DxfRenderContext();

            context.Model = model;

            foreach (var element in model.Elements.Values)
            {
                if (!_dxfCreators.TryGetValue(element.GetType(), out var converter))
                {
                    continue;
                }
                if (converter.TryToCreateDxfEntity(element, context, out var entity))
                {
                    doc.AddEntity(entity);
                }
            }

            var stream = new MemoryStream();

            doc.Save(stream);

            return(stream);
        }
예제 #4
0
        public netDxf.DxfDocument ToDXFDocument()
        {
            PointD[] boundary   = this.Boundary;
            PointD   sizeP      = boundary[1] - boundary[0];
            double   longLength = sizeP.ToArray().Max();

            netDxf.DxfDocument doc = new netDxf.DxfDocument(netDxf.Header.DxfVersion.AutoCad2007);

            //標註設定
            netDxf.Tables.DimensionStyle StandardDimStyle = doc.DimensionStyles["Standard"];
            StandardDimStyle.DIMDEC   = (short)3;
            StandardDimStyle.DIMATFIT = 3;
            StandardDimStyle.DIMASZ   = longLength / 80;
            StandardDimStyle.DIMTXT   = longLength / 120;

            //依圖層
            List <Layer> allLayers = (from entity in this.Entities.Values
                                      where entity is Layer
                                      select(Layer) entity).ToList();

            foreach (var layer in allLayers)
            {
                Tuple <netDxf.Tables.Layer, List <netDxf.Entities.EntityObject> > LayerAndEntities = layer.ToDxfEntitiesAndLayer();
                netDxf.Tables.Layer dxfLayer = LayerAndEntities.Item1;
                List <netDxf.Entities.EntityObject> entities = LayerAndEntities.Item2;
                //doc.Layers.Add(dxfLayer);
                foreach (var item in entities)
                {
                    if (item is netDxf.Entities.Dimension)
                    {
                        (item as netDxf.Entities.Dimension).Style = StandardDimStyle;
                    }
                    doc.AddEntity(item);
                }
            }


            //依元素
            netDxf.Tables.Layer defualtLayer = new netDxf.Tables.Layer("defualt");
            List <IToDXFEntity> Entities     = (from entity in this.Entities.Values
                                                where entity is IToDXFEntity
                                                select(IToDXFEntity) entity).ToList();

            foreach (var entity in Entities)
            {
                netDxf.Entities.EntityObject dxfEntity = entity.ToDXFEntity();
                if (dxfEntity != null)
                {
                    dxfEntity.Layer = defualtLayer;
                    doc.AddEntity(dxfEntity);
                }
            }
            List <IToDXFEntities> MultEntities = (from entity in this.Entities.Values
                                                  where entity is IToDXFEntities
                                                  select(IToDXFEntities) entity).ToList();

            foreach (var entity in MultEntities)
            {
                foreach (netDxf.Entities.EntityObject item in entity.ToDXFEntities())
                {
                    item.Layer = defualtLayer;
                    doc.AddEntity(item);
                }
            }

            return(doc);
        }
예제 #5
0
        public netDxf.DxfDocument ToDXFDocument()
        {
            PointD[] boundary = this.Boundary;
            PointD sizeP = boundary[1] - boundary[0];
            double longLength = sizeP.ToArray().Max();
            netDxf.DxfDocument doc = new netDxf.DxfDocument(netDxf.Header.DxfVersion.AutoCad2007);

            //標註設定
            netDxf.Tables.DimensionStyle StandardDimStyle = doc.DimensionStyles["Standard"];
            StandardDimStyle.DIMDEC = (short)3;
            StandardDimStyle.DIMATFIT = 3;
            StandardDimStyle.DIMASZ = longLength / 80;
            StandardDimStyle.DIMTXT = longLength / 120;

            //依圖層
            List<Layer> allLayers = (from entity in this.Entities.Values
                                     where entity is Layer
                                     select (Layer)entity).ToList();
            foreach (var layer in allLayers)
            {
                Tuple<netDxf.Tables.Layer, List<netDxf.Entities.EntityObject>> LayerAndEntities = layer.ToDxfEntitiesAndLayer();
                netDxf.Tables.Layer dxfLayer = LayerAndEntities.Item1;
                List<netDxf.Entities.EntityObject> entities = LayerAndEntities.Item2;
                //doc.Layers.Add(dxfLayer);
                foreach (var item in entities)
                {
                    if (item is netDxf.Entities.Dimension)
                        (item as netDxf.Entities.Dimension).Style = StandardDimStyle;
                    doc.AddEntity(item);
                }
            }
            

            //依元素
            netDxf.Tables.Layer defualtLayer = new netDxf.Tables.Layer("defualt");
            List<IToDXFEntity> Entities = (from entity in this.Entities.Values
                                                  where entity is IToDXFEntity
                                                  select (IToDXFEntity)entity).ToList();
            foreach (var entity in Entities)
            {
                netDxf.Entities.EntityObject dxfEntity = entity.ToDXFEntity();
                if (dxfEntity != null)
                {
                    dxfEntity.Layer = defualtLayer;
                    doc.AddEntity(dxfEntity); 
                }
            }
            List<IToDXFEntities> MultEntities = (from entity in this.Entities.Values
                                             where entity is IToDXFEntities
                                             select (IToDXFEntities)entity).ToList();
            foreach (var entity in MultEntities)
            {
                foreach (netDxf.Entities.EntityObject item in entity.ToDXFEntities())
                {
                    item.Layer = defualtLayer;
                    doc.AddEntity(item);
                }
            }

            return doc;
        }