Converting dxf to dwg issues using java and aspose (file not opening)

I’ve implemented the following sample code for DXF to DWG conversion. However, when I try to open the resulting DWG files in DWG TrueView, they fail to open. This makes me question if the conversion process is producing valid DWG files

package sample.converter.asposedwgtodxfconverter;

import com.aspose.cad.Image;
import com.aspose.cad.imageoptions.CadRasterizationOptions;
import com.aspose.cad.imageoptions.DwgOptions;

/**

  • Hello world!

*/
public class AsposeDxfToDwgConverter
{

public static void main(String[] args) {
    String inputFilePath  = "C:\\PSC\\project\\pscstsworkspace\\\\asposedwgtodxfconverter\\src\\main\\resources\\T-4R_1_CONVERTED2.dxf";
    String outputFile = "C:\\PSC\\project\\pscstsworkspace\\\\asposedwgtodxfconverter\\src\\main\\resources\\T-4R_1_CONVERTED2.DWG";

    try {

    	   
    	System.out.println("converstion from dxf to dwg started..");
    	Image image = Image.load(inputFilePath);
    	DwgOptions options = new DwgOptions();

		CadRasterizationOptions cadRasterizationOptions=new CadRasterizationOptions();
		
		options.setVectorRasterizationOptions(cadRasterizationOptions);
		image.save(outputFile,options);
    	System.out.println("\nThe converstion from dxf to dwg is completed!");
        
    } catch (Exception e) {
        e.printStackTrace();
    }
    
}

}

I need your help as soon as possible

with regards

@henokeshete

It seems you are experiencing issues with the conversion of DXF files to DWG format using Aspose.CAD for Java, specifically that the resulting DWG files are not opening in DWG TrueView. Here are a few suggestions to troubleshoot and potentially resolve the issue:

  1. Check Aspose.CAD Version: Ensure that you are using the latest version of Aspose.CAD for Java. There was a known issue with DXF to DWG conversion that has been addressed in version 22.2. If you are using an older version, consider upgrading to this version or later to benefit from the fixes.

  2. Verify Input File: Make sure that the input DXF file is valid and not corrupted. You can try opening the DXF file in another CAD application to confirm that it is functioning correctly.

  3. Review Conversion Options: The code you provided uses CadRasterizationOptions for vector rasterization. Depending on your specific requirements, you might want to explore other options or configurations that could affect the output. Ensure that the options you are using are appropriate for the type of content in your DXF file.

  4. Error Handling: Implement more detailed error handling in your code to capture any exceptions that may occur during the loading or saving process. This can provide insights into what might be going wrong.

Here is a modified version of your code with enhanced error handling:

package sample.converter.asposedwgtodxfconverter;

import com.aspose.cad.Image;
import com.aspose.cad.imageoptions.CadRasterizationOptions;
import com.aspose.cad.imageoptions.DwgOptions;

public class AsposeDxfToDwgConverter {

    public static void main(String[] args) {
        String inputFilePath = "C:\\PSC\\project\\pscstsworkspace\\asposedwgtodxfconverter\\src\\main\\resources\\T-4R_1_CONVERTED2.dxf";
        String outputFile = "C:\\PSC\\project\\pscstsworkspace\\asposedwgtodxfconverter\\src\\main\\resources\\T-4R_1_CONVERTED2.DWG";

        try {
            System.out.println("Conversion from DXF to DWG started...");
            Image image = Image.load(inputFilePath);
            DwgOptions options = new DwgOptions();
            CadRasterizationOptions cadRasterizationOptions = new CadRasterizationOptions();
            options.setVectorRasterizationOptions(cadRasterizationOptions);
            image.save(outputFile, options);
            System.out.println("Conversion from DXF to DWG completed successfully!");
        } catch (Exception e) {
            System.err.println("An error occurred during conversion: " + e.getMessage());
            e.printStackTrace();
        }
    }
}

By following these steps and ensuring you are using the latest version of the library, you should be able to resolve the issues with the DWG files not opening. If the problem persists, consider reaching out to Aspose support for further assistance.

@henokeshete,
Hi,
could you please share the test file so we can reproduce the issue.