I use Aspose.CAD for Java to read a dwg file, but I can’t find any XData in any properties of 'CadImage ', can it be supported? Which properties should be used?
CadImage image = (CadImage) CadImage.load(“20241104.dwg”);
I use Aspose.CAD for Java to read a dwg file, but I can’t find any XData in any properties of 'CadImage ', can it be supported? Which properties should be used?
CadImage image = (CadImage) CadImage.load(“20241104.dwg”);
Aspose.CAD for Java does not provide direct support for reading XData from DWG files. Instead, it focuses on extracting External References (XREF) meta data. If you are looking to access specific properties related to XREF, you can utilize the CadUnderlay
class, which represents XREF entities in the DWG file.
Here’s a brief example of how to load a DWG file and iterate through its entities to find XREF meta data:
import com.aspose.cad.Image;
import com.aspose.cad.fileformats.cad.CadImage;
import com.aspose.cad.fileformats.cad.cadobjects.CadBaseEntity;
import com.aspose.cad.fileformats.cad.cadobjects.CadUnderlay;
public class ReadXrefMetaData {
public static void main(String[] args) {
// Load the DWG file
CadImage image = (CadImage) Image.load("20241104.dwg");
// Iterate through entities to find XREFs
for (CadBaseEntity entity : image.getEntities()) {
if (entity instanceof CadUnderlay) {
CadUnderlay underlay = (CadUnderlay) entity;
// Extract XREF meta data
String path = underlay.getUnderlayPath();
System.out.println("XREF Path: " + path);
}
}
}
}
In this code, we load the DWG file and check each entity to see if it is an instance of CadUnderlay
. If it is, we can access properties such as the underlay path. Unfortunately, if you are specifically looking for XData, it is not supported in the current version of Aspose.CAD for Java.
For more detailed information on working with XREF meta data, you may want to refer to the tutorials available on the Aspose website, which provide insights into handling CAD files effectively.
Sources:
[1]: Read XREF Meta Data from DWG Files Using Aspose.CAD for Java
[2]: CAD Meta Data and Rendering | Aspose.CAD Java API
@jim_zhu,
Hello.
Xdata are stored in the objects they relate to, e.g., here is the example how to get Xdata for the first entity:
CadXdata xdata = cadImage.getEntities().get(0).getXdataContainer().getAcadData();
Thanks a lot. But in my side, getXdataContainer() always returns null. But Xdata is not null in my dwg file when I check in AutoCAD.
@jim_zhu,
please provide the initial DWG file so we can ivestigate and the screenshot with the required data.
Thanks for reply. Sorry, my dwg file contains some confidential data, so I can’t sent it out. I got a simple dwg file from internet, and the XData can be read by Aspose.CAD. I am not sure what’s the differents between the two dwg files. I am not good at CAD, so I can’t got the reason…
Do you have any suggestions that I can try? I had submit a purchase to 3rd supplier in my country to got a license. but got this trouble in using it.
@jim_zhu,
we are not very helpful if we can not see the issue and reproduce it. Please note, that you can remove partial or almost the entire data in your drawing as long as the issue is reproducible, we are interested only in the problematic content. Please visualize how you see the Xdata for dwg file from internet, but if we have issues with reading of dwg (for instance) we need to debug the probem using the initial file anyway. Please try to filter the content of the file that is problematic and consider sending it to us.
Untitled.png (67.9 KB)
Maybe good news, I tried today and got some findings, I use [CadImage image = (CadImage) CadImage.load(“xxx.dwg”)] to
load a dwg file, and got the result by [image.getObjects()] as below picture,
the items types are CadDictionary, CadXRecord an so on, it seems that contails the information that I want,
the question is that how should I parse the values in CadDictionary and CadXRecord, and CadBinaryCodeValue in CadXRecord,
I didn’t any way in the API docments, would you please give me an example about it?
@jim_zhu,
Please note, that items in Objects collection can store custom data. The items in this collection are usually analyzed when item in Entities collection refers directly to some object in Objects. Different entities, different versions of DWG format may store data differenly.
We don’t have ready to go example to process items in Objects collection as this is quite specific and frequently drawing-dependent. Here are references to CadXRecord and CadBinaryCodeValue, unfortunately, CadDictionary is missing in our documentation.
Please consider providing us the sample file and the screenshot with the data you are searching in it, we will do our best to help you.