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

calling/modifying existing commands?

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
apichalski
758 Views, 6 Replies

calling/modifying existing commands?

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

6 REPLIES 6
Message 2 of 7
StephenPreston
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
Message 3 of 7
hgasty1001
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

Message 4 of 7
StephenPreston
in reply to: hgasty1001

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

Cheers,

Stephen Preston
Autodesk Developer Network
Message 5 of 7
apichalski
in reply to: StephenPreston

thanks a bunch for the tips

 

Alex

Message 6 of 7
apichalski
in reply to: hgasty1001

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

 

Alex

Message 7 of 7

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

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost