<?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 Re: XData in VBA Forum</title>
    <link>https://forums.autodesk.com/t5/vba-forum/xdata/m-p/2628196#M14074</link>
    <description>I try Objectadded event to add xdata but it gave me error "Object open for read"</description>
    <pubDate>Sat, 06 Feb 2010 21:05:58 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2010-02-06T21:05:58Z</dc:date>
    <item>
      <title>XData</title>
      <link>https://forums.autodesk.com/t5/vba-forum/xdata/m-p/2628194#M14072</link>
      <description>Hi&lt;BR /&gt;
&lt;BR /&gt;
See the photo in the attach file &lt;BR /&gt;
what I need is&lt;BR /&gt;
how I can assign selected item as Xdata for any opject user will draw after click the xdata CommandButton&lt;BR /&gt;
the normal draw way using the autocad command &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
thanks</description>
      <pubDate>Fri, 05 Feb 2010 06:17:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/xdata/m-p/2628194#M14072</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-02-05T06:17:22Z</dc:date>
    </item>
    <item>
      <title>Re: XData</title>
      <link>https://forums.autodesk.com/t5/vba-forum/xdata/m-p/2628195#M14073</link>
      <description>Any Help  please   ???</description>
      <pubDate>Sat, 06 Feb 2010 06:29:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/xdata/m-p/2628195#M14073</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-02-06T06:29:14Z</dc:date>
    </item>
    <item>
      <title>Re: XData</title>
      <link>https://forums.autodesk.com/t5/vba-forum/xdata/m-p/2628196#M14074</link>
      <description>I try Objectadded event to add xdata but it gave me error "Object open for read"</description>
      <pubDate>Sat, 06 Feb 2010 21:05:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/xdata/m-p/2628196#M14074</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-02-06T21:05:58Z</dc:date>
    </item>
    <item>
      <title>Re: XData</title>
      <link>https://forums.autodesk.com/t5/vba-forum/xdata/m-p/2628197#M14075</link>
      <description>This should help you out dealing with XData&lt;BR /&gt;
&lt;BR /&gt;
{code}&lt;BR /&gt;
&lt;BR /&gt;
 'Purpose&lt;BR /&gt;
'Erases extended entity data, xdata, attached to an object. If an&lt;BR /&gt;
'application name is not specified, then all xdata is erased.&lt;BR /&gt;
&lt;BR /&gt;
'Arguments&lt;BR /&gt;
'An AcadObject and optionally a registered application name.&lt;BR /&gt;
&lt;BR /&gt;
'Example&lt;BR /&gt;
'Call ClearXData(myAcadObject, "ACADX")&lt;BR /&gt;
&lt;BR /&gt;
'Notes&lt;BR /&gt;
'ClearXData() will not erase xdata saved by AutoCAD.&lt;BR /&gt;
&lt;BR /&gt;
Sub SetXdata()&lt;BR /&gt;
Dim sset As AcadSelectionSet&lt;BR /&gt;
    Call SsetMake("sset")&lt;BR /&gt;
    Set sset = ThisDrawing.SelectionSets.item("sset")&lt;BR /&gt;
    sset.SelectOnScreen&lt;BR /&gt;
    &lt;BR /&gt;
Dim Color As String&lt;BR /&gt;
Dim xdataType(0 To 1) As Integer, xdata(0 To 1) As Variant&lt;BR /&gt;
For Each item In sset&lt;BR /&gt;
&lt;BR /&gt;
If TypeOf item Is AcadHatch Then&lt;BR /&gt;
    xdataType(0) = 1001: xdata(0) = "My Hatch Data"&lt;BR /&gt;
    xdataType(1) = 1000: xdata(1) = item.Color&lt;BR /&gt;
    item.SetXdata xdataType, xdata&lt;BR /&gt;
End If&lt;BR /&gt;
Next&lt;BR /&gt;
&lt;BR /&gt;
End Sub&lt;BR /&gt;
 &lt;BR /&gt;
 &lt;BR /&gt;
Sub GetXdata()&lt;BR /&gt;
Dim sset As AcadSelectionSet&lt;BR /&gt;
    Call SsetMake("sset")&lt;BR /&gt;
    Set sset = ThisDrawing.SelectionSets.item("sset")&lt;BR /&gt;
    sset.SelectOnScreen&lt;BR /&gt;
 &lt;BR /&gt;
    Dim Color As String&lt;BR /&gt;
    Dim xdataOut As Variant&lt;BR /&gt;
    Dim xtypeOut As Variant&lt;BR /&gt;
    &lt;BR /&gt;
    For Each item In sset&lt;BR /&gt;
        item.GetXdata "", xtypeOut, xdataOut&lt;BR /&gt;
    Next&lt;BR /&gt;
&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Sub StoreXdata(item As Variant, Text As String, value As Variant)&lt;BR /&gt;
Dim xdataType(0 To 1) As Integer, xdata(0 To 1) As Variant&lt;BR /&gt;
Exit Sub&lt;BR /&gt;
 &lt;BR /&gt;
    xdataType(0) = 1001: xdata(0) = Text&lt;BR /&gt;
    xdataType(1) = 1000: xdata(1) = value&lt;BR /&gt;
    If ThisDrawing.layers(item.layer).Lock = False Then&lt;BR /&gt;
        item.SetXdata xdataType, xdata&lt;BR /&gt;
    Else&lt;BR /&gt;
        UnLockLayer item.layer&lt;BR /&gt;
        item.SetXdata xdataType, xdata&lt;BR /&gt;
        LockLayer item.layer&lt;BR /&gt;
    End If&lt;BR /&gt;
 &lt;BR /&gt;
End Sub&lt;BR /&gt;
 &lt;BR /&gt;
 &lt;BR /&gt;
Function RetrieveXdata(item, Text As String) As Variant&lt;BR /&gt;
 Debug.Print&lt;BR /&gt;
 If TypeOf item Is AcadPViewport Or TypeOf item Is AcadViewport Or TypeOf item Is AcadModelSpace Or TypeOf item Is AcadPaperSpace Then Exit Function&lt;BR /&gt;
    Dim xdataOut As Variant&lt;BR /&gt;
    Dim xtypeOut As Variant&lt;BR /&gt;
    item.GetXdata "", xtypeOut, xdataOut&lt;BR /&gt;
    If isValid(xdataOut) Then&lt;BR /&gt;
        For I = LBound(xdataOut) To UBound(xdataOut)&lt;BR /&gt;
            If Not isValid(xdataOut(I)) Then&lt;BR /&gt;
            If UCase(xdataOut(I)) = UCase(Text) Then&lt;BR /&gt;
                If Not I + 1 &amp;gt; UBound(xdataOut) Then&lt;BR /&gt;
                    RetrieveXdata = xdataOut(I + 1)&lt;BR /&gt;
                    Exit For&lt;BR /&gt;
                End If&lt;BR /&gt;
            End If&lt;BR /&gt;
            End If&lt;BR /&gt;
        Next&lt;BR /&gt;
    End If&lt;BR /&gt;
&lt;BR /&gt;
End Function&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Public Sub ClearXData(obj As AcadObject, Optional RegApp As String = "")&lt;BR /&gt;
Const regAppKey As Integer = 1001&lt;BR /&gt;
Const acadApp As String = "ACAD"&lt;BR /&gt;
&lt;BR /&gt;
Dim XDType As Variant&lt;BR /&gt;
Dim XDData As Variant&lt;BR /&gt;
Dim NewType(0) As Integer&lt;BR /&gt;
Dim NewData(0) As Variant&lt;BR /&gt;
Dim I As Integer&lt;BR /&gt;
&lt;BR /&gt;
obj.GetXdata AppName:=RegApp, xdataType:=XDType, XDataValue:=XDData&lt;BR /&gt;
&lt;BR /&gt;
If Not IsEmpty(XDType) Then&lt;BR /&gt;
    For I = LBound(XDType) To UBound(XDType)&lt;BR /&gt;
        If XDType(I) = regAppKey Then&lt;BR /&gt;
            If Not XDData(I) Like acadApp Then&lt;BR /&gt;
                NewType(0) = regAppKey&lt;BR /&gt;
                NewData(0) = XDData(I)&lt;BR /&gt;
                obj.SetXdata xdataType:=NewType, XDataValue:=NewData&lt;BR /&gt;
            End If&lt;BR /&gt;
        End If&lt;BR /&gt;
    Next I&lt;BR /&gt;
End If&lt;BR /&gt;
&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
Function inc(myArray As Variant) As Variant&lt;BR /&gt;
 Dim temparray() As Variant&lt;BR /&gt;
    If isValid(myArray) Then&lt;BR /&gt;
        ReDim Preserve myArray(UBound(myArray) + 1)&lt;BR /&gt;
    Else&lt;BR /&gt;
        ReDim myArray(0)&lt;BR /&gt;
    End If&lt;BR /&gt;
inc = myArray&lt;BR /&gt;
End Function&lt;BR /&gt;
&lt;BR /&gt;
Function isValid(myArray As Variant) As Boolean&lt;BR /&gt;
 On Error GoTo theend&lt;BR /&gt;
 Dim I As Variant&lt;BR /&gt;
    For Each I In myArray&lt;BR /&gt;
        isValid = True&lt;BR /&gt;
        Exit Function&lt;BR /&gt;
    Next&lt;BR /&gt;
theend:&lt;BR /&gt;
    isValid = False&lt;BR /&gt;
End Function&lt;BR /&gt;
&lt;BR /&gt;
Function LockLayer(layer)&lt;BR /&gt;
If layer = "" Then Exit Function&lt;BR /&gt;
    ThisDrawing.layers(layer).Lock = True&lt;BR /&gt;
End Function&lt;BR /&gt;
&lt;BR /&gt;
Function UnLockLayer(layer)&lt;BR /&gt;
If layer = "" Then Exit Function&lt;BR /&gt;
    ThisDrawing.layers(layer).Lock = False&lt;BR /&gt;
End Function&lt;BR /&gt;
&lt;BR /&gt;
Public Sub SsetMake(ssetname As String)&lt;BR /&gt;
 Dim sset As AcadSelectionSet&lt;BR /&gt;
 Dim ssetcheck As Boolean&lt;BR /&gt;
    For Each sset In ThisDrawing.SelectionSets&lt;BR /&gt;
        If sset.Name = ssetname Then&lt;BR /&gt;
            ssetcheck = True&lt;BR /&gt;
            Exit For&lt;BR /&gt;
        End If&lt;BR /&gt;
    Next&lt;BR /&gt;
    If ssetcheck Then&lt;BR /&gt;
        ThisDrawing.SelectionSets.item(ssetname).Delete&lt;BR /&gt;
        Set sset = ThisDrawing.SelectionSets.Add(ssetname)&lt;BR /&gt;
    Else&lt;BR /&gt;
        Set sset = ThisDrawing.SelectionSets.Add(ssetname)&lt;BR /&gt;
    End If&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
{code}</description>
      <pubDate>Sun, 07 Feb 2010 06:25:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/xdata/m-p/2628197#M14075</guid>
      <dc:creator>arcticad</dc:creator>
      <dc:date>2010-02-07T06:25:12Z</dc:date>
    </item>
    <item>
      <title>Re: XData</title>
      <link>https://forums.autodesk.com/t5/vba-forum/xdata/m-p/2628198#M14076</link>
      <description>Thanks for your reply&lt;BR /&gt;
&lt;BR /&gt;
I have no problem in XData the problem in -- set XData for new object when create it --&lt;BR /&gt;
&lt;BR /&gt;
the event &lt;BR /&gt;
&lt;BR /&gt;
"  AcadDocument_ObjectAdded(ByVal Object As Object) "&lt;BR /&gt;
&lt;BR /&gt;
gave you the object after you add it but when I try to set Xdata I get error "object for read"&lt;BR /&gt;
&lt;BR /&gt;
the Application should set xdata for objects during drawing not after finishing the draw &lt;BR /&gt;
&lt;BR /&gt;
in other way I don't want select the object after I finish the draw to set Xdata it should be already there because I set it while I draw&lt;BR /&gt;
&lt;BR /&gt;
I hop this clearing my point</description>
      <pubDate>Sun, 07 Feb 2010 07:15:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/xdata/m-p/2628198#M14076</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-02-07T07:15:39Z</dc:date>
    </item>
    <item>
      <title>Re: XData</title>
      <link>https://forums.autodesk.com/t5/vba-forum/xdata/m-p/2628199#M14077</link>
      <description>The simple answer is you can't.&lt;BR /&gt;
The Object will be in use while the ObjectAdded event is running. &lt;BR /&gt;
You can't fix this. You will have to side step it. &lt;BR /&gt;
You will need to store the information of the added object. (objectID)&lt;BR /&gt;
I normally just store it in a dictionary entry and then check if the entry exists and do the next step. &lt;BR /&gt;
&lt;BR /&gt;
{code}&lt;BR /&gt;
Private Sub AcadDocument_EndCommand(ByVal CommandName As String)&lt;BR /&gt;
' if my dictionary is this value then&lt;BR /&gt;
' Get this objectID&lt;BR /&gt;
' and do something with it.&lt;BR /&gt;
' Delete Dictionary&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
 Private Sub AcadDocument_ObjectAdded(ByVal Object As Object)&lt;BR /&gt;
' Store ObjectID in dictionary&lt;BR /&gt;
End Sub&lt;BR /&gt;
{code}</description>
      <pubDate>Sun, 07 Feb 2010 07:27:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/xdata/m-p/2628199#M14077</guid>
      <dc:creator>arcticad</dc:creator>
      <dc:date>2010-02-07T07:27:59Z</dc:date>
    </item>
  </channel>
</rss>

