Learning How to Understand, Read XData for Reporting in C#

Learning How to Understand, Read XData for Reporting in C#

Anonymous
Not applicable
2,228 Views
5 Replies
Message 1 of 6

Learning How to Understand, Read XData for Reporting in C#

Anonymous
Not applicable

Okay, I am a newbie to AutoCAD's API, but do understand C# (Mid Level). We use a 3rd party software that runs on top of AutoCAD and uses Xdata, as its primary source of storing information to objects. Different sections of the application uses its own application name. What I am having trouble is understanding the Code "Numbers" (Code 1002, ASCII string: 1"). I understand the data types, but not the "Code 1002" and at that they are repeated several times with different data types and values. So if one pulls this information, who do you know which values you are extracting? Well intent is to try something like this:

 

  1. Create a grid view with some of these values. (maybe a tool palette?) What is the easiest for a beginner?
  2. Be able to summarize the values in different reporting formats in the grid view?
  3. I need for it to read the xrefs in the drawing as well. ( maybe add a toggle?)
  4. Be able to export the information out into excel or even use a excel template to write to and let it start to write at a certain row.

This would be a good start for me now. If anyone can point to where I can lean some of the bullet items, that would be very helpful. Sample code would also be appreciated\ and useful to get me started.

0 Likes
2,229 Views
5 Replies
Replies (5)
Message 2 of 6

_gile
Consultant
Consultant

Hi,

 

You can see the DXF Group Codes in Numerical Order Reference here. The codes related to DXF start with 1000.

You can also have a look at the DxfCode enum.

 

Anyway, except some specific ones (1001 = registered application name, 1002= "{" or "}" control strings) the values are arbitrary and only the creator of the data (a programmer) knows the meaning of the value.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 6

dgorsman
Consultant
Consultant

Well, the use of the value is arbitrary; the DXF code indicates the data type (int, double, string, etc.).  While most values have a range, its more common for XDATA designers to re-use the same value multiple times and only rely on the order.  That makes creating a standardized read/write method important.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


Message 4 of 6

artc2
Autodesk
Autodesk
For xdata you don't have a choice about using the same value mulitple times if you have multiple pieces of data that are the same type because there is only one group code for each data type/purpose for xdata.
0 Likes
Message 5 of 6

JamesMaeding
Advisor
Advisor

even if you have the dxf values, you have to know what they meant to the software that made them.

Many times I will convert a whole list of values to xdata, and you would have to know the order I cared about.

Like "the first number is decimal places, the second is the elevation, the third is the alignment index...."

 

So getting the dxf vals is the easy part. Also don't forget that programmers attach xrecord data as well as xdata.

Xdata is limited in length so I use xrecords for the bigger things.

good luck.


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

0 Likes
Message 6 of 6

ActivistInvestor
Mentor
Mentor

@Anonymous wrote:

Okay, I am a newbie to AutoCAD's API, but do understand C# (Mid Level). We use a 3rd party software that runs on top of AutoCAD and uses Xdata, as its primary source of storing information to objects. Different sections of the application uses its own application name. What I am having trouble is understanding the Code "Numbers" (Code 1002, ASCII string: 1"). I understand the data types, but not the "Code 1002" and at that they are repeated several times with different data types and values. So if one pulls this information, who do you know which values you are extracting? Well intent is to try something like this:

 

  1. Create a grid view with some of these values. (maybe a tool palette?) What is the easiest for a beginner?
  2. Be able to summarize the values in different reporting formats in the grid view?
  3. I need for it to read the xrefs in the drawing as well. ( maybe add a toggle?)
  4. Be able to export the information out into excel or even use a excel template to write to and let it start to write at a certain row.

This would be a good start for me now. If anyone can point to where I can lean some of the bullet items, that would be very helpful. Sample code would also be appreciated\ and useful to get me started.


IMO, a good start would be to make extensive use of System.ComponentModel (particularly the TypeDescriptor class), to expose XData through it, which not only makes it easy to consume from your own UI, but also allows it to be used and recognized by AutoCAD's DataExtraction functionality. IOW, do not deal directly with Xdata. Instead, write classes that wrap the xdata and expose it as class properties.

 

By adding custom type descriptors for AutoCAD types, you can add custom properties to those types that are recognized by components like the PropertyGrid, DataGridView (when binding to a class), and so forth (but unfortunately not by AutoCAD's properties palette without a lot of very complicated coding and reliance on 'unsupported' wrappers for managed code, that are limited in their ability and extremely difficult to work with, so for exposing your xdata to AutoCAD's properties palette, you'll most likely have to resort to C++ and the native API).

 

DataExtraction already has the ability to extract data to Excel, or to a formatted Table in a drawing, so a great deal of the functionality that you would probably want or need is already there, because DataExtraction will see and use your xdata if you expose it as custom properties on AutoCAD objects.

 

To expose custom properties on AutoCAD types, you have to do some work by creating CustomTypeDescriptors and TypeDescriptionProviders that will allow a call to TypeDescriptor.GetProperties() on an AutoCAD object to return your custom properties as well as those explicitly declared on the types.

 

As far as what the cryptic DXF codes mean, see the DXF documentation mentioned in other replies. To summarize, you can treat xdata as an arbitrary stream of data that only your application understands, where DXF codes are metadata that only describes the data type and nothing else. Hence, you would just develop a stream reader and writer that works with xdata rather than a file. It's also common to include a value that indicates the version of the application that wrote the xdata, so that if there are subsequent changes to its structure, future versions of your app will be able to read the xdata regardless of what version of the app wrote it.