cart: empty [ Login ]

Writing custom Hatch pattern

1 
Termitt
4/3/2008 7:21 PM
Hi all, i have problem writing DXF with Hatch-Custom Pattern. When I use Pattern = null (not set), then DXF can be displayed in ACAD. But when I try to use custom Pattern, then DXF writing fails. Sometimes with 'OutOfMemory Exception':
C# Code:
 at System.Collections.Generic.List`1..ctor(Int32 capacity)   at -.|.-(Polyline3D[] borders, Point2D reference, Vector2D offset, Vector2D direction, Double flatness, Double[] dashes, Boolean fillInterior)   at -.|.-(Polyline3D[] borders, Point2D reference, Vector2D offset, Vector2D direction, Double flatness, Double[] dashPattern, Boolean fillInterior)   at -.|.-(Polyline3D[] borders, Point2D reference, Vector2D offset, Vector2D direction, Double flatness, Double[] dashPattern, Boolean fillInterior)   at WW.Cad.Model.Entities.DxfPattern.Line.-(Polyline3D[] boundaries, Point2D seed, Boolean fillInterior)   at WW.Cad.Model.Entities.DxfPattern.-(List`1 polylines, Polyline3D[] boundaries, Point2D seed, Boolean fillInterior)   at WW.Cad.Model.Entities.DxfHatch.-(Wireframe context)   at WW.Cad.Model.Entities.DxfHatch.-(Wireframe context)   at WW.Cad.Model.Entities.DxfHatch.DrawInternal(Wireframe context)   at WW.Cad.Model.Entities.DxfEntity.Draw(Wireframe context)   at WW.Cad.Model.DxfModel.Draw(Wireframe context)
According to TaskManager I have only about 540MB memory used of 2GB... I use this to setup the Hatch pattern.
C# Code:
DxfPattern pat = new DxfPattern(); pat.Lines.Add(new DxfPattern.Line()); pat.Lines[0].Offset = new Vector2D(5d,5d); pat.Lines[0].Angle = Math.PI * 0.25;
Most probably I set something wrong, but I have been trying ot whole day and I'm desperate. If anyone could help me, it would be great. thanks, Termitt
Wout
4/4/2008 12:38 AM
Hi Termitt, I think the problem is that you chose the pattern line's offset vector having the same angle as the pattern angle. The vector must at least have a component perpendicular to the pattern angle otherwise no hatching will happen ofcourse, the hatch line will just continue to be on the same line. Here's a working example (but see also the DxfHatch documentation contains a working example):
C# Code:
using System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Printing; using System.IO; using System.Text; using WW.Cad.Base; using WW.Cad.Drawing; using WW.Cad.Drawing.GDI; using WW.Cad.IO; using WW.Cad.Model; using WW.Cad.Model.Entities; using WW.Cad.Model.Tables; using WW.Cad.Test; using WW.Math; namespace ConsoleApplication {   class Program {     static void Main(string[] args) {       DxfModel model = new DxfModel();       DxfHatch hatch = new DxfHatch();       DxfPattern pat = new DxfPattern();       pat.Lines.Add(new DxfPattern.Line());       pat.Lines[0].DashLengths.AddRange(new double[] { 0.1d, -0.15d, 0d, -0.15d });       pat.Lines[0].Offset = new Vector2D(-0.15d, 0.15d);       pat.Lines[0].Angle = Math.PI * 0.25;       hatch.Pattern = pat;       DxfHatch.BoundaryPath boundaryPath = new DxfHatch.BoundaryPath();       boundaryPath.Type = BoundaryPathType.Polyline;       boundaryPath.PolylineData = new DxfHatch.BoundaryPath.Polyline(           new Point2D(0d, 0d),           new Point2D(1d, 1d),           new Point2D(0.5d, 2d),           new Point2D(-0.5d, 2d),           new Point2D(-1d, 1d)         );       boundaryPath.PolylineData.Closed = true;       hatch.BoundaryPaths.Add(boundaryPath);       hatch.Color = Color.Blue;       model.Entities.Add(hatch);       DxfWriter.WriteDxf('hatchtest.dxf', model);     }   } }
Thanks, Wout
Termitt
4/4/2008 9:27 PM
Hi Wout, now it works, great. I know about example in documentation, I have read it several times, but i never realized that i made a mistake in Offset direction ; ). Thank you for help, Termitt
1