Java sdk 怎么修改元素后另存为 dwg 文件

java sdk 怎么修改元素后另存为 dwg 文件

@komorebi,
你好。
您能否澄清这个问题 - 您在谈论哪些元素?

我想使用的 SDK 为 Aspose.CAD for Java,希望通过该 SDK 实现实现读取 DWG 图片,然后修改里边的text 文本,然后另存为 DWG 文件

    // 加载原始的 DWG 文件
    String inputFilePath = "/Users/bytedance/IdeaProjects/cad-service/files/viewer/s.dwg";
    CadImage cadImage = (CadImage) Image.load(inputFilePath);


    String outputFilePath = "/Users/bytedance/IdeaProjects/cad-service/files/viewer/tt11.dwg";
    cadImage.save(outputFilePath);

Exception in thread “main” java.lang.NullPointerException
at com.aspose.cad.internal.gI.a.b(Unknown Source)
at com.aspose.cad.internal.gI.a.b(Unknown Source)
at com.aspose.cad.internal.gI.a.write(Unknown Source)
at com.aspose.cad.internal.gA.c.a(Unknown Source)
at com.aspose.cad.internal.go.al.write(Unknown Source)
at com.aspose.cad.internal.gA.a.a(Unknown Source)
at com.aspose.cad.internal.gA.a.write(Unknown Source)
at com.aspose.cad.internal.gA.b.write(Unknown Source)
at com.aspose.cad.internal.hQ.a.c(Unknown Source)
at com.aspose.cad.internal.hQ.a.write(Unknown Source)
at com.aspose.cad.fileformats.cad.CadImage.c(Unknown Source)
at com.aspose.cad.DataStreamSupporter.a(Unknown Source)
at com.aspose.cad.DataStreamSupporter.save(Unknown Source)
at com.bytedance.ea.cad.sdk.service.impl.CadParserServiceImpl.main(CadParserServiceImpl.java:716)

@komorebi,
请附上初始图像,我们会检查。 谢谢。

以下是如何处理 MTEXT 实体的示例:

String input = ...;
string output = ...;

Final CadImage cadImage = (CadImage)Image.load(in);

for (CadBaseEntity baseEntity: cadImage.getEntities())
{
          if (baseEntity.getTypeName() == CadEntityTypeName.MTEXT)
          {
               CadMText mtext = (CadMText)baseEntity;
               mtext.setText("new value");
          }
}

cadImage.save(out);

请注意,此示例显示了 MTEXT 实体的使用,但带有文本的其他实体可能会出现在绘图中。

我这边行不通,报错的.文件:House Floor Plan Sample.dwg.zip (203.8 KB)
jdk 版本是 22.2

异常信息为
Exception in thread “main” class com.aspose.cad.internal.Exceptions.NotImplementedException: The method or operation is not implemented
com.aspose.cad.internal.go.E.a(Unknown Source)
com.aspose.cad.internal.gA.a.a(Unknown Source)
com.aspose.cad.internal.gA.a.write(Unknown Source)
com.aspose.cad.internal.gA.b.write(Unknown Source)
com.aspose.cad.internal.hQ.a.c(Unknown Source)
com.aspose.cad.internal.hQ.a.write(Unknown Source)
com.aspose.cad.fileformats.cad.CadImage.c(Unknown Source)
com.aspose.cad.DataStreamSupporter.a(Unknown Source)
com.aspose.cad.DataStreamSupporter.save(Unknown Source)
com.bytedance.ea.cad.sdk.service.impl.CadParserServiceImpl.main(CadParserServiceImpl.java:717)
at com.aspose.cad.internal.go.E.a(Unknown Source)
at com.aspose.cad.internal.gA.a.a(Unknown Source)
at com.aspose.cad.internal.gA.a.write(Unknown Source)
at com.aspose.cad.internal.gA.b.write(Unknown Source)
at com.aspose.cad.internal.hQ.a.c(Unknown Source)
at com.aspose.cad.internal.hQ.a.write(Unknown Source)
at com.aspose.cad.fileformats.cad.CadImage.c(Unknown Source)
at com.aspose.cad.DataStreamSupporter.a(Unknown Source)
at com.aspose.cad.DataStreamSupporter.save(Unknown Source)
at com.bytedance.ea.cad.sdk.service.impl.CadParserServiceImpl.main(CadParserServiceImpl.java:717)

@komorebi
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): CADJAVA-11302

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@komorebi,
版本 22.2 肯定没有保存到 DWG,但我也可以看到最新 23.7 的问题。 我创建了上面提到的任务来解决这个问题。