跟朋友要的: Creating a new document and activating it from a custom command
Issue
How can I create a new document and activate it from a custom command?
Solution
There are two ways to do this:
Method #1 Register your command with ACRX_CMD_SESSION flag and use the appContextNewDocument API to create the new document. The drawback of this approach is that your command will be executed in the application context, therefore, you will need to do explicit document locking if you want to interact with any documents. Also, you cannot use acedCommand/acedCmd/acedInvoke APIs from the application context.
Method #2 Register your command with ACRX_CMD_MODAL flag and use the executeInApplicationContext API within your command handler to switch the application context. The drawback of this approach is that you will need to create a hidden window that coordinates the activation of the newly created document once the 'creator' command finishes.
Both methods are demonstrated in the attached AutoCAD 2002 sample.
|