70002093 Import NamedObjectsDictionaries from DWG DXF files

Article 70002093
Type Wish
Product Converter
Version 9002
Date Added 11/2/2021 12:00:00 AM
Fixed 9.9003.0.2 (11/4/2021 12:00:00 AM)
Submitted by Jens Scheffler

Summary

Import NamedObjectsDictionaries from DWG DXF files

Solution

Imports all NamedObjectsDictionary collection from DWG that contains valid Xrecords
Xrecord data are converted to new vdObjectArray collection
Supported Xrecord data types:
Integer , Double, String, vdHandle, ByteArray, gPoint


Dwg NamedObjectsDictionary are imported to vdDocument.UseTables["DWG"]["properties"]["NamedDictionary"] as a collection of vdXproperties

Export to Dwg is also supported
Note:
In case of DXF open/save use must set the vdxFiles.OpenSave.DisableVdrawDxf= true
Set vdDocumentc.FileProperties.ImportDWGFlags |= DWGImportFlags.ReadNamedObjectDictionaries; in order to support the import of dwg NamedObjectDictionaries.


example

//create some new custom data and add them to the Dwg UserTable

                //create some data
                vdObjectArray data1 = new vdObjectArray();
                data1.AddItem(1.0);
                data1.AddItem(1);
                data1.AddItem("Some Text 1");
                data1.AddItem(new gPoint(1, 1, 1));

                //create some data
                vdObjectArray data2 = new vdObjectArray();
                data2.AddItem(2.0);
                data2.AddItem(2);
                data2.AddItem("Some Text 2");
                data2.AddItem(new gPoint(2, 2, 2));

                //create a collection of vdXproperty to put out data
                vdXProperties data = new vdXProperties();
                data.Add("Mydata1", data1);//add a "Mydata1" dictionary reference data1
                data.Add("Mydata2", data2);//add a "Mydata2" dictionary reference data2
                //set the data collection of all of our property to the UserTables dictionary that is also exported to dwg file
                doc.UserTables["Dwg"]["properties"]["NamedDictionary"] = data;
                //save the drawing to dwg format
                doc.SaveAs(@"d:\trampa\trampa2\stavros\support\test.dwg");

                //open the previous saved drawing and read the imported data
                doc.FileProperties.ImportDWGFlags |= DWGImportFlags.ReadNamedObjectDictionaries;//needed in order to support the import of dwg NamedObjectDictionaries.
                doc.Open(@"d:\trampa\trampa2\stavros\support\test.dwg");
                vdXProperties dwgprops = doc.UserTables["Dwg"]["properties"]["NamedDictionary"] as vdXProperties;
                if(dwgprops != null)
                {
                    vdObjectArray _data1 = dwgprops["Mydata1"] as vdObjectArray;
                    if (_data1 != null)
                    {
                        MessageBox.Show(string.Format("Mydata1 = {0} items", _data1.Count));
                    }
                    vdObjectArray _data2 = dwgprops["Mydata2"] as vdObjectArray;
                    if (_data2 != null)
                    {
                        MessageBox.Show(string.Format("Mydata2 = {0} items", _data2.Count));
                    }
                }
Note: If the UserTables["Dwg"]["properties"]["NamedDictionary"] strings are not used exactly as they are in this sample code then these data will not be exported properly in .DWG/.DXF formats

Send comments on this topic.