CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ObjectARX 开发指南

示例:示例项目

2022-12-31 08:58| 发布者: admin| 查看: 252| 评论: 0|来自: AutoCAD

在示例项目中,用于创建工具的命令处理程序将浮出控件技术与工具创建相结合。它创建一个默认工具、两个工具和一个命令工具,并将每个工具添加到其形状包中。此示例通过调用函数来设置工具的默认值。然后,它通过提供覆盖这些默认值的专用属性值来创建新工具。以下清单显示了创建螺栓工具目录的命令的完整定义:New()

void asdkCreateTools()
{
    CComObject<CBoltTool> tool;
    // Create the stock tool (definition)
    AcTcCatalog
      *pCatalog=tool.CreateStockToolATC(_T("BoltCatalog"));
    if(!pCatalog)
    {
        acutPrintf("\nFailed to create the Stock Tool\n");
        return;
    }
    // Create the 'BoltPalette'
    AcTcPalette
      *pPalette=tool.CreatePaletteATC(pCatalog,_T("BoltPalette"));
    if(!pPalette)
    {
        acutPrintf("\nFailed to create the Palette\n");
        return;
    }
    // Create the shape package to hold the flyout tool definitions
    AcTcPackage*
      pShapePackage=tool.CreateShapeCatalogATC(_T("Bolt Flyout
        Catalog"));
    if(!pShapePackage)
    {
        acutPrintf("\nFailed to create the Shape Catalog\n");
        return;
    }
    if(pShapePackage->GetChildCount()==0)
    {
        // Add two tools to this package
        tool.New(); //Set Default Values specified in the New                     //override for this tool.
        if(!tool.CreateToolATC(pShapePackage,_T("Stainless Bolt"),
          _T("IDB_BOLTIMAGE")))
            acutPrintf("\nFailed to create a Tool instance\n");
        // Now, create additional tools with different parameters:
        tool.m_HeadSides=6;
        tool.m_HeadHeight=2.5f;
        tool.m_ShaftLength=12.0f;
        tool.m_ShaftDiameter=3.0f;
        tool.m_ThreadLength=3.5f;
        tool.m_ThreadWidth=0.1f;
        tool.m_HeadDiameter=7.0f;
        tool.m_Color.setColorIndex(2);
        _tcscpy(tool.m_MaterialName,_T("Aluminum"));
        _tcscpy(tool.m_PartNumber,_T("Unassigned"));										
        if(!tool.CreateToolATC(pShapePackage,_T("Aluminum Bolt"),
          _T("IDB_BOLTALUMINUM")))
            acutPrintf("\nFailed to create a Tool instance\n");
        // A separate galvanized tool.
        tool.m_HeadSides=6;
        tool.m_HeadHeight=3.5f;
        tool.m_ShaftLength=15.0f;
        tool.m_ShaftDiameter=5.0f;
        tool.m_ThreadLength=5.5f;
        tool.m_ThreadWidth=0.3f;
        tool.m_HeadDiameter=9.0f;
        tool.m_Color.setColorIndex(4);
        _tcscpy(tool.m_MaterialName,_T("Galvanized"));
        _tcscpy(tool.m_PartNumber,_T("Unassigned"));										
        if(!tool.CreateToolATC(pShapePackage, _T("Galvanized"),
          _T("IDB_BOLTGALVANIZED")))
            acutPrintf("\nFailed to create a Tool instance\n");
        if(!tool.CreateCommandToolATC(pShapePackage,           _T("BoltJig"), _T("IDB_BOLTJIG"), _T("^C^CBOLTJIG")))
            acutPrintf("\nFailed to create the Command Tool
              instance\n");
    }
    // Now create a flyout tool, a regular tool, and a command
    // tool on the palette.
    tool.New();//reset the properties...
    if(!tool.CreateFlyoutToolATC(pPalette, pShapePackage, "Bolt
      Flyout"))
        acutPrintf("\nFailed to create a Flyout Tool instance\n");
    if(!tool.CreateToolATC(pPalette, _T("Stainless Tool"),
      _T("IDB_BOLTIMAGE")))
        acutPrintf("\nFailed to create a Shape Tool instance\n");
    if(!tool.CreateCommandToolATC(pPalette, _T("BoltJig"),
      _T("IDB_ BOLTJIG"),_T("^C^CBOLTJIG")))
        acutPrintf("\nFailed to create a Shape Command Tool
          instance\n");
    // Refresh the Tool Palette with the above changes.
    AcTcGetManager()->LoadCatalogs(); // Refresh the Palette in the                                       // AutoCAD UI.
}

在上面的代码中,请注意专用属性设置如何创建铝螺栓工具,然后创建镀锌钢示例。唯一的形状表示弹出菜单上的每个工具。这些形状是通过为每个工具的函数调用提供单独的位图 ID 来指定的。CreateToolATC()


路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 )

GMT+8, 2024-5-28 02:03

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部