How to Save UserData into DWG File?

How to Save UserData into DWG File?

353800230
Contributor Contributor
464 Views
4 Replies
Message 1 of 5

How to Save UserData into DWG File?

353800230
Contributor
Contributor

353800230_1-1693558589691.png

 

I  want to save some custom data to a dwg File by Document.UserData.

I Save my custom Data of Bundle. When the document is opening, It is Used. I can get userdata form document.

Howerver, When I closed thd document, the userdata is not be save in the Dwg file. When open the file , the count of userdata is 0.

 Anyone cane helper me ,how to save custom data in dwg file by Document.UserData?

Thanks

0 Likes
Accepted solutions (1)
465 Views
4 Replies
Replies (4)
Message 2 of 5

daniel_cadext
Advisor
Advisor

maybe a Xrecord?

 

https://help.autodesk.com/view/OARX/2023/ENU/?guid=GUID-0B9BDDE0-CDB7-4235-A2B7-8BD1FA82503F

Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx
0 Likes
Message 3 of 5

youssefGC
Advocate
Advocate

Hi,

You can use NOD (Named Object Dictionary) to save data in a DWG file. NOD can include various elements such as blocks, layers, styles, and more information.

 

 

0 Likes
Message 4 of 5

Keith.Brown
Advisor
Advisor

User data does not persist between sessions.  Norman did some tests and verified this.

https://forums.autodesk.com/t5/net/does-document-userdata-persist-over-acad-sessions/td-p/2569077

My preferred method is to serialize a class to json with my information in it.  Zip that class up and then save it in an xrecord.  Once the boiler plate code is complete, you can create new classes of information quite quickly and save it in a document or on an entity.


0 Likes
Message 5 of 5

ntclmain
Advocate
Advocate
Accepted solution

@353800230 

 To save custom data in a drawing, you should use Xrecord as Daniel_cadext suggested.

Here is the old topics about XRecord with Example that may help you:

 https://forums.autodesk.com/t5/net/store-data-in-dwg-file/td-p/3074780
https://forums.autodesk.com/t5/net/xrecord/m-p/7784421/highlight/true#M57654
https://forums.autodesk.com/t5/net/save-a-string-value-in-dwg-file/td-p/8595020

0 Likes