zoukankan      html  css  js  c++  java
  • NXOpen 遍历部件并对每个部件加属性

    // Mandatory UF Includes
    #include <uf.h>
    #include <uf_object_types.h>

    // Internal Includes
    #include <NXOpen/ListingWindow.hxx>
    #include <NXOpen/NXMessageBox.hxx>
    #include <NXOpen/UI.hxx>

    // Internal+External Includes
    #include <NXOpen/Annotations.hxx>
    #include <NXOpen/Assemblies_Component.hxx>
    #include <NXOpen/Assemblies_ComponentAssembly.hxx>
    #include <NXOpen/Body.hxx>
    #include <NXOpen/BodyCollection.hxx>
    #include <NXOpen/Face.hxx>
    #include <NXOpen/Line.hxx>
    #include <NXOpen/NXException.hxx>
    #include <NXOpen/NXObject.hxx>
    #include <NXOpen/Part.hxx>
    #include <NXOpen/PartCollection.hxx>
    #include <NXOpen/Session.hxx>

    #include <NXOpen/BasePart.hxx>

    #include <NXOpen/AttributeManager.hxx>
    #include <NXOpen/AttributePropertiesBaseBuilder.hxx>
    #include <NXOpen/AttributePropertiesBuilder.hxx>

    //用户代码

    void MyClass::do_it()
    {

    Session *theSession = Session::GetSession();//获取绘画客口

    BasePart *basedisplaypart = theSession->Parts()->BaseDisplay();//定义basedisplaypart

    //遍历实例
    Assemblies::ComponentAssembly *componentassembly = basedisplaypart->ComponentAssembly();//获取装配底层(BaseWork为当前工作装配,basedisplaypart为当前显示的装配 两种结果是不一样的)
    Assemblies::Component *rootcomponent = componentassembly->RootComponent();//获取rootcomponent

    if (rootcomponent==NULL)//判断rootcomponent是否为空,空即提示不是装配,是就执行遍历
    {
    //弹出消息框(四种消息框 错误:DialogTypeError 警告:DialogTypeWarning 提示:DialogTypeInformation 询问:DialogTypeQuestion
    theUI->NXMessageBox()->Show("提示", NXOpen::NXMessageBox::DialogTypeWarning, "当前没在装配环境!"); //弹出消息框提示
    }
    else//
    {
    //theSession->ListingWindow()->WriteLine(rootcomponent->DisplayName()+" ");//信息窗口写入主装配 名字

    getchildren(rootcomponent);

    }

    }


    void MyClass::getchildren(Assemblies::Component *root)
    {

    //用户代码
    std::vector<Assemblies::Component *> children = root->GetChildren();//获取第一层Component

    for (int i = 0 ; i<children.size();i++)

    {
    Assemblies::Component *component = children[i];//获取第一层第i个Component

    //判断部件加载状态
    bool isloading = true;
    Part *resCurrentProtype = dynamic_cast<Part *>(children[i]->Prototype());

    if(resCurrentProtype == NULL)
    {
    isloading = false;// 不加载为false 全加载和部份加载为true
    }
    //遍历表达式
    if ( isloading == true )
    {

    //NXOpen对部件加属性
    std::vector<NXObject *> objects1(1);
    objects1[0] = resCurrentProtype;
    AttributePropertiesBuilder *attributePropertiesBuilder1;
    attributePropertiesBuilder1 = theSession->AttributeManager()->CreateAttributePropertiesBuilder(workPart, objects1, AttributePropertiesBuilder::OperationTypeNone);
    attributePropertiesBuilder1->SetTitle("PartNo");
    attributePropertiesBuilder1->SetStringValue("1-001");

    NXObject *nXObject1;
    nXObject1 = attributePropertiesBuilder1->Commit();

    attributePropertiesBuilder1->SetTitle("PartName");
    attributePropertiesBuilder1->SetStringValue("后模仁");

    NXObject *nXObject2;
    nXObject2 = attributePropertiesBuilder1->Commit();

    attributePropertiesBuilder1->Destroy();

    }

    getchildren(component);

    }

    }

    怡宁塑胶模具设计
  • 相关阅读:
    js中验证身份证号码是否正确支持15位和18位身份证号
    vue-element-admin-i18n 前端框架的使用
    根据年份选择周数-js
    js 计算开始日期和结束日期跨度几个月份的方法
    Java上传图片到服务器
    c# List<Object>和List<实体>相互转化
    GC 相关详细参数
    Groovy脚本和Groovy类反编译文件
    dev 控件中点击TreeList节点高亮显示GridControl中存在的行
    spring容器
  • 原文地址:https://www.cnblogs.com/hqsalanhuang/p/14310160.html
Copyright © 2011-2022 走看看