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

Get lisp variable

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
Anonymous
1709 Views, 5 Replies

Get lisp variable

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
5 REPLIES 5
Message 2 of 6
_gile
in reply to: Anonymous

Hi,

 

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

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 6
Anonymous
in reply to: _gile

 

 

 

Message 4 of 6
Anonymous
in reply to: _gile

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

 

 

Message 5 of 6
_gile
in reply to: Anonymous

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

Message 6 of 6
dgorsman
in reply to: Anonymous

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.


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

Post to forums  

Forma Design Contest


AutoCAD Beta