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.
<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
Solved! Go to Solution.
Solved by _gile. Go to Solution.
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")
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.
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.
Can't find what you're looking for? Ask the community or share your knowledge.