Adding Flyouts

Custom flyout tools use a package of shapes, rather than a single icon, to represent multiple tools on a flyout palette. In most cases, this means you must create images that you add to an ATC catalog. If your flyout needs only standard AutoCAD commands, however, you can use one of AutoCAD's pre-defined shape catalogs. A flyout tool may use any shape package described in the shapes.atc file.

If you wish to create your own shape catalog, the AcadToolImpl class again facilitates the task. Here is an outline of how to create a new shape catalog and flyout tool.

To create a new flyout tool (Palettes sample)

  1. Create a new tool:
    CComObject<CBoltTool> tool;
  2. Create a shape catalog using the AcadToolImpl::CreateShapeCatalogATC() function:
    AcTcPackage* pShapePackage=tool.CreateShapeCatalogATC("Bolt Flyout Catalog");
  3. Set the tool's properties to values that define one of the shapes.
  4. Call the AcadToolImpl::CreateToolATC() function, passing the shape package pointer from step 2 as the first parameter. If you want the shape to use an image other than the tool's default image, pass the resource ID of the desired image as the second parameter.
    if(!tool.CreateToolATC(pShapePackage,"IDB_BOLTALUMINUM"))
        acutPrintf("\nFailed to create a Tool instance\n");
  5. Repeat steps 3 and 4 for each shape in the catalog.
  6. After adding your tools to the shape package, call AcadToolImpl::CreateFlyoutToolATC() to create the flyout tool:
    if(!tool.CreateFlyoutToolATC(pPalette,pShapePackage))
        acutPrintf("\nFailed to create a Flyout Tool instance\n");

For the SimpleTool project, you can create a flyout tool more easily by using one of AutoCAD's pre-defined shape packages. You add a function call to create the shape catalog, and another to create the flyout tool. The following example uses the package named “*AutoCADShapes” to create your shape catalog.

To add a pre-packaged flyout tool to the SimpleTool project

  1. In the SimpleTool project, go to your command handler for the CREATESIMPLE AutoCAD command.
  2. Add the following two lines to your command implementation immediately after the CreatePaletteATC() function call:
AcTcPackage* pPackage = tool.CreateShapeCatalogATC("*AutoCADShapes");
tool.CreateFlyoutToolATC(pPalette, pPackage);

Here is the complete listing of your revised command handler:

static void asdkSimpleToolPalette_CREATESIMPLE(void)
{
  CComObject<CSimpleTool> tool;
  if (SUCCEEDED(tool.New()))
  {
      AcTcCatalog* pCatalog = tool.CreateStockToolATC(_T(“SimpleCatalog”));
      AcTcPalette* pPalette = tool.CreatePaletteATC(pCatalog, _T(“SimplePalette”));
      AcTcPackage* pPackage = tool.CreateShapeCatalogATC("*AutoCADShapes");
      tool.CreateFlyoutToolATC(pPalette, pPackage);
      tool.CreateCommandToolATC(pPalette, “Line”, “IDB_TOOL1”, “_LINE ”);
      tool.CreateToolATC(pPalette);
      AcTcGetManager()->LoadCatalogs(); // Refresh the palette in
                                        // AutoCAD
  }
}

For flyout tools, you can display a special property lets users choose which shapes to display. You need to add a new interface property named Flyout, and then add an entry to the flyout property map.

To add flyout property support

  1. Using Visual Studio's ATL wizard, add a new BSTR property named Flyout that supports both get and put functions.
  2. Open the SimpleTool.idl file.
  3. Find the new Flyout property declaration and make a note of its property ID.
  4. In SimpleTool.h, add the following entry between the BEGIN_FLYOUT_SPECIFIC_MAP() and END_FLYOUT_SPECIFIC_MAP() macro lines, using the property ID for the Flyout property as its argument:

    FLYOUT_ENTRY(2)

    Note: Do not provide declaration or implementation code for the Flyout property's accessors.

To see the effect of your flyout property, restart AutoCAD. When the tool palette appears, right-click your flyout tool and choose the Properties menu item. In the General section of the Tool Properties dialog box, you should see a new property named Flyout. In place of a property value, the dialog box displays the Choose Command prompt. Clicking this prompt displays an ellipsis button that launches a Flyout Options dialog box. This dialog box lets the user determine which shapes appear in the flyout menu.

The AcadToolImpl class pre-defines the Flyout property. You can also define your own flyout-specific properties and provide entries for them in the map. These properties apply only to flyout shapes that reference your flyout tool. If shapes within a flyout package reference other tool objects, your properties do not apply to those shapes.