Save dxf file in Java

2019-08-09 20:09发布

问题:

I am hoping that someone can help me here. I am using the yCad library to read a number of dxf files and output a composite model, to dxf format.

The initial process of reading the file is complete. However, when I save the file it is saved without the model.

Here is an example of the code used to save the dxf file

public static boolean SaveDxf(String outputPath, String fileName, Yxxf model)
{
    try
    {
        model.iohandler = new YutilIOHandler();
        model.ioname = new YutilIOHandlerName(fileName);
        model.ioname.dstfile = outputPath + "\\" + fileName + ".dxf";
        YdxfPutHandler handler = new YdxfPutHandler();
        handler.commandPutMainStart(model.iohandler, model);
        return true;
    }
    catch(Exception ex)
    {
        System.out.println("failed to save dxf file: " + ex.getMessage());
        return false;
    }
}

When the file is viewed from an editor an error is reported stating the model is empty.

The error occurs even when a dxf file is read and then saved with no manipulation.

回答1:

I have resolved this issue.

The resolution required a modification to the version of the YCad library that I was using due the following selection.

if (ent instanceof YxxfEntLine)
{
    YdxfPutEntLine.put(putbfr, (YxxfEntLine)ent);
}

NOTE: This may have been due to an out of date version of the library.

The method was modified to include all required types.

else if(ent instanceof YxxfEntPolyline)
{
    YdxfPutPolyline.put(putbfr, (YxxfEntPolyline)ent);
}

A number of new classes were added to the solution.

When I get time I will see if I can submit these modification to the source library, if they are required.



标签: java dxf