10 - 程序样例(楼梯)

1 新建一个空目录RpCtDmStair



2 VS 新建3DS Workspace 项目,选取RpCtDmStair文件夹。




3 创建新的框架 RF0001


4 配置Prerequisites




5 创建RM0001 模块


6 参考步骤5创建RM0002 模块

7 在RM0002.m中添加新建项 Stair.DSGen


8 用工具箱元素在 Stair.DSGen 上画图



9 特别注意下面参数配置为True

10 配置apply 按键触发方法

11 配置 SpiralStaircase_ApplyBtnPushed 方法的代码
    double r1 = 0; _edr1->GetText().ConvertToNum(&r1);
    double r2 = 0; _edr2->GetText().ConvertToNum(&r2);
    double num = 0; _edn->GetText().ConvertToNum(&num);
    double h = 0; _edh->GetText().ConvertToNum(&h);
    double a = 0; _eda->GetText().ConvertToNum(&a);

    double step_a = (a * PI) / num;
    double step_h = h / num;
    double offset_dimension = h / 2;

    CATFrmEditor* pEditor = CATFrmEditor::GetCurrentEditor();
    CATDocument *pDoc = pEditor->GetDocument();
    CATInit_var spInitOnDoc(pDoc);
    // Retrieves the root container
    CATIPrtContainer * piPrtCont = (CATIPrtContainer*)spInitOnDoc->GetRootContainer("CATIPrtContainer");

    // Retrieves the sketch factory to instantiate objects
    CATISketchFactory_var spSketchFactOnPrtCont(piPrtCont);

    // Creates the sketch plane
    // retrieves the reference planes of the part
    CATIPrtPart_var spPart;
    if (piPrtCont)
        spPart = piPrtCont->GetPart();
    CATListValCATISpecObject_var spListRefPlanes = spPart->GetReferencePlanes();

    // defines the xy plane as the first sketch plane
    CATISpecObject_var spSketchPlane = spListRefPlanes[1];

    // Retrieves the Mechanical Design factory to create the pad
    CATIPrtFactory_var      spPrtFactOnPrtCont(piPrtCont);
    if (piPrtCont)
    {
        piPrtCont->Release();
        piPrtCont = NULL;
    }

    for (int i = 1; i <= num; i++)
    {
        // Instantiates the sketch with the plane
        CATISketch_var spSketch = spSketchFactOnPrtCont->CreateSketch(spSketchPlane);

        // Retrieves the 2D factory to create the lines and points of the sketch
        CATI2DWFFactory_var spWF2DFactOnSketch(spSketch);

        // Creates the elements of the sketch
        double cp[2] = { 0., 0. };

        // Edits the sketch and draws the lines and the endpoints.
        spSketch->OpenEdition();

        double a1 = step_a * (i - 1);
        double a2 = step_a * i;
        CATISpecObject_var arc1 = spWF2DFactOnSketch->CreateCircle(cp, r1, a1, a2);
        CATISpecObject_var arc2 = spWF2DFactOnSketch->CreateCircle(cp, r2, a1, a2);

        double pt1[2] = { r1 * std::cos(a1), r1 * std::sin(a1) },
            pt2[2] = { r2 * std::cos(a1), r2 * std::sin(a1) },
            pt3[2] = { r1 * std::cos(a2), r1 * std::sin(a2) },
            pt4[2] = { r2 * std::cos(a2), r2 * std::sin(a2) };

        CATISpecObject_var spLine1 = spWF2DFactOnSketch->CreateLine(pt1, pt2);
        CATISpecObject_var spLine2 = spWF2DFactOnSketch->CreateLine(pt3, pt4);

        spSketch->CloseEdition();
        arc1->Update();
        arc2->Update();
        spLine1->Update();
        spLine2->Update();
        // Creates the pad
        // arguments :  a sketch
        //              2 limits
        //              a direction

        double firstLimit = step_h * i - offset_dimension; // First and second limits of the pad
        double secondLimit = -step_h * (i - 1) + offset_dimension;

        CATMathDirection dirZ(0., 0., 1.); // Direction of the pad

        CATISpecObject_var spSpecObj = spPrtFactOnPrtCont->CreatePad(spSketch);
        CATIPad_var spPadOnSpecObj(spSpecObj);
        spPadOnSpecObj->ModifyDirection(dirZ);
        spPadOnSpecObj->ModifyEndType(catOffsetLimit);
        spPadOnSpecObj->ModifyEndOffset(firstLimit);
        spPadOnSpecObj->ModifyStartType(catOffsetLimit);
        spPadOnSpecObj->ModifyStartOffset(secondLimit);
        spSpecObj->Update(); // Builds the pad
    }

    CATISketch_var spSketch = spSketchFactOnPrtCont->CreateSketch(spSketchPlane);
    CATI2DWFFactory_var spWF2DFactOnSketch(spSketch);
    double cp[2] = { 0., 0. };
    spSketch->OpenEdition();
    spWF2DFactOnSketch->CreateCircle(cp, r1);
    spWF2DFactOnSketch->CreateCircle(cp, r1 - 2);
    spSketch->CloseEdition();
    CATISpecObject_var spSpecObj = spPrtFactOnPrtCont->CreatePad(spSketch);
    CATMathDirection dirZ(0., 0., 1.); // Direction of the pad
    CATIPad_var spPadOnSpecObj(spSpecObj);
    spPadOnSpecObj->ModifyDirection(dirZ);
    spPadOnSpecObj->ModifyEndType(catOffsetLimit);
    spPadOnSpecObj->ModifyEndOffset(offset_dimension);
    spPadOnSpecObj->ModifyStartType(catOffsetLimit);
    spPadOnSpecObj->ModifyStartOffset(offset_dimension);
    spSpecObj->Update(); // Builds the pad

12 配置代码的依赖项样例,以 CATFrmEditor 为例。需要配置id Card :ApplicationFrame,Imakefile.mk :CATApplicationFrame,以及代码的引入项 #include "CATFrmEditor.h"。





13 参考步骤12,配置代码缺失的依赖项 id Card。



14 参考步骤12,配置代码缺失的依赖项 Imakefile.mk。

15 参考步骤12,配置代码缺失的依赖项 代码的引入项 #include。

16 参考 步骤10到15,配置Cancel 按键触发方法。




17 编译代码,验证配置的正确性。


18 在模块 RM0001.m 上添加新建项





19 配置CustWksAddin.h CustWksAddin.cpp内容,并更新依赖项。



20 配置认证文件
RpCtDmStair\win_b64\code\bin 目录下手动配置下面三个认证文件,这三个认证文件在安装Catia时配置过的。



21 打开 Prompt,并执行CNEXT 命令


22 Catia 窗口操作,画旋转楼梯
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容