• NX二次开发-NX11创建表达式组NXOpen::ExpressionGroup


      1 NX11+VS2013
      2 
      3 #include <uf.h>
      4 #include <uf_modl.h>
      5 #include <uf_part.h>
      6 #include <uf_ui.h>
      7 #include <NXOpen/ExpressionGroup.hxx>
      8 #include <NXOpen/ExpressionGroupCollection.hxx>
      9 #include <NXOpen/NXObjectManager.hxx>
     10 #include <NXOpen/Unit.hxx>
     11 #include <NXOpen/UnitCollection.hxx>
     12 #include <NXOpen/Update.hxx>
     13 #include <uf_group.h>
     14 
     15 
     16 UF_initialize();
     17 
     18 int number_of_exps = 0;
     19 tag_t * expsTag = NULL_TAG;
     20 UF_MODL_ask_exps_of_part(UF_PART_ask_display_part(), &number_of_exps, &expsTag);
     21 
     22 if (number_of_exps == 0)
     23 {
     24     //创建表达式
     25     tag_t DCTag = NULL_TAG;
     26     UF_MODL_create_exp_tag("DC=20", &DCTag);
     27     NXOpen::Expression *expressionDC(dynamic_cast<NXOpen::Expression *>(NXOpen::NXObjectManager::Get(DCTag)));
     28     expressionDC->EditComment("工作直径");
     29 
     30     tag_t DMMTag = NULL_TAG;
     31     UF_MODL_create_exp_tag("DMM=20", &DMMTag);
     32     NXOpen::Expression *expressionDMM(dynamic_cast<NXOpen::Expression *>(NXOpen::NXObjectManager::Get(DMMTag)));
     33     expressionDMM->EditComment("柄部直径");
     34 
     35     tag_t DNTag = NULL_TAG;
     36     UF_MODL_create_exp_tag("DN=19", &DNTag);
     37     NXOpen::Expression *expressionDN(dynamic_cast<NXOpen::Expression *>(NXOpen::NXObjectManager::Get(DNTag)));
     38     expressionDN->EditComment("颈部直径");
     39 
     40     tag_t OALTag = NULL_TAG;
     41     UF_MODL_create_exp_tag("OAL=100", &OALTag);
     42     NXOpen::Expression *expressionOAL(dynamic_cast<NXOpen::Expression *>(NXOpen::NXObjectManager::Get(OALTag)));
     43     expressionOAL->EditComment("刀具总长");
     44 
     45     tag_t LFTag = NULL_TAG;
     46     UF_MODL_create_exp_tag("LF=100", &LFTag);
     47     NXOpen::Expression *expressionLF(dynamic_cast<NXOpen::Expression *>(NXOpen::NXObjectManager::Get(LFTag)));
     48     expressionLF->EditComment("刀具高度");
     49 
     50     tag_t LUTag = NULL_TAG;
     51     UF_MODL_create_exp_tag("LU=30", &LUTag);
     52     NXOpen::Expression *expressionLU(dynamic_cast<NXOpen::Expression *>(NXOpen::NXObjectManager::Get(LUTag)));
     53     expressionLU->EditComment("工作长度");
     54 
     55     tag_t LCFTag = NULL_TAG;
     56     UF_MODL_create_exp_tag("LCF=40", &LCFTag);
     57     NXOpen::Expression *expressionLCF(dynamic_cast<NXOpen::Expression *>(NXOpen::NXObjectManager::Get(LCFTag)));
     58     expressionLCF->EditComment("槽长");
     59 
     60     tag_t SGATag = NULL_TAG;
     61     UF_MODL_create_exp_tag("SGA=120", &SGATag);
     62     NXOpen::Expression *expressionSGA(dynamic_cast<NXOpen::Expression *>(NXOpen::NXObjectManager::Get(SGATag)));
     63     expressionSGA->EditComment("角度");
     64 
     65     tag_t WFTag = NULL_TAG;
     66     UF_MODL_create_exp_tag("WF=20", &WFTag);
     67     NXOpen::Expression *expressionWF(dynamic_cast<NXOpen::Expression *>(NXOpen::NXObjectManager::Get(WFTag)));
     68     expressionWF->EditComment("工作宽度");
     69 
     70     tag_t CDXITag = NULL_TAG;
     71     UF_MODL_create_exp_tag("CDXI=10", &CDXITag);
     72     NXOpen::Expression *expressionCDXI(dynamic_cast<NXOpen::Expression *>(NXOpen::NXObjectManager::Get(CDXITag)));
     73     expressionCDXI->EditComment("切削长度");
     74 
     75     tag_t CWTag = NULL_TAG;
     76     UF_MODL_create_exp_tag("CW=3", &CWTag);
     77     NXOpen::Expression *expressionCW(dynamic_cast<NXOpen::Expression *>(NXOpen::NXObjectManager::Get(CWTag)));
     78     expressionCW->EditComment("切削宽度");
     79 
     80     //添加到vector
     81     std::vector<NXOpen::Expression*> Exp1;
     82     Exp1.push_back(expressionDC);
     83     Exp1.push_back(expressionDMM);
     84     Exp1.push_back(expressionDN);
     85     Exp1.push_back(expressionOAL);
     86     Exp1.push_back(expressionLF);
     87     Exp1.push_back(expressionLU);
     88     Exp1.push_back(expressionLCF);
     89     Exp1.push_back(expressionSGA);
     90     Exp1.push_back(expressionWF);
     91     Exp1.push_back(expressionCDXI);
     92     Exp1.push_back(expressionCW);
     93 
     94     //创建表达式组
     95     NXOpen::ExpressionGroup *expressionGroup1;
     96     expressionGroup1 = workPart->ExpressionGroups()->Create("刀杆参数");
     97     expressionGroup1->SetExpressions(Exp1);
     98 
     99 
    100     //创建表达式
    101     NXOpen::Expression *expressiondp_scpe;
    102     expressiondp_scpe = workPart->Expressions()->CreateExpression("String", "dp_scpe="A"");
    103     expressiondp_scpe->EditComment("刀片规格");
    104 
    105     tag_t W1Tag = NULL_TAG;
    106     UF_MODL_create_exp_tag("W1=0", &W1Tag);
    107     NXOpen::Expression *expressionW1(dynamic_cast<NXOpen::Expression *>(NXOpen::NXObjectManager::Get(W1Tag)));
    108     expressionW1->EditComment("刀片内切圆");
    109 
    110     tag_t S1Tag = NULL_TAG;
    111     UF_MODL_create_exp_tag("S1=0", &S1Tag);
    112     NXOpen::Expression *expressionS1(dynamic_cast<NXOpen::Expression *>(NXOpen::NXObjectManager::Get(S1Tag)));
    113     expressionS1->EditComment("刀片厚度");
    114 
    115     //添加到vector
    116     std::vector<NXOpen::Expression*> Exp2;
    117     Exp2.push_back(expressionW1);
    118     Exp2.push_back(expressionS1);
    119     Exp2.push_back(expressiondp_scpe);
    120 
    121 
    122     //创建表达式组
    123     NXOpen::ExpressionGroup *expressionGroup2;
    124     expressionGroup2 = workPart->ExpressionGroups()->Create("刀片参数");
    125     expressionGroup2->SetExpressions(Exp2);
    126 
    127 
    128     //创建表达式
    129     tag_t A1Tag = NULL_TAG;
    130     UF_MODL_create_exp_tag("A1=SIN(30)", &A1Tag);
    131     NXOpen::Expression *expressionA1(dynamic_cast<NXOpen::Expression *>(NXOpen::NXObjectManager::Get(A1Tag)));
    132 
    133     tag_t A2Tag = NULL_TAG;
    134     UF_MODL_create_exp_tag("A2=COS(30)", &A2Tag);
    135     NXOpen::Expression *expressionA2(dynamic_cast<NXOpen::Expression *>(NXOpen::NXObjectManager::Get(A2Tag)));
    136 
    137     tag_t A3Tag = NULL_TAG;
    138     UF_MODL_create_exp_tag("A3=TAN(30)", &A3Tag);
    139     NXOpen::Expression *expressionA3(dynamic_cast<NXOpen::Expression *>(NXOpen::NXObjectManager::Get(A3Tag)));
    140 
    141     //添加到vector
    142     std::vector<NXOpen::Expression*> Exp3;
    143     Exp3.push_back(expressionA1);
    144     Exp3.push_back(expressionA2);
    145     Exp3.push_back(expressionA3);
    146 
    147     //创建表达式组
    148     NXOpen::ExpressionGroup *expressionGroup3;
    149     expressionGroup3 = workPart->ExpressionGroups()->Create("计算参数");
    150     expressionGroup3->SetExpressions(Exp3);
    151 
    152 
    153     //创建表达式
    154     NXOpen::Expression *expressionh_type;
    155     expressionh_type = workPart->Expressions()->CreateExpression("String", "h_type="weldon"");
    156     expressionh_type->EditComment("柄部规格");
    157 
    158     NXOpen::Unit *nullNXOpen_Unit(NULL);
    159     NXOpen::Expression *expressionA4;
    160     expressionA4 = workPart->Expressions()->CreateWithUnits("A4=if(h_type=="weldon") 1 else 0", nullNXOpen_Unit);
    161 
    162 
    163     //添加到vector
    164     std::vector<NXOpen::Expression*> Exp4;
    165     Exp4.push_back(expressionh_type);
    166     Exp4.push_back(expressionA4);
    167 
    168     NXOpen::ExpressionGroup *expressionGroup4;
    169     expressionGroup4 = workPart->ExpressionGroups()->Create("表达式抑制");
    170     expressionGroup4->SetExpressions(Exp4);        
    171 
    172 }
    173 
    174 else
    175 {
    176     uc1601("当前part已存在表达式,此命令不能使用", 1);
    177 }
    178 
    179 UF_free(expsTag);
    180 
    181 UF_terminate();

  • 相关阅读:
    存储过程使用:
    java map,set,list
    Jbox帮助文档,默认的属性含义
    checkboxlist的说明及使用
    java中两种select方式,,一种从数据表中读取
    IE6下<a href="#">与<a href="javascript:void(0);">的区别
    用javascript如何在框架间传值
    a href=#与 a href=javascript:void(0) 的区别
    关于如何导入GPUImage
    GPUImage实现过程
  • 原文地址:https://www.cnblogs.com/nxopen2018/p/10981676.html
Copyright © 2020-2023  润新知