<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Does Document.UserData persist over Acad sessions? in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/does-document-userdata-persist-over-acad-sessions/m-p/2569077#M68856</link>
    <description>I am in a project development that may want to have a few pieces of data embeded in a drawing for later process. I looked at Document.UserData and though it meets my need well with its ease of use.&lt;BR /&gt;
&lt;BR /&gt;
I kew there was artical from Kean Walmsley on this topic. However, his sample code was written to run within the same Acad session. &lt;BR /&gt;
&lt;BR /&gt;
There is no document on whether the UserData persists over Acad sessions. So, I wrote a few line of testing code to see if the UserData survives Acad session. The result is bad: the UserData does not live through Acad session. &lt;BR /&gt;
&lt;BR /&gt;
Can anyone confirm that Document.UserData is only useful within the same Acad session?&lt;BR /&gt;
&lt;BR /&gt;
Here is my code:&lt;BR /&gt;
&lt;BR /&gt;
{code}&lt;BR /&gt;
&lt;BR /&gt;
''Simplified data class to be embeded in Document.UserData&lt;BR /&gt;
Public Class MyData&lt;BR /&gt;
&lt;BR /&gt;
    Public IntData As Integer = 3&lt;BR /&gt;
    Public StrData As String = "ABC"&lt;BR /&gt;
    Public BolData As Boolean = True&lt;BR /&gt;
    Public DatData As DateTime = DateTime.Today&lt;BR /&gt;
&lt;BR /&gt;
End Class&lt;BR /&gt;
&lt;BR /&gt;
Public Class MyCommand&lt;BR /&gt;
&lt;BR /&gt;
    Private Const DATA_KEY As String = "MY_DATA"&lt;BR /&gt;
&lt;BR /&gt;
    &lt;COMMANDMETHOD&gt; _&lt;BR /&gt;
    Public Shared Sub SetDocData()&lt;BR /&gt;
&lt;BR /&gt;
        Dim dwg As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument&lt;BR /&gt;
        Dim store As Hashtable = dwg.UserData&lt;BR /&gt;
        If store.ContainsKey(DATA_KEY) Then&lt;BR /&gt;
            store.Remove(DATA_KEY)&lt;BR /&gt;
        End If&lt;BR /&gt;
&lt;BR /&gt;
        store.Add(DATA_KEY, New MyData())&lt;BR /&gt;
        dwg.Editor.WriteMessage(vbCrLf &amp;amp; "Data has been saved with key """ &amp;amp; DATA_KEY &amp;amp; """.")&lt;BR /&gt;
&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
    &lt;COMMANDMETHOD&gt; _&lt;BR /&gt;
    Public Shared Sub GetData()&lt;BR /&gt;
&lt;BR /&gt;
        Dim dwg As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument&lt;BR /&gt;
        Dim ed As Editor = dwg.Editor&lt;BR /&gt;
&lt;BR /&gt;
        Dim store As Hashtable = dwg.UserData&lt;BR /&gt;
        If store.ContainsKey(DATA_KEY) Then&lt;BR /&gt;
            Dim data As MyData = TryCast(store(DATA_KEY), MyData)&lt;BR /&gt;
            If data IsNot Nothing Then&lt;BR /&gt;
                ed.WriteMessage(vbCrLf &amp;amp; "Data stored in this drawing has been found!")&lt;BR /&gt;
            Else&lt;BR /&gt;
                ed.WriteMessage(vbCrLf &amp;amp; "Data stored in this drawing is not type of MyData!")&lt;BR /&gt;
            End If&lt;BR /&gt;
        Else&lt;BR /&gt;
            ed.WriteMessage(vbCrLf &amp;amp; "No data was saved in this document!")&lt;BR /&gt;
        End If&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
End Class&lt;BR /&gt;
&lt;BR /&gt;
{code}&lt;BR /&gt;
&lt;BR /&gt;
That is, if I run the command "SetData" and then run "GetData" right after, the embeded UserData was found. &lt;BR /&gt;
&lt;BR /&gt;
However, if I run command "SetData", save and close the drawing, and then open it again, run command "GetData", the UserData was not there.&lt;BR /&gt;
&lt;BR /&gt;
Obviously, the Docuement.UserData does not stay over Acad sessions, I'd use other means, such as Dictionary/XData...

Edited by: norman.yuan on Oct 7, 2009 6:50 PM&lt;/COMMANDMETHOD&gt;&lt;/COMMANDMETHOD&gt;</description>
    <pubDate>Wed, 07 Oct 2009 18:49:50 GMT</pubDate>
    <dc:creator>norman.yuan</dc:creator>
    <dc:date>2009-10-07T18:49:50Z</dc:date>
    <item>
      <title>Does Document.UserData persist over Acad sessions?</title>
      <link>https://forums.autodesk.com/t5/net-forum/does-document-userdata-persist-over-acad-sessions/m-p/2569077#M68856</link>
      <description>I am in a project development that may want to have a few pieces of data embeded in a drawing for later process. I looked at Document.UserData and though it meets my need well with its ease of use.&lt;BR /&gt;
&lt;BR /&gt;
I kew there was artical from Kean Walmsley on this topic. However, his sample code was written to run within the same Acad session. &lt;BR /&gt;
&lt;BR /&gt;
There is no document on whether the UserData persists over Acad sessions. So, I wrote a few line of testing code to see if the UserData survives Acad session. The result is bad: the UserData does not live through Acad session. &lt;BR /&gt;
&lt;BR /&gt;
Can anyone confirm that Document.UserData is only useful within the same Acad session?&lt;BR /&gt;
&lt;BR /&gt;
Here is my code:&lt;BR /&gt;
&lt;BR /&gt;
{code}&lt;BR /&gt;
&lt;BR /&gt;
''Simplified data class to be embeded in Document.UserData&lt;BR /&gt;
Public Class MyData&lt;BR /&gt;
&lt;BR /&gt;
    Public IntData As Integer = 3&lt;BR /&gt;
    Public StrData As String = "ABC"&lt;BR /&gt;
    Public BolData As Boolean = True&lt;BR /&gt;
    Public DatData As DateTime = DateTime.Today&lt;BR /&gt;
&lt;BR /&gt;
End Class&lt;BR /&gt;
&lt;BR /&gt;
Public Class MyCommand&lt;BR /&gt;
&lt;BR /&gt;
    Private Const DATA_KEY As String = "MY_DATA"&lt;BR /&gt;
&lt;BR /&gt;
    &lt;COMMANDMETHOD&gt; _&lt;BR /&gt;
    Public Shared Sub SetDocData()&lt;BR /&gt;
&lt;BR /&gt;
        Dim dwg As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument&lt;BR /&gt;
        Dim store As Hashtable = dwg.UserData&lt;BR /&gt;
        If store.ContainsKey(DATA_KEY) Then&lt;BR /&gt;
            store.Remove(DATA_KEY)&lt;BR /&gt;
        End If&lt;BR /&gt;
&lt;BR /&gt;
        store.Add(DATA_KEY, New MyData())&lt;BR /&gt;
        dwg.Editor.WriteMessage(vbCrLf &amp;amp; "Data has been saved with key """ &amp;amp; DATA_KEY &amp;amp; """.")&lt;BR /&gt;
&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
    &lt;COMMANDMETHOD&gt; _&lt;BR /&gt;
    Public Shared Sub GetData()&lt;BR /&gt;
&lt;BR /&gt;
        Dim dwg As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument&lt;BR /&gt;
        Dim ed As Editor = dwg.Editor&lt;BR /&gt;
&lt;BR /&gt;
        Dim store As Hashtable = dwg.UserData&lt;BR /&gt;
        If store.ContainsKey(DATA_KEY) Then&lt;BR /&gt;
            Dim data As MyData = TryCast(store(DATA_KEY), MyData)&lt;BR /&gt;
            If data IsNot Nothing Then&lt;BR /&gt;
                ed.WriteMessage(vbCrLf &amp;amp; "Data stored in this drawing has been found!")&lt;BR /&gt;
            Else&lt;BR /&gt;
                ed.WriteMessage(vbCrLf &amp;amp; "Data stored in this drawing is not type of MyData!")&lt;BR /&gt;
            End If&lt;BR /&gt;
        Else&lt;BR /&gt;
            ed.WriteMessage(vbCrLf &amp;amp; "No data was saved in this document!")&lt;BR /&gt;
        End If&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
End Class&lt;BR /&gt;
&lt;BR /&gt;
{code}&lt;BR /&gt;
&lt;BR /&gt;
That is, if I run the command "SetData" and then run "GetData" right after, the embeded UserData was found. &lt;BR /&gt;
&lt;BR /&gt;
However, if I run command "SetData", save and close the drawing, and then open it again, run command "GetData", the UserData was not there.&lt;BR /&gt;
&lt;BR /&gt;
Obviously, the Docuement.UserData does not stay over Acad sessions, I'd use other means, such as Dictionary/XData...

Edited by: norman.yuan on Oct 7, 2009 6:50 PM&lt;/COMMANDMETHOD&gt;&lt;/COMMANDMETHOD&gt;</description>
      <pubDate>Wed, 07 Oct 2009 18:49:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/does-document-userdata-persist-over-acad-sessions/m-p/2569077#M68856</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2009-10-07T18:49:50Z</dc:date>
    </item>
    <item>
      <title>Re: Does Document.UserData persist over Acad sessions?</title>
      <link>https://forums.autodesk.com/t5/net-forum/does-document-userdata-persist-over-acad-sessions/m-p/2569078#M68857</link>
      <description>Document.UserData isn't persistent.&lt;BR /&gt;
&lt;BR /&gt;
You would need to persist it yourself in a dictionary or something.&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD&lt;BR /&gt;
Supporting AutoCAD 2000 through 2010&lt;BR /&gt;
&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");&lt;BR /&gt;
&lt;BR /&gt;
&lt;NORMAN.YUAN&gt; wrote in message news:6267790@discussion.autodesk.com...&lt;BR /&gt;
I am in a project development that may want to have a few pieces of data &lt;BR /&gt;
embeded in a drawing for later process. I looked at Document.UserData and &lt;BR /&gt;
though it meets my need well with its ease of use.&lt;BR /&gt;
&lt;BR /&gt;
I kew there was artical from Kean Walmsley on this topic. However, his &lt;BR /&gt;
sample code was written to run within the same Acad session.&lt;BR /&gt;
&lt;BR /&gt;
There is no document on whether the UserData persists over Acad sessions. &lt;BR /&gt;
So, I wrote a few line of testing code to see if the UserData survives Acad &lt;BR /&gt;
session. The result is bad: the UserData does not live through Acad session.&lt;BR /&gt;
&lt;BR /&gt;
Can anyone confirm that Document.UserData is only useful within the same &lt;BR /&gt;
Acad session?&lt;BR /&gt;
&lt;BR /&gt;
Here is my code:&lt;BR /&gt;
&lt;BR /&gt;
{code}&lt;BR /&gt;
&lt;BR /&gt;
''Simplified data class to be embeded in Document.UserData&lt;BR /&gt;
Public Class MyData&lt;BR /&gt;
&lt;BR /&gt;
    Public IntData As Integer = 3&lt;BR /&gt;
    Public StrData As String = "ABC"&lt;BR /&gt;
    Public BolData As Boolean = True&lt;BR /&gt;
    Public DatData As DateTime = DateTime.Today&lt;BR /&gt;
&lt;BR /&gt;
End Class&lt;BR /&gt;
&lt;BR /&gt;
Public Class MyCommand&lt;BR /&gt;
&lt;BR /&gt;
    Private Const DATA_KEY As String = "MY_DATA"&lt;BR /&gt;
&lt;BR /&gt;
    &lt;COMMANDMETHOD&gt; _&lt;BR /&gt;
    Public Shared Sub SetDocData()&lt;BR /&gt;
&lt;BR /&gt;
        Dim dwg As Document = &lt;BR /&gt;
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument&lt;BR /&gt;
        Dim store As Hashtable = dwg.UserData&lt;BR /&gt;
        If store.ContainsKey(DATA_KEY) Then&lt;BR /&gt;
            store.Remove(DATA_KEY)&lt;BR /&gt;
        End If&lt;BR /&gt;
&lt;BR /&gt;
        store.Add(DATA_KEY, New MyData())&lt;BR /&gt;
        dwg.Editor.WriteMessage(vbCrLf &amp;amp; "Data has been saved with key """ &amp;amp; &lt;BR /&gt;
DATA_KEY &amp;amp; """.")&lt;BR /&gt;
&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
    &lt;COMMANDMETHOD&gt; _&lt;BR /&gt;
    Public Shared Sub GetData()&lt;BR /&gt;
&lt;BR /&gt;
        Dim dwg As Document = &lt;BR /&gt;
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument&lt;BR /&gt;
        Dim ed As Editor = dwg.Editor&lt;BR /&gt;
&lt;BR /&gt;
        Dim store As Hashtable = dwg.UserData&lt;BR /&gt;
        If store.ContainsKey(DATA_KEY) Then&lt;BR /&gt;
            Dim data As MyData = TryCast(store(DATA_KEY), MyData)&lt;BR /&gt;
            If data IsNot Nothing Then&lt;BR /&gt;
                ed.WriteMessage(vbCrLf &amp;amp; "Data stored in this drawing has &lt;BR /&gt;
been found!")&lt;BR /&gt;
            Else&lt;BR /&gt;
                ed.WriteMessage(vbCrLf &amp;amp; "Data stored in this drawing is not &lt;BR /&gt;
type of MyData!")&lt;BR /&gt;
            End If&lt;BR /&gt;
        Else&lt;BR /&gt;
            ed.WriteMessage(vbCrLf &amp;amp; "No data was saved in this document!")&lt;BR /&gt;
        End If&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
End Class&lt;BR /&gt;
&lt;BR /&gt;
{code}&lt;BR /&gt;
&lt;BR /&gt;
That is, if I run the command "SetData" and then run "GetData" right after, &lt;BR /&gt;
the embeded UserData was found.&lt;BR /&gt;
&lt;BR /&gt;
However, if I run command "SetData", save and close the drawing, and then &lt;BR /&gt;
open it again, run command "GetData", the UserData was not there.&lt;BR /&gt;
&lt;BR /&gt;
Obviously, the Docuement.UserData does not stay over Acad sessions, I'd use &lt;BR /&gt;
other means, such as Dictionary/XData...&lt;BR /&gt;
&lt;BR /&gt;
Edited by: norman.yuan on Oct 7, 2009 6:50 PM&lt;/COMMANDMETHOD&gt;&lt;/COMMANDMETHOD&gt;&lt;/NORMAN.YUAN&gt;</description>
      <pubDate>Thu, 08 Oct 2009 05:13:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/does-document-userdata-persist-over-acad-sessions/m-p/2569078#M68857</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2009-10-08T05:13:19Z</dc:date>
    </item>
  </channel>
</rss>

