Author Topic: AcedGetSym in 32-bit AutoCAD 2015  (Read 3215 times)

0 Members and 1 Guest are viewing this topic.

AIYOUNG

  • Guest
AcedGetSym in 32-bit AutoCAD 2015
« on: June 12, 2014, 04:11:33 PM »
I was wondering if anyone has ran into any issues when using code that calls AcedGetSym when the code is ran in 32-bit AutoCAD 2015?

I currently get an error stating that AutoCAD can't find AcedGetSym in acCore.dll.

The same code runs fine in AutoCAD 2013 & 2014 in 32 bit and it runs fine in AutoCAD 2013-2015 64 bit.


fylancer

  • Guest
Re: AcedGetSym in 32-bit AutoCAD 2015
« Reply #1 on: June 13, 2014, 12:57:37 PM »
In 2015 you can use

Document.GetLispSymbol
and

Document.SetLispSymbol


public object GetLispSymbol(
    string name
);

and

public void SetLispSymbol(
    string name,
    object value
);

AIYOUNG

  • Guest
Re: AcedGetSym in 32-bit AutoCAD 2015
« Reply #2 on: June 13, 2014, 01:09:01 PM »
Thanks for the reply!

The code i am working on has to support 2012 up to 2015 in 32 and 64 bit, so if those commands are only in AutoCAD 2015, that's not a good option for me.

I just think that it's odd that AcedGetSym would work in 2015 64 bit but not in 2015 32 bit.


Alexander Rivilis

  • Bull Frog
  • Posts: 214
  • Programmer from Kyiv (Ukraine)
Re: AcedGetSym in 32-bit AutoCAD 2015
« Reply #3 on: June 16, 2014, 09:32:51 AM »
Name of function acedGetSym are different in AutoCAD 2015 x84 and x86:
x86: "_acedGetSym" or "?acedGetSym@@YAHPB_WPAPAUresbuf@@@Z"
x64: "acedGetSym" or "?acedGetSym@@YAHPEB_WPEAPEAUresbuf@@@Z" 

AIYOUNG

  • Guest
Re: AcedGetSym in 32-bit AutoCAD 2015
« Reply #4 on: June 16, 2014, 10:08:14 AM »
I'm using P/Invoke to grab AcedGetSym from acCore.dll.

Code: [Select]
    'Use P/Invoke for AcedGetSym
    <DllImport("acCore.dll", CharSet:=CharSet.Unicode, _
           CallingConvention:=CallingConvention.Cdecl, EntryPoint:="acedGetSym")> _
    Shared Function acedGetSym(ByVal args As String, <Out()> ByRef result As IntPtr) As Integer
    End Function

AIYOUNG

  • Guest
Re: AcedGetSym in 32-bit AutoCAD 2015
« Reply #5 on: June 16, 2014, 10:12:39 AM »
Here's an example code i wrote where a user can query if an AutoLISP symbol is valid.

I've tested the code in 64 bit versions of AutoCAD 2013 through 2015, and it works fine on those systems.

I've also tested the code on 32 bit versions of AutoCAD 2013 through 2015. It only fails to run on 32 bit 2015.

AGS_Class.vb

Code: [Select]
'import the AutoCAD/ObjectDBX type libeary

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.EditorInput

Imports System.Text ' for StringBuilder
Imports Autodesk.AutoCAD.DatabaseServices ' For ResultsBuffer

Imports System.Runtime.InteropServices 'for DllImport()
'imports the AutoCAD Type library
Imports Autodesk.AutoCAD.Interop

Imports Autodesk.AutoCAD.ApplicationServices
Imports System.Windows.Forms

Public Class AGS_Class

    'Define ThisDrawing. The production code i am working on was converted from VBA to VB.NET, hence this has to be defined.
    Public ReadOnly Property ThisDrawing() As AcadDocument
        Get
            Return DocumentExtension.GetAcadDocument(Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument)
        End Get
    End Property

    'Define the entry point/command.
    <Autodesk.AutoCAD.Runtime.CommandMethod("AIY_AcedGetSym_Test")> _
    Public Sub EntryPoint()
        Dim My_Form1 As New Form1
        My_Form1.ShowDialog()
    End Sub

    'Use P/Invoke for AcedGetSym
    <DllImport("acCore.dll", CharSet:=CharSet.Unicode, _
           CallingConvention:=CallingConvention.Cdecl, EntryPoint:="acedGetSym")> _
    Shared Function acedGetSym(ByVal args As String, <Out()> ByRef result As IntPtr) As Integer
    End Function

    Public Shared Function AcadGetSym(ByVal varname As String) As ResultBuffer
        ' IntPtr is an integer (used as a pointer for .NET) initialize to zero
        Dim rb As IntPtr = IntPtr.Zero
        ' use the function that was p/Invoked, pass in the name that was
        ' provided by the user and the IntPtr
        Dim stat As Integer = 0
        stat = acedGetSym(varname, rb)
        ' If stat is ok and the IntPtr is not zero create a ResultBuffer and Return it
        If stat = CType(PromptStatus.OK, Integer) AndAlso Not (rb = IntPtr.Zero) Then
            Return CType(DisposableWrapper.Create(GetType(ResultBuffer), rb, True), ResultBuffer)
        End If

        ' Getting the symbol failed if we reach this return statement
        Return Nothing
    End Function

    Public Shared Function GetLispStrSym(ByVal sym As String) As String
        ' Get the string value of a Lisp symbol
        ' The name (or expression) of the lisp symbol is passed in sym.
        ' Adapted from CP 214-4 AutoCADŽ .NET: Using .NET With Your LISP Applications example
        '   Output values are returned in an AutoCAD specific ResultBuffer.
        '   ResultBuffer can contain int, float, string, etc.
        '   This routine only accomodates a string!

        ' Populate a ResultBuffer with the values of the symbol by calling
        ' local function AcadGetSym which uses acedGetSym that was called through
        ' P/Invoke

        Dim ResBuf As ResultBuffer = AcadGetSym(sym)

        ' Ensure that ResultBuffer is not nothing
        If Not (ResBuf Is Nothing) Then
            Dim s As StringBuilder = New StringBuilder
            ' Append each type and value in the symbol
            For Each val As TypedValue In CType(ResBuf, IEnumerable)
                If val.TypeCode = 5005 Then 'is it a string?
                    s.AppendFormat("{0}", val.Value.ToString)
                Else
                    GetLispStrSym = "Valid LISP symbol, but it's not a string!"
                    Exit Function
                End If
            Next
            GetLispStrSym = s.ToString()
        Else
            GetLispStrSym = "*That's not a Lisp Symbol*"
        End If
    End Function


End Class

and the simple form code. Form1.vb
Code: [Select]
Public Class Form1

    'setup an example LISP symbol input.
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        EnterText.Text = "pi"
    End Sub

    'On cliking okay, we pass the entered entered text into GetLispStrSym
    Private Sub Okay_Click(sender As Object, e As EventArgs) Handles Okay.Click
        ReturnTxt.Text = AGS_Class.GetLispStrSym(EnterText.Text).ToString
    End Sub
    'Exit if canceled.
    Private Sub CanIt_Click(sender As Object, e As EventArgs) Handles CanIt.Click
        Me.Close()
    End Sub


End Class



AIYOUNG

  • Guest
Re: AcedGetSym in 32-bit AutoCAD 2015
« Reply #6 on: June 16, 2014, 12:55:48 PM »
Using

Code: [Select]
    <DllImport("acCore.dll", CharSet:=CharSet.Unicode, _
           CallingConvention:=CallingConvention.Cdecl, EntryPoint:="_acedGetSym")> _
    Shared Function acedGetSym(ByVal args As String, <Out()> ByRef result As IntPtr) As Integer
    End Function

Instead of

Code: [Select]
    <DllImport("acCore.dll", CharSet:=CharSet.Unicode, _
           CallingConvention:=CallingConvention.Cdecl, EntryPoint:="acedGetSym")> _
    Shared Function acedGetSym(ByVal args As String, <Out()> ByRef result As IntPtr) As Integer
    End Function

works great for 32 bit AutoCAD 2015.

Thanks for all the help!

It is still really weird that AcedGetSym is named different in 32 bit 2015 though.