Dwg转dwg图纸效果和原图不一样问题

1.png (5.5 KB)

2.png (6.5 KB)

图1为原始的dwg,图2为转换后的dwg
并且数字30.78和46.3原来是线条,后面变成了粗体。

下面是我的代码:

 License license = new License();
license.setLicense("Aspose.CAD.Java.lic");
LoadOptions loadOptions = new LoadOptions();
loadOptions.setSpecifiedEncoding(CodePages.SimpChinese);
CadImage cadImage = (CadImage)Image.load("D:\\dwgtest\\demo2.dwg",loadOptions);
cadImage.updateSize();
for (CadEntityBase entity : cadImage.getEntities()) {
               if (entity instanceof CadTolerance) {
                    CadTolerance tolerance = (CadTolerance) entity;
                    String currentText = tolerance.getToleranceString();
                    // replacing concentricity symbol
                    tolerance.setToleranceString(currentText.replace("{\\Fgdt;r}","\u2609"));
                }

}

for (int i = 0, size = cadImage.getLayers().size(); i < size; i++)
{
    CadLayerTable layer = (CadLayerTable) cadImage.getLayers().get_Item(i);
    layer.setLineWeight((short) 0);
}

DwgOptions dwgOptions = new DwgOptions();
dwgOptions.setOutputMode(CadOutputMode.Render);
cadImage.save("D:\\dwgtest\\demo2dwg.dwg",dwgOptions);

@wangwei001

Cause

The issue you’re experiencing with the converted DWG file, where certain elements like the numbers have changed from lines to bold text, is likely due to how line weights and text styles are managed during the conversion process. The line weight settings in your code may not be applied correctly, resulting in unexpected rendering outcomes.

Solution

To ensure that the line weights are set correctly and to prevent changes in text styles during conversion, you can modify your code as follows:

  1. Set Line Weights: Explicitly set the line weight for each entity rather than just for the layers.
  2. Check Text Entities: Ensure that the properties of specific text entities are preserved during the conversion to avoid unexpected changes.

Code

Here’s an updated version of your code that includes setting the line weight for each entity:

License license = new License();
license.setLicense("Aspose.CAD.Java.lic");
LoadOptions loadOptions = new LoadOptions();
loadOptions.setSpecifiedEncoding(CodePages.SimpChinese);
CadImage cadImage = (CadImage)Image.load("D:\\dwgtest\\demo2.dwg", loadOptions);
cadImage.updateSize();

for (CadEntityBase entity : cadImage.getEntities()) {
    if (entity instanceof CadTolerance) {
        CadTolerance tolerance = (CadTolerance) entity;
        String currentText = tolerance.getToleranceString();
        // Replacing concentricity symbol
        tolerance.setToleranceString(currentText.replace("{\\Fgdt;r}", "\u2609"));
    }
    // Set line weight for each entity
    entity.setLineWeight((short) 0); // Adjust this value as needed
}

DwgOptions dwgOptions = new DwgOptions();
dwgOptions.setOutputMode(CadOutputMode.Render);
cadImage.save("D:\\dwgtest\\demo2dwg.dwg", dwgOptions);

Next Steps

  1. Test the updated code to determine if it resolves the issue with the text and line weights.
  2. If the problem persists, check the original DWG file for any specific attributes that might be affecting the conversion.
  3. Review the documentation on handling line weights and text styles for additional insights.

Please implement these changes and let me know if you need further assistance!

加了entity.setLineWeight((short) 0);
试了,并没有效果。

@wangwei001,
此结果符合预期。使用 CadOutputMode.Render 选项时,初始图形将转换为线条并写入文件。传递 CadOutputMode.Convert 应该用于 DWG 到 DWG 的转换,但我们无法完全支持不同类型的 DWG。请尝试使用 java cadImage.save(outDwg); 在没有选项的情况下运行,如果运行不成功,请附上初始文件,我们将进行调试并考虑修复。