Get lisp variable

This widget could not be displayed.

Get lisp variable

Anonymous
Not applicable

I have the below code, works perfectly in AutoCAD 2015 32 bit

we are looking to upgrade to AutoCAD 2019 64 bit, but this code is causing AutoCAD to crash

 

after searching the internet I tried changing "?acedGetSym@@YAHPB_WPAPAUresbuf@@@Z" to x64: "acedGetSym" or "?acedGetSym@@YAHPEB_WPEAPEAUresbuf@@@Z" and even just "acedGetSym" but i still get the error

 

This is the error.

Capture.JPG

 

 

 

   <System.Security.SuppressUnmanagedCodeSecurity> <DllImport("accore.dll", CallingConvention:=CallingConvention.Cdecl, CharSet:=CharSet.Unicode, EntryPoint:="?acedGetSym@@YAHPB_WPAPAUresbuf@@@Z")>
        Private Shared Function acedGetSym(args As String, ByRef result As IntPtr) As Integer
        End Function
        Public Shared Function GetLispSym(name As String) As String
            Dim ip As IntPtr = IntPtr.Zero
            Dim status As Integer = acedGetSym(name, ip)
            If status = CInt(PromptStatus.OK) AndAlso ip <> IntPtr.Zero Then
                Dim resbuf As ResultBuffer = ResultBuffer.Create(ip, True)
                For Each tv As TypedValue In resbuf
                    Return tv.Value.ToString.ToUpper
                Next
            End If
            Return Nothing
        End Function
    End Class
0 Likes
Reply
Accepted solutions (1)
1,883 Views
5 Replies
Replies (5)

_gile
Mentor
Mentor
Accepted solution

Hi,

 

You should try to use the managed Document.GetLispSymbol() method instead.

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes

Anonymous
Not applicable

 

 

 

0 Likes

Anonymous
Not applicable

Thanks for the reply.

What would be the best way to error trap this in case the variable does not exist?

 

a simple try catch causes a major crash in the event the variable name does not exist.

 

    Public Shared Function GetLispSym(name As String) As String
            Dim acdoc As Autodesk.AutoCAD.ApplicationServices.Document = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument
            Dim value As String = String.Empty
            Try
                value = acdoc.GetLispSymbol(name).ToString.ToUpper
            Catch ex As Exception
                Return Nothing
            End Try
            Return value

 

  Dim x As String = GetLispSym("kjdjfsdjf")

image.png

 

 

0 Likes

_gile
Mentor
Mentor

I do not think the error you is due to the "variable does not exist". If the variable is nil, the method returns null (Nothing with VB).

 

I guess the error is due to the context the GetLispSym method is called.

AutoLISP runs in the document context, if your method is run in application context (e.g. CommandFlags.Session or a modeless UI) it should throw such exception.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes

dgorsman
Consultant
Consultant

Watch the scope of that "Catch ex as Exception" - there are two Exceptions, one thrown by AutoCAD and one by the system.  Without a scope you might be trying to catch the wrong one and missing.

 

Might want to also consider a higher-level try/catch to handle "leakers" so they don't crash the system, or throw an exception all the way back to the user.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


0 Likes