ObjectARX applications typically define one or more commands that the user can call from the AutoCAD command prompt. For your tool application, you need only a single command to create tool catalogs, tool palettes, and tools. This command is used only once, when your application is first loaded. After your command has successfully created the tool components, AutoCAD saves their information to ATC files, along with the path to your ObjectARX module. Thereafter, the Tool Palette framework loads your application when it initializes the Tool Palettes window. Your tools and palettes become part of the Tool Palettes window's default configuration until they are removed.
For this project, you create a new AutoCAD command named CREATESIMPLE. You can define this command by clicking the ObjectARX wizard's ObjectARX Commands button, and then choosing New from the right-click menu in the ARX command list grid. Alternatively, if you did not use the ObjectARX wizard, you may create a registered command as described in ObjectARX Application Basics.
CComObject<CSimpleTool> tool; // Don't redefine the stock tool if it's already in the catalog if (AcTcGetManager()->FindStockTool(tool.GetObjectCLSID()) != NULL) return; AcTcCatalog* pCatalog = tool.CreateStockToolATC(_T(“SimpleCatalog”)); AcTcPalette* pPalette = tool.CreatePaletteATC(pCatalog, _T(“SimplePalette”)); tool.CreateCommandToolATC(pPalette, “Line”, “IDB_TOOL1”, “_LINE “);
AcTcGetManager()->LoadCatalogs(); // Refresh the palette in // AutoCAD.
You now have a working tool palette with a single tool that starts the LINE command. To add more tools, simply make additional calls to any of the following methods:
To use CreateFlyoutToolATC(), you must have created a shape catalog. You can do this by calling CreateShapeCatalogATC(). See the Adding Flyouts section for information on using these functions.
The CreateToolATC() function provides an optional parameter, szToolImageOverride, that lets you override your stock tool's default icon image setting by providing an image filename. The CreateFlyoutToolATC() function's optional szToolNameOverride parameter allows you to override the tool's default name.
Because this sample application hasn't used your COM object's properties, you don't encounter problems with uninitialized variables. However, most Tool Palette applications create tools that rely on custom data. To initialize the member variables that contain custom tool data, your coclass needs to override the AcadToolImpl::New() method. You should do the initialization in the New() method, rather than in the coclass constructor, because the constructor is used only to create the stock tool.
STDMETHOD(New)() { }
STDMETHOD(New)() { tcscpy(m_tcCmdName, _T("_LINE")); // Add other property variable initializations here... return S_OK; }
The following listing shows the finished command handler code:
CComObject<CSimpleTool> tool; // Don't redefine the stock tool if it's already in the catalog if (AcTcGetManager()->FindStockTool(tool.GetObjectCLSID()) != NULL) return;if (SUCCEEDED(tool.New())) {AcTcCatalog* pCatalog = tool.CreateStockToolATC(_T(“SimpleCatalog”)); AcTcPalette* pPalette = tool.CreatePaletteATC(pCatalog, _T(“SimplePalette”)); tool.CreateCommandToolATC(pPalette, “Line”, “IDB_TOOL1”, “_LINE “); AcTcGetManager()->LoadCatalogs(); // Refresh the palette in // AutoCAD}
By calling New(), you set the tool's properties to their default values. You can then reset some or all of those properties to specialized values before creating tools.