zoukankan      html  css  js  c++  java
  • NXOpen 遍历部件

    C++

    #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>

    void MyClass::do_it()
    {

    // TODO: add your code here

    //用户代码

    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
    for (int i = 0 ; i<children.size();i++)

    {
    Assemblies::Component *component = children[i];//获取第一层第i个Component
    theSession->ListingWindow()->WriteLine(component->DisplayName()+" ");//信息窗口写入Component 名字

    getchildren(component);

    }

    }

     

    //获取部件加载状态


    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
    //判断部件加载状态
    Part *part = dynamic_cast<Part *>(component->Prototype()); //component强制转换为part
    if (part == NULL)
    {

    //没加载
    theSession->ListingWindow()->WriteLine(component->DisplayName() + " " + "加载状态:没加载" + " ");//信息窗口写入Component 名字
    }
    else
    {
    if(part->IsFullyLoaded())
    {
    //已加载
    theSession->ListingWindow()->WriteLine(component->DisplayName() + " " + "加载状态:已加载" + " ");//信息窗口写入Component 名字
    }
    else
    {
    //部份加载
    theSession->ListingWindow()->WriteLine(component->DisplayName() + " " + "加载状态:部份加载" + " ");//信息窗口写入Component 名字
    }

    }

    getchildren(component);

    }

    }

    怡宁塑胶模具设计
  • 相关阅读:
    BZOJ 2574: [Poi1999]Store-Keeper
    BZOJ 1024: [SCOI2009]生日快乐
    BZOJ 2541: [Ctsc2000]冰原探险
    hihoCoder 1303 数论六·模线性方程组
    Codeforces 710 D. Two Arithmetic Progressions
    BZOJ 1670: [Usaco2006 Oct]Building the Moat护城河的挖掘
    ZJOI2014 2048
    51Nod 1766 树上的最远点对
    Codeforces 727 F. Polycarp's problems
    BZOJ 3736: [Pa2013]Karty
  • 原文地址:https://www.cnblogs.com/hqsalanhuang/p/14224272.html
Copyright © 2011-2022 走看看