cart: empty [ Login ]

Add DxfText causes exception on DxfWriter.Write

1 
CSGemini
5/25/2022 1:17 PM
Have opened an existing .dxf and can add entities such as lines etc without problem and save the file. If I try adding a dxfText entity: model.Entities.Add(new DxfText("Text", new Point3D(0d, 14d, 0d), 1d)); I get the following exception on writing the file: System.TypeInitializationException: 'The type initializer for 'WW.Math.Geometry.GeneralShape2D' threw an exception.' Operation is not valid due to the current state of the object. at WW.Math.Geometry.GeneralShape2D..Current(Point2D[] , Int32 )\r\n at WW.Math.Geometry.ShapeTool.AddToBounds(Bounds2D bounds, ISegment2DIterator iterator)\r\n at WW.Math.Geometry.GeneralShape2D.AddToBounds(Bounds2D bounds)\r\n at WW.Math.Geometry.CachedBoundsShape2D..ctor(IShape2D wrappedShape)\r\n at .(String , Color , Int16 , Boolean )\r\n at .(ICollection`1 , Matrix4D , Int16 )\r\n at .(ICollection`1 , Matrix4D , Int16 )\r\n at .(DxfText , Color , Int16 , Matrix4D , Bounds2D , Vector2D& , Vector2D& ,  )\r\n at WW.Cad.Model.Entities.DxfText.(IPathDrawer , Color , Int16 )\r\n at WW.Cad.Model.Entities.DxfText.DrawInternal(Wireframe context, IWireframeGraphicsFactory graphicsFactory)\r\n at WW.Cad.Drawing.BoundsCalculator.GetBounds(DxfModel model, Matrix4D modelTransform)\r\n at WW.Cad.Drawing.BoundsCalculator.GetBounds(DxfModel model)\r\n at WW.Cad.Model.DxfModel.(Boolean )\r\n at WW.Cad.Model.DxfModel.( )\r\n at WW.Cad.IO.DxfWriter.Write(Boolean validate)\r\n at WW.Cad.IO.DxfWriter.Write(String filename, DxfModel model, Boolean binary)\r\n at WW.Cad.IO.DxfWriter.Write(String filename, DxfModel model)\r\n
Wout
5/26/2022 9:56 AM
I can't reproduce this with the information in this post alone. - Wout
CSGemini
5/26/2022 10:58 AM
I think I have narrowed this down a bit. If I simply try opening the attached dxf and save it again under a new name via DxfWriter I get the same error. I was originally thinking it was because of the text I was adding but looks more like something it does not like in the file....
CSGemini
5/26/2022 11:00 AM
var fileName = @"c:\a\original.dxf"; //var fileName = @"c:\a\openone.dxf"; using (FileStream stream = new FileStream(fileName, FileMode.Open)) { DxfReader reader = new DxfReader(stream); reader.Read(); DxfModel model = reader.Model; DxfWriter.Write(@"c:\a\newone2.dxf", reader.Model); }
CSGemini
5/26/2022 11:03 AM
If I remove all the existing text elements it saves ok: using (FileStream stream = new FileStream(fileName, FileMode.Open)) { DxfReader reader = new DxfReader(stream); reader.Read(); DxfModel model = reader.Model; foreach (var e in model.Entities.ToList()) { if (e.EntityType == "TEXT") { model.Entities.Remove(e); } } DxfWriter.Write(@"c:\a\newone2.dxf", reader.Model);
Wout
5/26/2022 12:47 PM
Hi, I still can't reproduce it. Tested with CadLib 5.0.39.41. - Wout
CSGemini
5/26/2022 1:42 PM
I found the problem. My project was running .net 6. Moved it to .Net 5 and all worked fine.
1