.NET

Reply
Contributor
apichalski
Posts: 15
Registered: ‎08-13-2013
Message 1 of 7 (304 Views)
Accepted Solution

calling/modifying existing commands?

304 Views, 6 Replies
01-03-2014 08:37 AM

Hey all,

My question probably reveals my inexperience with API- I've been tearing through tutorials this week.

 

I'm really curious, is it possible to call or modify/inherit any autocad command? I'm looking to create a command that hatches the area between an offset, but I can't find any material on how to even utilize existing commands.

 

Thanks in advance for any help

Alex

You can call an AutoCAD command from your own command using one of the following techniques:

 

The .NET SendStringToExecute method

The ActiveX SendCommand method

P/Invoking the C++ acedCommand method - this technique has a slight risk to it, because of AutoCAD's use of Fiber technology (which the .NET Framework doesn't support), but it usually works without problem.

 

You can't modify an existing command, but you can redefine it or react to what it has done (using event callbacks).

 

You'll find some sample code if you search for all those method names on http://adndevblog.typepad.com/autocad/.

 

Hi,

 

In addition to Stephen's advice, you can also check this link to the Kean's blog: Hatch

 

Gaston Nunez

Board Manager
StephenPreston
Posts: 383
Registered: ‎05-22-2006
Message 2 of 7 (293 Views)

Re: calling/modifying existing commands?

01-03-2014 10:17 AM in reply to: apichalski

You can call an AutoCAD command from your own command using one of the following techniques:

 

The .NET SendStringToExecute method

The ActiveX SendCommand method

P/Invoking the C++ acedCommand method - this technique has a slight risk to it, because of AutoCAD's use of Fiber technology (which the .NET Framework doesn't support), but it usually works without problem.

 

You can't modify an existing command, but you can redefine it or react to what it has done (using event callbacks).

 

You'll find some sample code if you search for all those method names on http://adndevblog.typepad.com/autocad/.

 

Cheers,

Stephen Preston
Autodesk Developer Network
Valued Mentor
gasty1001
Posts: 487
Registered: ‎04-11-2010
Message 3 of 7 (283 Views)

Re: calling/modifying existing commands?

01-03-2014 11:58 AM in reply to: apichalski

Hi,

 

In addition to Stephen's advice, you can also check this link to the Kean's blog: Hatch

 

Gaston Nunez

Board Manager
StephenPreston
Posts: 383
Registered: ‎05-22-2006
Message 4 of 7 (264 Views)

Re: calling/modifying existing commands?

01-03-2014 02:46 PM in reply to: gasty1001

Thank you Gaston. I didn't notice that this was about creating a hatch.

Cheers,

Stephen Preston
Autodesk Developer Network
Contributor
apichalski
Posts: 15
Registered: ‎08-13-2013
Message 5 of 7 (229 Views)

Re: calling/modifying existing commands?

01-06-2014 06:00 AM in reply to: StephenPreston

thanks a bunch for the tips

 

Alex

Contributor
apichalski
Posts: 15
Registered: ‎08-13-2013
Message 6 of 7 (225 Views)

Re: calling/modifying existing commands?

01-06-2014 06:09 AM in reply to: gasty1001

gasty, thank you so much. that is a huge help!

 

Alex

Valued Mentor
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 7 of 7 (203 Views)

Re: calling/modifying existing commands?

01-07-2014 12:24 AM in reply to: apichalski

I've found that the best way to script AutoCAD commands from managed code is synchronously, using the undocumented RunCommand() method of the Editor class. The .NET framework's lack of support for the cooperative/non-preemptive threading model AutoCAD uses (e.g. 'fibers') is not a problem. Managed code runs in AutoCAD's cooperaative fiber mode threading model just fine.

 

What you cannot do with RunCommand() or acedCmd() is execute commnds that trigger a change in the active document (e.g., "OPEN", "NEW", etc), because acedCmd() (and its RunCommand() managed wrapper) can only be called from the document execution context, which is active only when its associated document is active (every open document has its own distinct execution context, only one of which can be active at any given time). So, if your command-scripting code causes the active document to change, the execution of the calling code will be suspended until the associated document that was active when the scripting was started becomes active again. That usually isn't a problem for simple cases where you are only operating on the active document. It would be a problem in cases where your scripting operates on many open documents (like ScriptPro does), so that's something to bear in mind.

 

The RunCommand() managed wrapper for acedCmd() addresses a few problems associated with the direct use of the latter via P/Invoke, which Kean's writing doesn't mention, namely that acedCmd() does not support managed selection sets.  The RunCommand() method addresses that internally and provides a way to automate commands that require a user to select objects, and to provide them with a managed selection set.

 

The post at the link below contains a wrapper for RunCommand() that makes it easier to use, along with an example:

 

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

Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.