zoukankan      html  css  js  c++  java
  • NXOpen 遍历部件的Number表达式 根据表达式名过虑得到对应的值

    // 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/Expression.hxx>
    #include <NXOpen/ExpressionCollection.hxx>

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

    //用户代码

    void MyClass::do_it()
    {

    theSession->ListingWindow()->Open();//打开信息窗口

    Session *theSession = Session::GetSession();//获取绘画客口
    Part *workPart(theSession->Parts()->Work());//获取工作部件
    Part *displayPart(theSession->Parts()->Display());//获取显示部件

    //BasePart *baseworkpart = theSession->Parts()->BaseWork();//定义baseworkpart
    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

    //表达式相关的定义
    std::vector<NXString> expression1NameNXString1 ;
    std::vector<int> expression1Value1;
    const char* expression1Name;
    char expression1Value2[256];

    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::Part *part2 = dynamic_cast<Part *>(children[i]->Prototype()); //component强制转换为part
    std::vector<Expression *> exprs = part2->Expressions()->GetVisibleExpressions();
    Expression *expression1;

    for (size_t k = 0; k < exprs.size(); k++)
    {
    expression1 = dynamic_cast<Expression *>(exprs[k]);
    expression1NameNXString1.push_back(expression1->Name());
    expression1Value1.push_back(expression1->Value());
    expression1Name = expression1NameNXString1[k].GetLocaleText();
    if (!strcmp(expression1Name ,"SCREW_DIA") )
    {
    sprintf (expression1Value2,"%d",expression1Value1[k]);
    theSession->ListingWindow()->WriteLine(children[i]->DisplayName()+"表达式:"+expression1NameNXString1[k]+"="+expression1Value2);

    }

    }
    }

    getchildren(component);

    }

    }

    怡宁塑胶模具设计
  • 相关阅读:
    时间差的计算
    时间差的计算第二篇
    并不能完全不编码完成Windows Service的安装和卸载
    今年是搜索引擎年吗?热!搜索引擎算法点击率火爆
    Virtual PC,我真的不敢用你!
    我理解的17种C#写的Hello World程序
    反搜索引擎
    如何保证Windows Serverice健壮长效运转?
    服务器是怎么做成的?
    超酷的超级DataGrid
  • 原文地址:https://www.cnblogs.com/hqsalanhuang/p/14310029.html
Copyright © 2011-2022 走看看