1. from Techniques for calling AutoCAD commands programmatically link(cn)
AutoCAD Command invoke method collection in ObjectARX
ObjectARX调用AUTOCAD内部命令方法大集合
ads_queueexpr()
This old favourite is intended to be used from acrxEntryPoint() to execute a sequence of commands after (s::startup) has been called from LISP (as you are not able to use acedCommand() from this context)
You need to declare it yourself (extern "C" void ads_queueexpr( ACHAR *);) before use
It has been unsupported as long as I can remember, but is widely-used and mentioned in the Tips & Techniques section of the ObjectARX Developer's Guide
AcApDocManager::sendStringToExecute()
This function has the advantage of a few more options being available as arguments, mainly around where to execute the string (which document, and whether it be activated), and whether to echo the string to the command-line
::SendMessage()
This is a standard Win32 platform API and so can, in effect, be used to drive AutoCAD from an external client. It uses a structure to pass the string that is often a bit tricky to set up (it became a migration issue when we switched to Unicode, for example)
IAcadDocument::SendCommand()
This COM method is the only way (other than acedCommand() or acedCmd()) to execute a command synchronously from AutoCAD (and even then it may not be completely synchronous if requiring user input)
acedCommand()
This is the ObjectARX equivalent to (command), and is genuinely synchronous. Unfortunately (as mentioned earlier) there are issues with using it directly from a natively-registered command, so I'd recommend only using it from acedDefun()-registered commands (see the ObjectARX documentation and the below sample for more details)
acedPostCommand()
VBA (some of which also applies to VB)
ThisDrawing.SendCommand
This is the same as IAcadDocument::SendCommand() from C++
SendKeys
This is just a simple technique to send key-strokes to the command-line
SendMessage
This is just the Win32 API mentioned above, but declared and called from VB(A)
尽管有着相同的方法或者函数,但是不同的开发语言方法或者函数使用方式却不径相同,例如sendStringToExecute() ,
在VB.NET中的用法是:
public void SendStringToExecute( String command, Boolean activate, Boolean wrapUpInactiveDoc, Boolean echoCommand );
Parameterscommand String to use as input. activate Boolean indicating whether to activate the target document. wrapUpInactiveDoc Boolean indicating whether to queue current active document to complete in the next OnIdle() when switching active documents. echoCommand Boolean indicating whether the sent string is echoed on the command line.
在C++中的用法又是这样的:
virtual Acad::ErrorStatus sendStringToExecute( AcApDocument* pAcTargetDocument, const char * pszExecute, bool bActivate = true, bool bWrapUpInactiveDoc = false, bool bEchoString = true) = 0;
pAcTargetDocumentDocument to send input topszExecuteString to use as inputbActivateBoolean indicating whether to activate the target documentbWrapUpInactiveDocBoolean indicating whether to queue current active document to complete in next OnIdle() when switching active documents.bEchoStringBoolean indicating whether the sent string is echoed on the command line
from Execute Commands from a Modeless dialog,
Use the function AcApDocManager::sendStringToExecute() (ensure one escape (ASCII 27) characters down first before the real string, this will cancel any previous running commands, if any).
Simulate menu selection by sending WM_COMMAND rather than WM_CHAR messages. Once the command is active you can then, of course, send WM_CHAR messages for the parameters. This would then only call commands that exist in the menu structure (though they could hidden/deeply nested).
Use the function int acedPostCommand(const ACHAR*) to send characters command-prompt.
Use the function int ads_queueexpr(const ACHAR *) to again send characters to the command prompt.