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); }
public void ToDxf() { netDxf.DxfDocument dxf = new netDxf.DxfDocument(); SaveFileDialog fdlg = new SaveFileDialog { DefaultExt = "DXF", Title = "Save As", Filter = "DXF(*.DXF)|.DXF", FilterIndex = 1, FileName = "Untitled", AddExtension = true, }; bool?result = fdlg.ShowDialog(); if (result.HasValue && result.Value) { foreach (IFigure f in Figures) { if (f is FigureBase) { var figure = f as FigureBase; //var boxculvert = (Shopdrawing.Structures.Culvert.BoxCulvertSection)f; figure.ToDxf(dxf); } } } dxf.Save(fdlg.FileName); }
/// <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); }
/// <summary> /// /// </summary> public Linetype() { DataContext = this; _document = new netDxf.DxfDocument(); _document.Linetypes.Clear(); InitializeComponent(); }
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); }
public virtual void ExportDXF_netDxf(Part DXF2Export, string filename, bool openFolder, bool openFile) { netDxf.DxfDocument dxf = DXF2Export.ToDXFDocument(); dxf.Save(filename); if (openFolder) { string path = System.IO.Path.GetDirectoryName(filename); System.Diagnostics.Process.Start(path); } if (openFile) { System.Diagnostics.Process.Start(filename); } }
/// <summary> /// Clone layer collection in document for modification /// </summary> /// <param name="dxfDocument"></param> public Layer(netDxf.DxfDocument dxfDocument) { foreach (netDxf.Tables.Layer layer in dxfDocument.Layers) { var newLayer = new DxfLayerExtended(layer.Name) { IsVisible = layer.IsVisible, IsFrozen = layer.IsFrozen, IsLocked = layer.IsLocked, Plot = layer.Plot, Color = layer.Color, Linetype = layer.Linetype, Lineweight = layer.Lineweight, Transparency = layer.Transparency, }; LayerCollection.Add(newLayer); } DataContext = this; InitializeComponent(); }
/// <summary> /// Export to dxf file /// </summary> /// <param name="fileName"></param> public virtual void ToDxf(netDxf.DxfDocument dxf) { }
//--------------------------------------------------------------------- public void Refresh( AxeCalc app ) { m_tuning.SetupProperties(); // calculate perfect string spacings if( m_bridgePickup.m_eStringSpacing == PickupSettings.Spacing.Perfect ) m_bridgePickup.m_dPerPoleStringSpacing = GetCrossFretboardLine( m_bridgePickup.m_dPosition ).length() / ( m_iStringCount - 1 ); if( m_middlePickup.m_eStringSpacing == PickupSettings.Spacing.Perfect ) m_middlePickup.m_dPerPoleStringSpacing = GetCrossFretboardLine( m_middlePickup.m_dPosition ).length() / ( m_iStringCount - 1 ); if( m_neckPickup.m_eStringSpacing == PickupSettings.Spacing.Perfect ) m_neckPickup.m_dPerPoleStringSpacing = GetCrossFretboardLine( m_neckPickup.m_dPosition ).length() / ( m_iStringCount - 1 ); RefreshFretCharts( app ); // cache the prefab used try { m_currentSaddlePrefab = m_saddlePrefabs[ m_eSaddleStyle ]; } catch { m_currentSaddlePrefab = null; } Type t = typeof( GuitarProperties ); m_calculatedStuff.Remove( "General", "Bridge angle" ); m_calculatedStuff.Remove( "General", "Nut angle" ); if( m_fBassScaleLength != m_fTrebleScaleLength ) { m_calculatedStuff.Add( new CustomProperty( "General", "Bridge angle", "The angle of the bridge from the vertical", "BridgeAngle", this, true, true ) ); m_calculatedStuff.Add( new CustomProperty( "General", "Nut angle", "The angle of the nut from the vertical", "NutAngle", this, true, true ) ); } /* Remove( "Aesthetics", "Fretboard block width" ); Remove( "Aesthetics", "Fretboard block spacing" ); if( m_eMarkerStyle == MarkerStyle.SquareBlocks ) { Add( new CustomProperty( "Aesthetics", "Fretboard block width", "Width of the square fretboard blocks", "SquareBlockWidth", this, false, true ) ); Add( new CustomProperty( "Aesthetics", "Fretboard block spacing", "Spacing between blocks & edge of fretboard", "SquareBlockEdgeSpacing", this, false, true ) ); }*/ }
public GuitarProperties( AxeCalc app, CustomClass calculatedStuff ) { // initialize the prefabs m_saddlePrefabs = new Dictionary<SaddleStyles, netDxf.DxfDocument>(); foreach( SaddleStyles style in Enum.GetValues( typeof( SaddleStyles ) ) ) { string strName = Enum.GetName( typeof( SaddleStyles ), style ); try { netDxf.DxfDocument dxf = new netDxf.DxfDocument(); dxf.Load( "Data/Saddles/" + strName + ".dxf" ); m_saddlePrefabs.Add( style, dxf ); } catch { } } m_calculatedStuff = calculatedStuff; m_iStringCount = 6; m_iFretCount = 22; m_iStraightFret = 8; ScaleLength = "630"; TotalBridgeStringSpacing = 51.85; // 52.5; TotalNutStringSpacing = 35.05; // 35.7; FretboardWidthAtNut = 43; FretboardWidthAt12th = 53; m_dFretwireWidth = 2.79; m_dFretwireCrownHeight = 1.32; m_bZeroFret = true; m_dZeroFretNutOffset = 8; m_dNutWidth = 5; m_dStringHeightAt12th = 3; m_dMinStringHeightAt12th = 1.5; m_dMaxStringHeightAt12th = 4; m_dDotRadius = 3; m_dDotEdgeSpacing = 6; m_eMarkerStyle = MarkerStyle.Centred; m_dSquareBlockSpacing = 3; m_dSquareBlockWidth = 30; SaddleStyle = SaddleStyles.Hardtail; m_bridgePickup.Type = PickupTypes.Humbucker; m_bridgePickup.m_dPosition = 43 / 630.0; m_neckPickup.Type = PickupTypes.Humbucker; m_neckPickup.m_dPosition = 148 / 630.0; /* fStratNeckPos = 6.375 / 25.5 fStratMiddlePos = 3.875 / 25.5 fStratBridgePos = 1.625 / 25.5 fStratBridgeBassPos = 1.815 / 25.5 fStratBridgeTreblePos = 1.435 / 25.5 fJBNeckPos = 6 / 34.0 fJBBridgePos = 2.13 / 34.0 fPRSNeckPos = 148 / 635.0 fPRSBridgePos = 43 / 635.0 */ // These are based on what D'Addario's Regular Light strings give on a 25.5" scale guitar m_dPlainSteelStringTensionTarget = 16; m_dNickelWoundStringTensionTarget = 18.5; m_tuning = new Tuning( this, m_calculatedStuff ); Type t = typeof( GuitarProperties ); //Add( new CustomProperty( this, m_iTestValue ) ); AddMarkedUpVariables( this ); Refresh( app ); }
/// <summary> /// /// </summary> /// <param name="document"></param> public Linetype(netDxf.DxfDocument document) { DataContext = this; _document = document; InitializeComponent(); }
public static void RegisterGraphArea(CmdlineParser parser) { var cmdReplaceToken = parser.AddCommand("graph-area", "compute area under graph XY", (parserGraphArea) => { var _decimalDelimiter = parserGraphArea.AddShort("d", "decimal separator (default=.)", "VAL"); var _fieldDelimiter = parserGraphArea.AddShort("f", "field separator (default=,)", "VAL"); var _genDxf = parserGraphArea.AddShort("x", "generate dxf lwpolyline output"); var _filename = parserGraphArea.AddMandatoryParameter("filename", "simple XY column file"); parserGraphArea.OnCmdlineMatch(() => { var genDxf = (bool)_genDxf; var pathfilename = (string)_filename; if (!File.Exists(pathfilename)) { System.Console.WriteLine($"can't find file [{pathfilename}]"); return; } string dxfPathfilename = null; netDxf.DxfDocument dxf = null; if (genDxf) { dxfPathfilename = Path.Combine( Path.GetDirectoryName(pathfilename), Path.GetFileNameWithoutExtension(pathfilename) + ".dxf"); dxf = new netDxf.DxfDocument(); } var decDelim = (string)_decimalDelimiter; var fieldDelim = (string)_fieldDelimiter; if (decDelim == null) { decDelim = "."; } if (fieldDelim == null) { fieldDelim = ","; } var ni = (NumberFormatInfo)CultureInfo.InvariantCulture.NumberFormat.Clone(); ni.NumberDecimalSeparator = decDelim; var area = 0d; var pts = new List <XYPt>(); using (var sr = new StreamReader(pathfilename)) { while (!sr.EndOfStream) { var line = sr.ReadLine().Trim(); if (line.Length != 0) { var ss = line.Split(fieldDelim); var x = double.Parse(ss[0], ni); var y = double.Parse(ss[1], ni); pts.Add(new XYPt() { x = x, y = y }); } } } pts = pts.OrderBy(w => w.x).ToList(); var MINY = pts.Min(w => w.y); var prevx = 0d; var prevy = 0d; int cnt = 0; netDxf.Entities.LwPolyline lw = null; if (dxf != null) { lw = new netDxf.Entities.LwPolyline(); } foreach (var pt in pts) { if (dxf != null) { lw.Vertexes.Add(new netDxf.Entities.LwPolylineVertex(pt.x, pt.y)); } if (cnt > 0) { var maxy = Max(prevy, pt.y); var miny = Min(prevy, pt.y); var b = (pt.x - prevx); area += b * (miny - MINY) + b * (maxy - miny) / 2; } prevx = pt.x; prevy = pt.y; ++cnt; } System.Console.WriteLine(Invariant($"area: {area}")); if (dxf != null) { dxf.AddEntity(lw); dxf.Save(dxfPathfilename, true); System.Console.WriteLine($"[{dxfPathfilename}] written."); } }); }); }
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); }
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; }
public SvgTransform(netDxf.DxfDocument doc) { }
public static void Convert() { string file = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); file = System.IO.Path.Combine(file, ".."); file = System.IO.Path.Combine(file, ".."); // file = System.IO.Path.Combine (file, "Zimmertyp_1_.dxf"); // file = System.IO.Path.Combine(file, "drawing.dxf"); file = System.IO.Path.Combine(file, "../DwgToSvgConverter/0001_GB01_OG14_0000_Aperture_dxf13.dxf"); // D:\Stefan.Steiger\Documents\Visual Studio 2013\Projects\SvgConverter\SvgConverter\drawing.dxf file = System.IO.Path.GetFullPath(file); // file = @"D:\stefan.steiger\Downloads\7602_GB01_OG01_0000_Aperture.dxf"; #if true // InfoDump.DumpFile (file); // DxfDocument doc = Test(file, "output.log"); // DxfDocument doc = Test(file); netDxf.DxfDocument doc = netDxf.DxfDocument.Load(file); // foreach (string ln in doc.Layers.Names) System.Console.WriteLine (ln); System.Console.WriteLine("\t{0}; count: {1}", netDxf.Entities.EntityType.Line, doc.Lines.Count); // https://www.alt-soft.com/tutorial/svg_tutorial/file_struct.html // <?xml version="1.0" standalone="no"?> // <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> // <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/PR-SVG-20010719/DTD/svg10.dtd"> // https://books.google.de/books?id=YemMcMyMIgEC&pg=PA115&lpg=PA115&source=bl&ots=-Uryzwrz1F&sig=vGiu9s87qjMXai0mV0TcVNiXmE4&hl=en&sa=X&ei=kqISVffTK8vtUomlhJAF&redir_esc=y#v=onepage&q&f=false // xmlns:dc="http://purl.org/dc/elements/1.1/" // xmlns:cc="http://creativecommons.org/ns#" // xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" // xmlns:svg="http://www.w3.org/2000/svg" cSVG SVG = new cSVG(); netDxf.Vector3 TopLeft = new netDxf.Vector3() { X = 0, Y = 0, Z = 0 }; netDxf.Vector3 BottomRight = new netDxf.Vector3() { X = 0, Y = 0, Z = 0 }; /* * foreach(netDxf.Blocks.Block x in doc.Blocks) * { * } */ foreach (netDxf.Entities.LwPolyline x in doc.LwPolylines) { if (System.StringComparer.OrdinalIgnoreCase.Equals("FM_OBJEKT_RAUM", x.Layer.Name)) { System.Console.WriteLine(x.Layer.Name); } } foreach (netDxf.Entities.EntityObject dim in doc.Dimensions) { System.Console.WriteLine(dim); } foreach (netDxf.Entities.Line l in doc.Lines) { TopLeft.X = System.Math.Min(TopLeft.X, l.StartPoint.X); TopLeft.X = System.Math.Min(TopLeft.X, l.EndPoint.X); TopLeft.Y = System.Math.Max(TopLeft.Y, l.StartPoint.Y); TopLeft.Y = System.Math.Max(TopLeft.Y, l.EndPoint.Y); BottomRight.X = System.Math.Max(BottomRight.X, l.StartPoint.X); BottomRight.X = System.Math.Max(BottomRight.X, l.EndPoint.X); BottomRight.Y = System.Math.Min(BottomRight.Y, l.StartPoint.Y); BottomRight.Y = System.Math.Min(BottomRight.Y, l.EndPoint.Y); } foreach (netDxf.Entities.Line l in doc.Lines) { long handle = System.Convert.ToInt64(l.Handle, 16); // System.Console.WriteLine( l.Handle ); System.Console.WriteLine(handle); System.Console.WriteLine(l.StartPoint); System.Console.WriteLine(l.EndPoint); // Transform netDxf.Vector3 vecStart = l.StartPoint - TopLeft; netDxf.Vector3 vecEnd = l.EndPoint - TopLeft; vecStart.Y *= -1; vecEnd.Y *= -1; // End Transform // Margin vecStart.X += 10; vecEnd.X += 10; vecStart.Y += 10; vecEnd.Y += 10; // End Margin //SVG.AddLine(l.StartPoint, l.EndPoint); SVG.AddLine(vecStart, vecEnd); } // Next l SVG.Save(ToSvgFile(file)); #endif // CreateSampleDocument(); // https://www.alt-soft.com/tutorial/svg_tutorial/file_struct.html // http://commons.wikimedia.org/wiki/SVG_examples // https://code.google.com/p/opus/source/browse/#svn%2Fbranches%2Fsvg%2FOpus.Core%2FSVG // https://code.google.com/p/opus/source/browse/branches/svg/Opus.Core/SVG/SVG.cs // http://kooboo.codeplex.com/ // http://www.java2s.com/Tutorial/CSharp/0540__XML/GetNamespaceURIPrefixandLocalName.htm // Console.WriteLine(doc.DocumentElement.NamespaceURI); // Console.WriteLine(doc.DocumentElement.Prefix); // Console.WriteLine(doc.DocumentElement.LocalName); }