.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Read Lisp's property by VB.NET

8 REPLIES 8
Reply
Message 1 of 9
NovayaEra
970 Views, 8 Replies

Read Lisp's property by VB.NET

Hi

 

I have old Lisp macros, that writes property to drawing by command (vlax-ldata-put "SpData" cVar cVal). How can I read this property's value, using VB.NET ?

 

I attached file with this property, its value="TEST"

Tags (1)
8 REPLIES 8
Message 2 of 9
Hallex
in reply to: NovayaEra

See if this is working for you:

 

    Public Function GetDictionary(ByVal dictname As String) As DBDictionary
        Dim dict As New DBDictionary
        Dim db As Database = HostApplicationServices.WorkingDatabase
        Using tr As Transaction = db.TransactionManager.StartOpenCloseTransaction
            Dim nod As DBDictionary = TryCast(tr.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForRead), DBDictionary)
            If nod Is Nothing Then
                Return Nothing
            End If
            Dim id As ObjectId = ObjectId.Null
            Try
                id = nod.GetAt(dictname)
                dict = TryCast(tr.GetObject(id, OpenMode.ForRead), DBDictionary)
                If dict Is Nothing Then
                    Return Nothing
                Else
                    Return dict
                End If
            Catch ex As Exception
                Return Nothing
            End Try
        End Using

    End Function
    <CommandMethod("ldt")> _
    Public Sub GetLdata()
        Dim doc As Document = Application.DocumentManager.MdiActiveDocument
        Dim ed As Editor = doc.Editor
        Dim db As Database = doc.Database
        Dim spdict As DBDictionary = Getdictionary("SpData")
        If spdict IsNot Nothing Then
            MsgBox("""SpData"" dictionary exist")
        Else
            MsgBox("""SpData"" dictionary does not exist")
            Return
        End If
      
        For Each de As DictionaryEntry In spdict
            ed.WriteMessage("\n{0}\t{1}", de.Key, de.Value)
        Next

    End Sub
    'I've got the returned values like this:
    '    \nFileName\t(2129675160)\nFUSAGE\t(2129675096)\nNAIM\t(2129675088)\nNCONTR\t(212
    '9675128)\nOBOZN\t(2129675080)\nPOSDELTA1\t(2129675144)\nPOSDELTA2\t(2129675152)\
    'nPROV\t(2129675112)\nQUANTNUM\t(2129675168)\nRAZRAB\t(2129675104)\nTCONTR\t(2129
    '675120)\nUTV\t(2129675136)

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 3 of 9
NovayaEra
in reply to: NovayaEra

Thank You!

 

I so understood that de.Value is an Autodesk.Autocad.DatabaseServices.ImpDBObject's ID? How to get this object's text? I tried do this, but got error "Autodesk.AutoCAD.DatabaseServices.ImpDBObject is unavailable in this context because it's 'Friend' ". 

 

For Each de As DictionaryEntry In spdict

    Using tr As Transaction = db.TransactionManager.StartTransaction
      
      Dim imp As Autodesk.AutoCAD.DatabaseServices.ImpDBObject = tr.GetObject(de.Value, OpenMode.ForWrite, False, True)
       
      MsgBox(imp.Text)

     End Using

Next

 

Message 4 of 9
Hallex
in reply to: NovayaEra

Try to use OpenMode.ForRead instead:

 

Using tr As Transaction = db.TransactionManager.StartTransaction

 

For Each de As DictionaryEntry In spdict     

          Dim imp As Autodesk.AutoCAD.DatabaseServices.ImpDBObject = tr.GetObject(de.Value, OpenMode.ForRead, False, True)     

        MsgBox(imp.Text)  

Next

 

  End Using

 

If you do open for write, you have first open for write "SpData" dictionary,

then digg deeper inside

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 5 of 9
NovayaEra
in reply to: NovayaEra

if I made so, I received an error:

Dim imp As Autodesk.AutoCAD.DatabaseServices.ImpDBObject 
'Here I got error: "Autodesk.AutoCAD.DatabaseServices.ImpDBObject is 'unavailable in this context because it's 'Friend' "

 

 Trying to made so:

Dim obj As DBObject = tr.GetObject(de.Value, OpenMode.ForRead, False, True)

MsgBox(obj.Handle.Value.ToString)

 

 but received numbers like 440 ... 435 ... etc

 

This construction:

Dim obj As DBObject = tr.GetObject(de.Value, OpenMode.ForRead, False, True)

MsgBox(obj.Handle.ToString)

 Returns 1BB ... 1B3 ... etc, but not text string "Test", like in file

 

 

Make this:

Using tr As Transaction = db.TransactionManager.StartTransaction

  For Each de As DictionaryEntry In spdict


      Dim obj As DBObject = tr.GetObject(de.Value, OpenMode.ForRead, False, True)

      Dim txt As DBText = obj


      MsgBox(txt.TextString)

  Next

End Using

 But received error "it was not possible to give object type  Autodesk.AutoCAD.DatabaseServices.ImpDBObject to  Autodesk.AutoCAD.DatabaseServices.DBText" (sorry, I translate errors from non-english version of Visual Studio)

 

I in perplexity Smiley Indifferent

Message 6 of 9

Well, using vlax-ldata-* functions is a grave mistake to start with, going by the fact that in one AutoCAD release, Autodesk provided no way to access data that was put there by a previous release.

 

I would suggest you get your data out of that 'trap' and use XRecords instead, because they don't have that problem, and you can get at them from any API.

 

In the mean time, the only way to get this data from managed code is by P/Invoking acdbEntGet().

 

"ImpDBObject" is the managed wrapper type that AutoCAD places around database objects that have no other specific managed wrapper type (IOW, object types that are not supported by the managed API). And because there's no specific managed wrapper provided for the custom object that stores the data accessed via vlax-ldata-* functions, it gets this wrapper by default.

 

You can search this forum for more information on using acdbEntGet() from managed code.

Message 7 of 9
NovayaEra
in reply to: NovayaEra

DinigPhilosopfer, thanks, I will try 

Message 8 of 9

I'm confused by vlax-ldata-*, too.
Thank you, maybe I can have the problem solved.
聚傲气于一身,显傲骨之精华
Message 9 of 9
Balaji_Ram
in reply to: viper_007

Here is another approach to retrieve the data &colon;

 

http://adndevblog.typepad.com/autocad/2013/01/accessing-ldata-values-from-vba.html

 

Regards,

Balaji



Balaji
Developer Technical Services
Autodesk Developer Network

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost