netDxf icon indicating copy to clipboard operation
netDxf copied to clipboard

Saving DxfDocument including a certain dimension causes error.

Open kyosukeSakurai opened this issue 3 years ago • 1 comments

Saving DxfDocument including a certain dimension causes error.

There is a Dimension that causes an error when adding and saving to DxfDocument.(dimension.dxf) The error reproduction code is as follows.

static void Main(string[] args)
 {
     DxfDocument dxffile = new DxfDocument();
     string debugfile = "C:\\tmp\\dimension.dxf";
     DxfDocument a = DxfDocument.Load(debugfile);
     var dimensions = a.Dimensions.ToList();
     List<EntityObject> tmp = new List<EntityObject>();
     foreach (netDxf.Entities.Dimension dim in dimensions)
     {
         netDxf.Entities.Dimension c = (netDxf.Entities.Dimension)dim.Clone();
         c.Block = (Block)dim.Block.Clone();
         tmp.Add(c as EntityObject);
     }
     dxffile.AddEntity(tmp);

     a.Save(@"C:\tmp\AfterDimension.dxf");
 }

note: To try the sample code, create a folder named 'tmp' directly under the C drive in advance to store the sample dxf file 'dimension.dxf'. dimension.zip

There is an error on line 3532 of DxfWriter.cs.

	case DimensionStyleOverrideType.FitOptions:
		xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 289));
		xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) styleOverride.Value));

I tentatively changed the code as follows, the error will not occur.(I don't think this is the right change...)

	case DimensionStyleOverrideType.FitOptions:
		xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 289));
		//xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) styleOverride.Value));
		xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short)0));

Would you please confirm if it's a code bug?

kyosukeSakurai avatar May 25 '21 08:05 kyosukeSakurai

This issue was fixed a few months ago with the 2.4.2 release, also the piece of code you have shown is also outdated.

haplokuon avatar May 26 '21 17:05 haplokuon