Implementing Runtime Behavior

You define your tool's runtime behavior in its executeCallback() routine. This function is called by the AcadToolImpl implementation of IAcadTool::Execute().

A tool can do anything that is programmatically possible within AutoCAD. Command tools, for instance, launch AutoCAD commands and macros. If you create a command tool with the AcadToolImpl class, you merely specify the command or macro string when you call CreateCommandToolATC(). Internally, the macro string is stored in the stock tool's ATC file in a special <Macro> XML node. In this simplest case, you do not provide any other execution code.

Non-command tools frequently create pre-configured instances of custom entities, for example, a tool palette that offers several pre-configured versions of a custom entity. Then when a tool is executed, the user provides only the insertion point and dimensions of the tool. Other properties could be set to match built-in industry standards.

In the following sample, the executeCallback() method uses an AsdkBoltJig instance, PromptObject, to create a new entity. AsdkBoltJig derives from the AsdkPromptBase template class which, in turn, inherits AcEdJig. When an AsdkBoltJig object is instantiated, it creates a database-resident asdkBolt object. Because AsdkPromptBase inherits AcEdJig, PromptObject can be used to prompt the user to specify properties interactively. The executeCallback() code uses a pointer to the asdkBolt object to set its tool-specific properties. After the user specifies the remaining property values, the AsdkBoltJig object applies those settings to the object.

Here is a sample executeCallback() function:

STDMETHODIMP CBoltTool::executeCallback()
{
CComObject <AsdkBoltJig> PromptObject; // Instantiate a Prompt
                                       // for the Employee.
// Set the color, layer, Material and Part Number.
asdkBolt *pBolt =     (asdkBolt*)asdkBolt::cast(PromptObject.m_pDbrObject);
if (pBolt)
{
    // Color, Color Name and Book Name
    AcCmColor color;
    color.setColor(m_Color.color());
    color.setNames(m_Color.colorName(),m_Color.bookName());
    pBolt->setColor(color);
    pBolt->setLayer(CT2A(m_szLayer));
    pBolt->setMaterialName(CT2A(m_MaterialName));
    pBolt->setPartNumber(CT2A(m_PartNumber));
}
else
    return E_FAIL;
// Specify that we're setting the Tool's properties to the 
// Prompt so they are not jigged.
PromptObject.bSetFromTool=true;
PromptObject.m_HeadSides=m_HeadSides;
PromptObject.m_HeadHeight=m_HeadHeight;
PromptObject.m_ShaftLength=m_ShaftLength;
PromptObject.m_ShaftDiameter=m_ShaftDiameter;
PromptObject.m_ThreadLength=m_ThreadLength;
PromptObject.m_ThreadWidth=m_ThreadWidth;
PromptObject.m_HeadDiameter=m_HeadDiameter;
// Enter the prompt loop.
AcDbObjectId PromptId=PromptObject.promptLoop();
return S_OK;
}

The AsdkPromptBase helper template class is part of the ObjectARX SDK. It is defined in the \inc\asdkPromptBase.h file.