Reading XData

Reading XData

Anonymous
Not applicable
1,906 Views
5 Replies
Message 1 of 6

Reading XData

Anonymous
Not applicable

Is there an example, preferrably in VB.NET, of
actually reading XData (not writing)? I get a ResultBuffer and don't know how to
read certain value at specified index.

 

Regards,

Maksim Sestic
0 Likes
1,907 Views
5 Replies
Replies (5)
Message 2 of 6

Mikko
Advocate
Advocate
Dim idArray() As ObjectId
Try
Dim res As PromptSelectionResult = ed.GetSelection
If res.Status PromptStatus.OK Then
Exit Sub
End If
Dim SS As Autodesk.AutoCAD.EditorInput.SelectionSet = res.Value
idArray = SS.GetObjectIds()
Dim objId As ObjectId
For Each objId In idArray
Dim XDataEnt As Entity = CType(myT.GetObject(objId, OpenMode.ForRead), Entity)
If XDataEnt.GetType.Name.ToString() = "YourXDataEntity ex. CIRCLE LINE etc...." Then
Try
Dim myXdata As Array
myXdata = XDataEnt.XData.AsArray
var0 = myXdata.GetValue(0)
var1 = myXdata.GetValue(1)
Catch ex As Exception
ed.WriteMessage("Selected entity does not have any xdata attached to it." & vbCrLf & "Try Again!")
Exit Sub
End Try
End If
Next
myT.Commit()
Catch ex As Exception
ed.WriteMessage(ex.ToString)
Finally
myT.Dispose()
End Try
ed.WriteMessage(var0 & ", " & var1) null
0 Likes
Message 3 of 6

Anonymous
Not applicable

Mikko,

 

Thanks for the tip, but I'm still having problem
with this part of code you've sent:

 

...

Dim myXdata As
Array
myXdata = XDataEnt.XData.AsArray
...

 

The error reported: 
color=#808080>'AsArray' is not a member of
'Autodesk.AutoCAD.DatabaseServices.ResultBuffer'
,

and also: Value of type
'Autodesk.AutoCAD.DatabaseServices.ResultBuffer' cannot be converted to
'System.Array'
.

There is no
XData.AsArray method exposed (?!)... I'm using AutoCAD 2005.

 

Regards,

Maksim Sestic
0 Likes
Message 4 of 6

Mikko
Advocate
Advocate
According to the 2006 Object Browser

Public Function AsArray() As Autodesk.AutoCAD.DatabaseServices.TypedValue()
Member of: Autodesk.AutoCAD.DatabaseServices.ResultBuffer

Must be new to 2006. Never used 2005 very much, the API was very incomplete. You can always use the COM Interop, still works just fine. Not the answer you wanted to hear. Maybe someone else has the remedy.
0 Likes
Message 5 of 6

Anonymous
Not applicable

Mikko,

 

Thanks anyway, I'm planning to switch to 2006
soon so I guess this is newly exposed functionality. Regarding ResultBuffer type
in 2005 - it's a simple List user needs to iterate (ForEach...Next) to get to
desired index and then get a Value property.

 

Regards,

Maksim Sestic

 

According to the 2006 Object
Browser

Public Function AsArray() As
Autodesk.AutoCAD.DatabaseServices.TypedValue()
    
Member of: Autodesk.AutoCAD.DatabaseServices.ResultBuffer

Must be new to
2006.  Never used 2005 very much, the API was very incomplete.  You
can always use the COM Interop, still works just fine.  Not the answer you
wanted to hear.  Maybe someone else has the remedy.
0 Likes
Message 6 of 6

Anonymous
Not applicable
DESI BRE KUME
MORAO SAM PO NETU DA TE TRAZIM
AJDE PISHI DESI I SHTA IMA NOVO
U BANGKOKU SAM VEC DUZE.....I TAKO SVE OK
PISHI
POZDRAV
0 Likes