.NET

Reply
Distinguished Contributor
HJohn1
Posts: 169
Registered: ‎09-26-2008
Message 1 of 9 (486 Views)
Accepted Solution

Problem calling acedCmd

486 Views, 8 Replies
01-15-2014 09:20 AM

I am using TT's CommandLine class in my project. Initially, when I loaded the project in AutoCAD 2014 I had to change "acad.exe" to "accore.dll" and it worked fine and continues working fine in my developing machine.  Now, I am having problems in some computers where the commandline class seems to be not working properly. It seems to me that I had come across some posts that talked about the differences in the function signature for 32 and 64bit platforms, however now I can't find any information about it.  Can someone give me some help on this issue.  It will be really appreciated. 

Valued Mentor
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 2 of 9 (465 Views)

Re: Problem calling acedCmd

01-15-2014 01:33 PM in reply to: HJohn1

There's no need to P/Invoke acedCmd() directly on recent releases of AutoCAD

thanks to the RunCommand wrapper (not sure what release it appeared in initially).

 

acedCmd() doesn't support the use of managed selection sets, but RunCommand()

does (it handles that internally for you) and allows them to be passed as arguments

where a command is expecting a selection set.

 

See this post:

 

http://forums.autodesk.com/t5/NET/Send-Command-Executes-after-exiting-command-method/td-p/3882929

Distinguished Contributor
HJohn1
Posts: 169
Registered: ‎09-26-2008
Message 3 of 9 (439 Views)

Re: Problem calling acedCmd

01-16-2014 05:37 AM in reply to: DiningPhilosopher

DP thank you very much for your help, very appreciated.  Now, would it be to much to ask if there is, you have or have seen a VB version.  I am using VS2010 Express and can not use C# code.  Trying to Port it myself will make the few hair left to fall out.

*Expert Elite*
_gile
Posts: 2,077
Registered: ‎04-29-2006
Message 4 of 9 (420 Views)

Re: Problem calling acedCmd

01-16-2014 12:12 PM in reply to: HJohn1

Hi,

 

Here's a VB conversion of Tony's RunCommand wrapper.

 

With VB, extension methods have to be defined a module. If the module isn't part of the same namespace, you have to import it:

 

Imports EditorInputExtensionMethods

 

    Module EditorInputExtensionMethods
 
       <System.Runtime.CompilerServices.Extension> _
       Public Function Command(editor As Editor, ParamArray args As Object()) As PromptStatus
           If editor Is Nothing Then
               Throw New ArgumentNullException("editor")
           End If
           Return runCommand(editor, args)
       End Function
 
       Dim runCommand As Func(Of Editor, Object(), PromptStatus) = GenerateRunCommand()
 
       Private Function GenerateRunCommand() As Func(Of Editor, Object(), PromptStatus)
           Dim method As MethodInfo = GetType(Editor).GetMethod( _
               "RunCommand", BindingFlags.Instance Or BindingFlags.NonPublic Or BindingFlags.[Public])
           Dim instance As ParameterExpression = Expression.Parameter(GetType(Editor), "editor")
           Dim args As ParameterExpression = Expression.Parameter(GetType(Object()), "args")
           Return Expression.Lambda(Of Func(Of Editor, Object(), PromptStatus)) _
               (Expression.Call(instance, method, args), instance, args).Compile()
       End Function
 
   End Module

 

Gilles Chanteau
Valued Mentor
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 5 of 9 (418 Views)

Re: Problem calling acedCmd

01-16-2014 12:20 PM in reply to: HJohn1
I see that Giles has help you out (thanks Giles)
Distinguished Contributor
HJohn1
Posts: 169
Registered: ‎09-26-2008
Message 6 of 9 (377 Views)

Re: Problem calling acedCmd

01-20-2014 07:37 AM in reply to: DiningPhilosopher

Thank you both for your help. I have marked both of your posts as solutions, since it is what I was looking for.  However, I have not been able to run or test this solution.  Since the moment I added the ExtensionMethod to my project, I am getting a error message on VS 2010 that says "No Source Available".  I am going to create a separate post about this issue.  I have never come across something like this, but it seems to be common.

Distinguished Contributor
HJohn1
Posts: 169
Registered: ‎09-26-2008
Message 7 of 9 (363 Views)

Re: Problem calling acedCmd

01-20-2014 10:19 AM in reply to: HJohn1
I was able to build the project and run the code, and your solution works very well, so thanks again.
Member
bruceamcd
Posts: 3
Registered: ‎11-30-2007
Message 8 of 9 (295 Views)

Re: Problem calling acedCmd

02-12-2014 11:38 AM in reply to: _gile

I am having trouble with the EditorinputExtensionMethods.  I'm not sure what I'm doing wrong, but when I call the editor.Command(parameters), absolutely nothing happens.  I have access to the editor, because the editor.WriteMessage command works.  I am calling the editor.Command from a button click on a windows form in a module loaded into AutoCAD with NETLOAD.  Any insight would be greatly appreciated!  Code is inserted below.

 

Imports System
Imports System.Collections
Imports System.Collections.Generic
Imports System.IO
Imports System.Linq
Imports System.Reflection
Imports System.Linq.Expressions
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime

Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Imports System.Data.SqlServerCe
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.ApplicationServices.DocumentExtension

Module EditorInputExtensionMethods

    <System.Runtime.CompilerServices.Extension> _
    Public Function Command(editor As Editor, ParamArray args As Object()) As PromptStatus
        If editor Is Nothing Then
            Throw New ArgumentNullException("editor")
        End If
        Return runCommand(editor, args)
    End Function

    Dim runCommand As Func(Of Editor, Object(), PromptStatus) = GenerateRunCommand()

    Private Function GenerateRunCommand() As Func(Of Editor, Object(), PromptStatus)
        Dim method As MethodInfo = GetType(Editor).GetMethod( _
            "RunCommand", BindingFlags.Instance Or BindingFlags.NonPublic Or BindingFlags.Public)
        Dim instance As ParameterExpression = Expression.Parameter(GetType(Editor), "editor")
        'Dim instance As ParameterExpression = Expression.Parameter(GetType(Editor), "instance")
        Dim args As ParameterExpression = Expression.Parameter(GetType(Object()), "args")
        Return Expression.Lambda(Of Func(Of Editor, Object(), PromptStatus)) _
            (Expression.Call(instance, method, args), instance, args).Compile()
    End Function

End Module

Public Class frmMhsApp
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim doc As Document =
                  Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
        Dim ed As Editor = doc.Editor

        ed.Command("._line", New Point3d(0, 0, 0), New Point3d(5, 5, 0))

        ed.WriteMessage("Message Test")
    End Sub


 

Member
bruceamcd
Posts: 3
Registered: ‎11-30-2007
Message 9 of 9 (252 Views)

Re: Problem calling acedCmd

02-14-2014 01:07 PM in reply to: bruceamcd

I found my issue!  I had to load my form as follows:

 

Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(frmApp)

 

Hope this helps someone else.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

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 to get help installing your software.

Ask the Community