We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Failed to convert DXF to PNG

Hi Aspose,
I upgrade Aspose CAD from 20.9 to the lastest version 22.6. And then, I can not convert some dxf file to png. The exception threw is “Object reference not set to an instance of an object”
Bellow is my current code:

        using(var image = Image.Load(inFile))
        {
            // Create an instance of CadRasterizationOptions
            var rasterizationOptions = new CadRasterizationOptions
            {
                // Set page width & height
                PageWidth = image.Width,
                PageHeight = image.Height
            };

            //Get all layouts
            Aspose.CAD.FileFormats.Cad.CadImage cadImage = (Aspose.CAD.FileFormats.Cad.CadImage)image;
            Aspose.CAD.FileFormats.Cad.CadLayoutDictionary layouts = cadImage.Layouts;

            foreach(Aspose.CAD.FileFormats.Cad.CadObjects.CadLayout layout in layouts.Values)
            {
                rasterizationOptions.Layouts = new string[] { layout.LayoutName };
                // Create an instance of PngOptions for the resultant image
                ImageOptionsBase option = new PngOptions();
                // Set rasterization options
                option.VectorRasterizationOptions = rasterizationOptions;

                string outFilePath = Path.Combine(outFile, layout.LayoutName + "." + to);
                image.Save(outFilePath, option);
            }
        }

The failed is cause by the layout in cad image has null value. Do you have any advice for me to handle this problem ? If this is a bug, please help me check and fix it.
Thanks!
Sample : sample.zip (57.8 KB)

@dunghnguyen,
Hello.
A lot of things changed from 20.9, probably, earlier this case was processed in different way.
Unfortunately, the source of the error is the DXF file itself. It uses DXF R12 (AC1009) version that is very old and there were no “layout” concept at that time. So this file definitely has no information about layouts. Additionally, format became more strict since that time, for example, each entity should have handle as identifier, and this information is missing in this file too. So, you can export only “Model” layout here and some other issues may occur for such files too.