Extended data (xdata) is the functional equivalent of MicroStation's element linkage. Extended data can be attached to any entity and consists of a data entries preceded by "group codes" that denote their type. The order of these group codes implies the application ownership - an application precedes it group data with its application ID and any data following that ID and up to the next application ID belongs to that application. Except for beginning with an application ID, the order and content of the extended data is determined by the application. The group code values are completely described in the AutoCAD documentation, but the more common values are defined in msdefs.h as follows:

#define DWGXDATA_String 1000
#define DWGXDATA_Application_Name 1001
#define DWGXDATA_ControlString 1002
#define DWGXDATA_LayerName 1003
#define DWGXDATA_BinaryData 1004
#define DWGXDATA_DatabaseHandle 1005
#define DWGXDATA_Point 1010
#define DWGXDATA_Space_Point 1011
#define DWGXDATA_Disp_Point 1012
#define DWGXDATA_Dir_Point 1013
#define DWGXDATA_Real 1040
#define DWGXDATA_Dist 1041
#define DWGXDATA_Scale 1042
#define DWGXDATA_Integer 1070
#define DWGXDATA_Long_Integer 1071

An application can add extended data to an element with the mdlLinkage_addXDataGroupCode function as demonstrated in the code fragment below (from the example application dwgappdata)

if (SUCCESS == mdlRegApp_idFromName (&regAppID, s_applicationName,
dgnFile, TRUE))
char *pTestString = "Test String";
DPoint3d testPoint = {1.0, 2.0, 3.0};
&regAppID, sizeof(regAppID));
pTestString, strlen (pTestString));
"{", 1);
&testPoint, sizeof(&testPoint));
"}", 1);

The extended data created by this code fragment would appear in a DWG file as follows:

Test String

Similarly, an application can look for extended data on an element with mdlLinkage_findApplicationXData. If the element contains extended data for the supplied application then the function returns success and the index of that application's extended data.

The extended data can then be read by repeatedly calling mdlLinkage_getXDataGroupCode to extract each the individual group codes and their associated data. See the dwgappdata application for an example of that illustrates the extraction of extended data.

Extended Records

Extended Records (xrecords) are the DWG equivalent of MicroStation's application (type 66, level 20) elements. They are similar to extended data in that they contain a series of data chunks with the data type denoted by a group code. They also provide similar functionality of XAttributes.

In order to locate extended records or other objects a DWG file contains a series of "Dictionary Objects". A dictionary contains a series of entries that contain a name and the ID of an element associated with that entry. An application will typically add an extended dictionary to a file that contains entries for each of its extended records. The application's extended dictionary is located by an application supplied, unique name in the file's main dictionary. The mdlDictionary_findDictionary function can be used to find an application dictionary. The mdlDictionary_extractEntry function can then be used to extract the dictionary entries.

Once a dictionary element is located, it's data can be extracted by using the mdlXRecord_extractGroupData and mdlXRecord_getGroupCode functions. See the dwgappdata application for an example that demonstrates this process.

Copyright © 2017 Bentley Systems, Incorporated. All rights reserved.