zoukankan      html  css  js  c++  java
  • NXOpen 工作部件创建引用集

    C++

    //用户头文件
    #include <NXOpen/ListingWindow.hxx> //打印信息
    #include <NXOpen/NXException.hxx> //异常处理
    #include <NXOpen/BasePart.hxx>
    #include <NXOpen/Body.hxx>
    #include <NXOpen/BodyCollection.hxx>
    #include <NXOpen/INXObject.hxx>
    #include <NXOpen/NXObject.hxx>
    #include <NXOpen/Part.hxx>
    #include <NXOpen/PartCollection.hxx>
    #include <NXOpen/ReferenceSet.hxx>
    #include <NXOpen/NXObjectManager.hxx>
    #include <NXOpen/Update.hxx>
    #include <uf_ui.h>
    #include <uf.h>
    #include <uf_obj.h>
    #include <uf_assem.h>

    //设置过虑(注释处改动即可使用)
    Selection::SelectionAction action = Selection::SelectionActionClearAndEnableSpecific;
    std::vector<Selection::MaskTriple> maskArray(1);
    maskArray[0] = Selection::MaskTriple( UF_solid_type, UF_solid_body_subtype/*此处控制选择的类型,右键点转到定义查开类型*/, UF_UI_SEL_FEATURE_SOLID_BODY /*此处控制选择的类型,在头文件uf_ui_types.可以查到*/ ); // Bodies
    selection0/*此处blockID需按实际改*/->GetProperties()->SetSelectionFilter("SelectionFilter",action,maskArray);

    theDialog->TopBlock()->FindBlock("Dialog")->GetProperties()->SetString("Label","引用集 制作:Alan Huang QQ:185266370");//对话框标题设置
    button0->GetProperties()->SetString("Label","制作:Alan Huang QQ:185266370"); //修改按钮显示的内容
    //枚举值获取
    PropertyList *enum0Props = enum0->GetProperties();
    int EnumValue = enum0Props->GetEnum("Value");
    delete enum0Props;
    enum0Props = NULL;

    //设置枚举默认值
    enum0->GetProperties()->SetEnum("Value", 0 );

    //从选择UI中获取所选对象的标记
    std::vector<NXOpen::TaggedObject *>CreateReferenceSet::GetSelectedObjects()
    {
    std::vector<NXOpen::TaggedObject *>SelectObjectTags ;
    try
    {
    NXOpen::BlockStyler::PropertyList *selection0Props =selection0->GetProperties();
    SelectObjectTags = selection0Props->GetTaggedObjectVector("SelectedObjects");
    delete selection0Props;
    selection0Props = NULL;

    }
    catch(exception& ex)
    {
    CreateReferenceSet::theUI->NXMessageBox()->Show("从选择对象块中获取所选对象的标记", NXOpen::NXMessageBox::DialogTypeError, "程序错误,请检查代码");
    }
    return SelectObjectTags;
    }

    //创建引用集和把对象加到引用集
    void CreateReferenceSet::CreateReferenceSetNew()
    {

    try
    {
    UF_initialize();

    Part *workPart = theSession->Parts()->Work();//获取工作部件

    char msg[256];
    theSession->ListingWindow()->Open();//打开信息窗口

    //获取工作部件引用集
    tag_t refObjTAG = NULL_TAG;
    char ref_set_name [ MAX_ENTITY_NAME_SIZE+1 ];
    double origin1 [ 3 ];
    double matrix [ 9 ];
    int num_members;
    tag_t * members ;

    tag_t TRUE_id =NULL_TAG;
    tag_t FALSE_id =NULL_TAG;

    bool TRUEref_State = false ;
    bool FALSEref_State = false ;

    UF_OBJ_cycle_objs_in_part( workPart->Tag(), UF_reference_set_type, &refObjTAG );//按引用集类型遍历

    //遍历引用集
    while ( refObjTAG != NULL_TAG )
    {
    UF_ASSEM_ask_ref_set_data( refObjTAG, ref_set_name, origin1, matrix, &num_members, &members );
    //theSession->ListingWindow()->WriteLine(ref_set_name);
    if ( strcmp( ref_set_name, "TRUE" ) == 0 ) //如果返回值 < 0,则表示 str1 小于 str2 ,如果返回值 > 0,则表示 str2 小于 str1,如果返回值 = 0,则表示 str1 等于 str2
    {
    //TRUE_id == refObjTAG ;
    TRUEref_State = true ;
    //theUI->NXMessageBox()->Show("提示", NXOpen::NXMessageBox::DialogTypeWarning, "TRUE引用集已经有");
    }

    if ( strcmp( ref_set_name, "FALSE" ) == 0 ) //如果返回值 < 0,则表示 str1 小于 str2 ,如果返回值 > 0,则表示 str2 小于 str1,如果返回值 = 0,则表示 str1 等于 str2
    {
    //FALSE_id == refObjTAG ;
    FALSEref_State = true ;
    //theUI->NXMessageBox()->Show("提示", NXOpen::NXMessageBox::DialogTypeWarning, "FALSE引用集已经有");
    }

    UF_free( members );
    UF_OBJ_cycle_objs_in_part( workPart->Tag(), UF_reference_set_type, &refObjTAG );

    }

    //获取选择对象
    std::vector<NXOpen::TaggedObject *>selObjectData = GetSelectedObjects();

    //枚举值获取
    PropertyList *enum0Props = enum0->GetProperties();
    int EnumValue = enum0Props->GetEnum("Value");
    delete enum0Props;
    enum0Props = NULL;
    if ( EnumValue == 0 )
    {
    //如明没有TRUE引用集就创建
    if ( TRUEref_State == false )
    {
    ReferenceSet *referenceSet1;
    referenceSet1 = workPart->CreateReferenceSet();
    for ( int i = 0 ;i < selObjectData.size() ; i++)
    {
    std::vector<NXObject *> components1(1);
    Body *body1(dynamic_cast<Body *>(NXObjectManager::Get(selObjectData[i]->Tag()))); //选择的目标转换body
    components1[0] = body1;
    referenceSet1->AddObjectsToReferenceSet(components1);
    }

    referenceSet1->SetName("TRUE");

    }
    else if ( TRUEref_State == true )
    {
    //加对象到引用集

    }

    else if ( EnumValue == 1 )
    {
    //如明没有FALSE引用集就创建
    if ( FALSEref_State == false )
    {
    ReferenceSet *referenceSet2;
    referenceSet2 = workPart->CreateReferenceSet();

    for ( int i = 0 ;i < selObjectData.size() ; i++)
    {
    std::vector<NXObject *> components1(1);
    Body *body1(dynamic_cast<Body *>(NXObjectManager::Get(selObjectData[i]->Tag()))); //选择的目标转换body
    components1[0] = body1;
    referenceSet2->AddObjectsToReferenceSet(components1);
    }

    referenceSet2->SetName("FALSE");
    }
    else if ( FALSEref_State == true )
    {

    //加对象到引用集

    }


    UF_terminate();

    }
    catch(exception& ex)
    {
    CreateReferenceSet::theUI->NXMessageBox()->Show("创建引用集和把对象加到引用集", NXOpen::NXMessageBox::DialogTypeError, "程序错误,请检查代码");
    }

    }

    怡宁塑胶模具设计
  • 相关阅读:
    最受欢迎的ASP.NET的CMS下载
    asp.net开源CMS推荐
    Oracle分组小计、总计示例(grouping sets的使用)
    PLSQL登录的时候Warning提示:Using a filter for all users can lead to poor performance!
    hibernate saveorupdate方法只有更新有效果,保存没有效果
    Hibernate的generator属性
    在oracle中存入date类型数据遇到的问题及其解决方法(利用java.sql.date和Timestamp)
    Hibernate更新、删除后数据库无变化
    Oracle执行update时卡死问题的解决方法
    Hibernate
  • 原文地址:https://www.cnblogs.com/hqsalanhuang/p/14314718.html
Copyright © 2011-2022 走看看