.NET

Reply
Contributor
NovayaEra
Posts: 13
Registered: ‎08-10-2011
Message 1 of 7 (483 Views)

Read Lisp's property by VB.NET

483 Views, 6 Replies
09-04-2012 03:01 AM

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"

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 2 of 7 (475 Views)

Re: Read Lisp's property by VB.NET

09-04-2012 05:20 AM 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
Contributor
NovayaEra
Posts: 13
Registered: ‎08-10-2011
Message 3 of 7 (449 Views)

Re: Read Lisp's property by VB.NET

09-05-2012 02:51 AM 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

 

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 4 of 7 (434 Views)

Re: Read Lisp's property by VB.NET

09-05-2012 09:36 AM 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
Contributor
NovayaEra
Posts: 13
Registered: ‎08-10-2011
Message 5 of 7 (393 Views)

Re: Read Lisp's property by VB.NET

09-11-2012 05:01 AM 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 :smileyindifferent:

Valued Mentor
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 6 of 7 (386 Views)

Re: Read Lisp's property by VB.NET

09-11-2012 08:09 AM in reply to: NovayaEra

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.

Contributor
NovayaEra
Posts: 13
Registered: ‎08-10-2011
Message 7 of 7 (354 Views)

Re: Read Lisp's property by VB.NET

09-12-2012 11:52 PM in reply to: NovayaEra

DinigPhilosopfer, thanks, I will try 

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.