Creo Elements/Direct Model Manager Customization Guide > Additional Customizations > Command handler for Creo Elements/Direct Modeling or Creo Elements/Direct Drafting
Command handler for Creo Elements/Direct Modeling or Creo Elements/Direct Drafting
You can register new commands in Creo Elements/Direct Model Manager or Creo Elements/Direct Drawing Manager that are called by Creo Elements/Direct Modeling or Creo Elements/Direct Drafting. A custom command handler works like this:
1. The command handler class is registered when the XML configuration file is read at startup.
2. When a command comes from Creo Elements/Direct Modeling or Creo Elements/Direct Drafting, the processCommand method is called on the appropriate command handler object.
How to create a command handler
To create a command handler, you must
1. 1. Add the command handler to your custom XML configuration file.
2. 2. Create a command handler class that implements the OSDCommandHandler or ME10CommandHandler interface.
1. Add the command handler
You add the command handler in your custom XML configuration file. Add the following tags and value to the <Handlers> section:
<OSDHandler>MY-COMMAND-HANDLER
<Implementation>com.mydomain.datamgmt.integration.command.osd.myCommandHandler</Implementation> </OSDHandler>
This tells Creo Elements/Direct Modeling or Creo Elements/Direct Drafting which object to invoke when the command is requested. You should replace the values for your command name and processor in the example above.
* 
Remember, you should never change wmconf.xml; you should always add custom configuration to your custom configuration file.
2. Create a command handler class
Your custom command handler must implement the OSDCommandHandler interface for Creo Elements/Direct Model Manager, or the ME10CommandHandler interface for Creo Elements/Direct Drawing Manager.
In either case, the class constructor calls super with two boolean values: runInSeparateThread and ignoreUIEventsWhileRunning. These two values are important, because if they are not set correctly for your operations, Creo Elements/Direct Modeling or Creo Elements/Direct Drafting and Creo Elements/Direct Model Manager or Creo Elements/Direct Drawing Manager will hang, and your users will lose their work.
The runInSeparateThread value determines if the command handler executes in the calling thread or in a new thread. If the command handler executes in the calling thread (the value is set to false), Creo Elements/Direct Modeling or Creo Elements/Direct Drafting blocks all other operations while the call is taking place. You should use the calling thread if the command handler needs to return a value to Creo Elements/Direct Modeling or Creo Elements/Direct Drafting.
You can also run the command handler in a new thread (set the runInSeparateThread value to true). You must run in a new thread if the handler needs to call a function in Creo Elements/Direct Modeling or Creo Elements/Direct Drafting. For example, if you need to open a model during your operation, you must run the command in a new thread. If you don't use a new thread in this case, Creo Elements/Direct Modeling will block the call from the Java side and both applications will hang. However, you cannot return a value to Creo Elements/Direct Modeling or Creo Elements/Direct Drafting if you run the call in a new thread.
The ignoreUIEventsWhileRunning value determines whether or not the user interface (UI) will update while the command is being processed. You should set this value to true if the handler opens, closes or processes a lot of data. If it is set to false, the UI is not updated while the command is processed, and events that were blocked will be processed when the processCommand method has completed.
If you aren't sure how to set these values for your command handler, set runInSeparateThread to false and ignoreUIEventsWhileRunning to true, then test your new command. Your class constructor would look like this:
public myCommandProcessor() {
super(false, true);
}
Your command handler class must also include a processCommand method, which is called when the command is invoked in Creo Elements/Direct Modeling or Creo Elements/Direct Drafting. This method is where you add your Java code to perform the command. The parameters for the method are a list of strings, and the method should return either "T" or "nil".
Your processCommand method should look like this:
public String processCommand(java.util.List parameters) throws WMException {
String myParameters = removeQuotes((String)parameters.get(0));
// Your code goes here
return "T";
}
As you can see in the example above, you may need to remove the quotes that were used in LISP. You can also see the return, which should be available in Creo Elements/Direct Modeling or Creo Elements/Direct Drafting. Please note that "T" will appear as String T, not the LISP T.
3. Call at startup
If you need the command handler to be called on the startup of Creo Elements/Direct Model Manager or Creo Elements/Direct Drawing Manager, you need to add LISP/Macro code to the Creo Elements/Direct Model Manager or Creo Elements/Direct Drawing Manager startup customization file. The file is located in:
C:\Program Files\PTC\Creo Elements\Direct Modeling 20.6\personality\sd_customize\ModelManager\mm_customize
-or-
WMDT_DIR\aips\me10\startup\cust.m
The Creo Elements/Direct Modeling LISP call would be:
(modelmanager::mm-send-cmd "COMMAND-NAME 'arg1' 'arg2'")
* 
Only simple strings (maximum 15 characters and without any special characters) like ELIDs, SYSIDs, paths, or filenames, can be specified as an argument. Arguments must not contain double quotes or single quotes. Complex strings must be saved in a file and the filename can then be specified as an argument.
For Creo Elements/Direct Drafting:
DWG_MGMT_SEND_COMMAND "COMMAND-NAME 'arg1' 'arg2'"
4. Call the CAD application
For Creo Elements/Direct Model Manager, use:
String rtn = com.osm.datamgmt.DataManager.getInstance().getSolidDesigner(). execute( "(LISP)");
rtn will be the LISP return value converted to a Java string.
For Creo Elements/Direct Drawing Manager, use:
com.osm.datamgmt.DataManager.getInstance().getME10().executeCommand("ME10 MACRO");
There is no specific Creo Elements/Direct Annotation object. Commands to Creo Elements/Direct Annotation go through Creo Elements/Direct Modeling, so you should use the example for Creo Elements/Direct Model Manager. If you need to get macro code executed in Creo Elements/Direct Annotation, you can use something like this:
com.osm.datamgmt.DataManager.getInstance().getSolidDesigner(). execute("(docu-cmd 'macro call')");
* 
The customization file for the integration between Creo Elements/Direct Annotation and Creo Elements/Direct Model Manager is am_mm_customize and that for integration between Creo Elements/Direct Annotation and Desktop or Design Data Management is am_wm_customize. For more information about the customization file, see the Creo Elements/Direct Modeling Help.
Was this helpful?