This porting VBA to ,net is a pain. I have attatched a number of xdata to an object in one function. I need to retrieve specific xdata in another. I cant seem to find where to put the index value to get to item 5 in the xdata. I can read all of the xdata just fine
Thanks Mike
Solved! Go to Solution.
Hi,
please upload either a drawing with one element in modelspace with your EED/XDATA or show your code so we see what you wrote/how you did it.
The element with index 5 of an array is normally readable by
myArrData(5)
But as there might be more than just one application that needs to assign EED to an object you have 2 options to get your data:
a) take all XDATA from the object (as array), then scan it for your appname and that is the index where you start now, add + 5 to get your value
b) use the function DBObj.GetXDataForApplication ==> that gives you only your EED as resultbuffer
HTH, - alfred -
Here is the code i have. I got it returning the first character in each
xdata record:
Public Sub ViewXData()
' Get the current database and start a transaction
Dim acCurDb As Autodesk.AutoCAD.DatabaseServices.Database
acCurDb = Application.DocumentManager.MdiActiveDocument.Database
Dim acDoc As Document =
Application.DocumentManager.MdiActiveDocument
Dim appName As String = "mikeC"
Dim msgstr As String = ""
Dim objColection As ObjectIdCollection = New ObjectIdCollection()
Using acTrans As Transaction =
acCurDb.TransactionManager.StartTransaction()
' Request objects to be selected in the drawing area
Dim acSSPrompt As PromptSelectionResult =
acDoc.Editor.GetSelection()
' If the prompt status is OK, objects were selected
If acSSPrompt.Status = PromptStatus.OK Then
Dim i As Integer
i = 0
Dim acSSet As SelectionSet = acSSPrompt.Value
'' add more objects
objColection = New ObjectIdCollection(acSSet.GetObjectIds())
' Step through the objects in the selection set
For Each acSSObj As SelectedObject In acSSet
' Open the selected object for read
Dim acEnt As Object =
acTrans.GetObject(acSSObj.ObjectId, _
OpenMode.ForRead)
' Get the extended data attached to each object for
mikeC
Dim rb As ResultBuffer =
acEnt.GetXDataForApplication(appName)
' Make sure the Xdata is not empty
If Not IsNothing(rb) Then
' Get the values in the xdata
For Each typeVal As TypedValue In rb
MsgBox(typeVal.Value(i)).ToString()
msgstr = msgstr & vbCrLf &
typeVal.TypeCode.ToString() & ":" & typeVal.Value
Next
Else
msgstr = "NONE"
End If
' Display the values returned
MsgBox(appName & " xdata on " &
VarType(acEnt).ToString() & ":" & vbCrLf & msgstr)
msgstr = ""
Next
i = i + 1
End If
' Ends the transaction and ensures any changes made are ignored
acTrans.Abort()
' Dispose of the transaction
End Using
End Sub
Hi,
>> I got it returning the first character in each xdata record
Look to that lines:
For Each typeVal As TypedValue In rb
MsgBox(typeVal.Value(i)).ToString()
There you start of a loop that already handles each item of the resultbuffer (For Each ...)
And within that loop you should take the value (typeVal.Value) and that's it
With your syntax typeVal.Value(i) you don't take the full string, you just take the element i in the array ... for a string that means you take the character at position i out of the array of characters.
HTH, - alfred -
Also, don't forget that the arrays are 0 based so element 5 is going to be located at position 4...
Tom
I don't know if this the correct way to do this but here is what worked.
My above Code
If rb IsNot Nothing Then
' Get the values in the xdata
Dim XdataOut As TypedValue() = rb.AsArray()
Dim xdata4 As Double = XdataOut.ElementAt(4).Value
Dim xdata5 As Double = XdataOut.ElementAt(5).Value
Thanks Mike