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

Problem calling acedCmd

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
HJohn1
3432 Views, 9 Replies

Problem calling acedCmd

HJohn1
Advocate
Advocate

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. 

0 Likes

Problem calling acedCmd

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. 

9 REPLIES 9
Message 2 of 10
DiningPhilosopher
in reply to: HJohn1

DiningPhilosopher
Collaborator
Collaborator
Accepted solution

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

0 Likes

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

Message 3 of 10
HJohn1
in reply to: DiningPhilosopher

HJohn1
Advocate
Advocate

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.

0 Likes

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.

Message 4 of 10
_gile
in reply to: HJohn1

_gile
Mentor
Mentor
Accepted solution

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
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes

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
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 5 of 10
DiningPhilosopher
in reply to: HJohn1

DiningPhilosopher
Collaborator
Collaborator
I see that Giles has help you out (thanks Giles)
0 Likes

I see that Giles has help you out (thanks Giles)
Message 6 of 10
HJohn1
in reply to: DiningPhilosopher

HJohn1
Advocate
Advocate

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.

0 Likes

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.

Message 7 of 10
HJohn1
in reply to: HJohn1

HJohn1
Advocate
Advocate
I was able to build the project and run the code, and your solution works very well, so thanks again.
0 Likes

I was able to build the project and run the code, and your solution works very well, so thanks again.
Message 8 of 10
Anonymous
in reply to: _gile

Anonymous
Not applicable

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


 

0 Likes

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


 

Message 9 of 10
Anonymous
in reply to: Anonymous

Anonymous
Not applicable

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

 

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

 

Hope this helps someone else.

0 Likes

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

 

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

 

Hope this helps someone else.

Message 10 of 10
Anonymous
in reply to: Anonymous

Anonymous
Not applicable

I'm having the same issue as bruceamcd. Without a form it works fine.

But using a form with either Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog or ShowModelessDialog it doesn't.

 

I'm using Tony's Runcommand wrapper from Autocad 2014 x64.

FIBERWORLD is set to 1 as required.

 

Any thoughts on what might cause this behavior are welcome. thanks.

0 Likes

I'm having the same issue as bruceamcd. Without a form it works fine.

But using a form with either Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog or ShowModelessDialog it doesn't.

 

I'm using Tony's Runcommand wrapper from Autocad 2014 x64.

FIBERWORLD is set to 1 as required.

 

Any thoughts on what might cause this behavior are welcome. thanks.

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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report