• NX二次开发读属性/表达式封装函数


    int Read_ATTR_Type(int ObjTag, char* Attr_Title); //读取属性返回属性类型
    string Read_ATTR_StringValue(int ObjTag, char* Attr_Title);//读取属性返回属性字符串值
    string Read_PartExprDoubleValue(int ComponentTag, char * Expressions_Title); //遍历部件获取表达式值 Double型
    string Read_PartExprIntValue(int ComponentTag, char* Expressions_Title); //遍历部件获取表达式值 Int型


    int YN_BOM::Read_ATTR_Type(int ObjTag, char * Attr_Title) //读取属性返回属性类型
    {
    try
    {
    UF_initialize();
    UF_ATTR_value_t Attr_Value;//定义结构体
    Attr_Value.value.string = new char[UF_ATTR_MAX_STRING_LEN + 1];
    UF_ATTR_read_value(ObjTag, Attr_Title, UF_ATTR_string, &Attr_Value);//获取属性
    int TypeResults = Attr_Value.type;

    return TypeResults;

    //释放内存
    delete Attr_Value.value.string;
    UF_terminate();
    }
    catch (exception& ex)
    {
    //---- Enter your exception handling code here -----
    YN_BOM::theUI->NXMessageBox()->Show("属性类型", NXOpen::NXMessageBox::DialogTypeError, "程序错误,请检查代码");
    }
    }

    string YN_BOM::Read_ATTR_StringValue(int ObjTag, char* Attr_Title) //读取属性返回属性字符串值
    {
    try
    {
    UF_initialize();
    UF_ATTR_value_t Attr_Value;//定义结构体
    Attr_Value.value.string = new char[UF_ATTR_MAX_STRING_LEN + 1];
    UF_ATTR_read_value(ObjTag, Attr_Title, UF_ATTR_string, &Attr_Value);//获取属性
    string StringValeResults = Attr_Value.value.string;

    return StringValeResults;

    //释放内存
    delete Attr_Value.value.string;
    UF_terminate();
    }
    catch (exception& ex)
    {
    //---- Enter your exception handling code here -----
    YN_BOM::theUI->NXMessageBox()->Show("属性字符串值", NXOpen::NXMessageBox::DialogTypeError, "程序错误,请检查代码");
    }
    }
    string YN_BOM::Read_PartExprDoubleValue(int ComponentTag , char* Expressions_Title) //遍历部件获取表达式值 Double型
    {
    try
    {
    Assemblies::Component* component = dynamic_cast<NXOpen::Assemblies::Component*>(NXObjectManager::Get(ComponentTag));//获取Component
    NXOpen::Part* ThePart = dynamic_cast<Part*>(component->Prototype()); //component强制转换为part
    //遍历表达式
    std::vector<Expression*> PartExprs = ThePart->Expressions()->GetVisibleExpressions();
    Expression* PartExpression;

    char PartExpCharValue[256];
    string PartExpStrValue;

    for (int i = 0 ; i < PartExprs.size(); i++)
    {
    PartExpression = dynamic_cast<Expression*>(PartExprs[i]);
    NXString PartExpressionName = PartExpression->Name();
    double PartExpressionValue = PartExpression->Value();
    if (strcmp(PartExpressionName.GetLocaleText(), Expressions_Title) == 0)
    {
    sprintf(PartExpCharValue, "%.2f", PartExpressionValue);
    }
    }
    PartExpStrValue = PartExpCharValue;
    //theSession->ListingWindow()->WriteLine(component->DisplayName()+"表达式:" + Expressions_Title +"值=" + PartExpStrValue );
    return PartExpStrValue;
    }
    catch (exception& ex)
    {
    //---- Enter your exception handling code here -----
    YN_BOM::theUI->NXMessageBox()->Show("获取表达式Double值", NXOpen::NXMessageBox::DialogTypeError, "程序错误,请检查代码");
    }
    }

    string YN_BOM::Read_PartExprIntValue(int ComponentTag, char* Expressions_Title) //遍历部件获取表达式值 Int型
    {
    try
    {
    Assemblies::Component* component = dynamic_cast<NXOpen::Assemblies::Component*>(NXObjectManager::Get(ComponentTag));//获取Component
    NXOpen::Part* ThePart = dynamic_cast<Part*>(component->Prototype()); //component强制转换为part
    //遍历表达式
    std::vector<Expression*> PartExprs = ThePart->Expressions()->GetVisibleExpressions();
    Expression* PartExpression;

    char PartExpCharValue[256];
    string PartExpStrValue;

    for (int i = 0; i < PartExprs.size(); i++)
    {
    PartExpression = dynamic_cast<Expression*>(PartExprs[i]);
    NXString PartExpressionName = PartExpression->Name();
    int PartExpressionValue = PartExpression->Value();
    if (strcmp(PartExpressionName.GetLocaleText(), Expressions_Title) == 0)
    {
    sprintf(PartExpCharValue, "%d", PartExpressionValue);
    //theSession->ListingWindow()->WriteLine(component->DisplayName() + "表达式:" + Expressions_Title + "值=" + PartExpCharValue);
    }
    }
    PartExpStrValue = PartExpCharValue;

    return PartExpStrValue;
    }
    catch (exception& ex)
    {
    //---- Enter your exception handling code here -----
    YN_BOM::theUI->NXMessageBox()->Show("获取表达式Int值", NXOpen::NXMessageBox::DialogTypeError, "程序错误,请检查代码");
    }
    }

    怡宁塑胶模具设计
  • 相关阅读:
    Python冒泡算法和修改配置文件
    第五章:处理数据
    第四章:持久存储
    Python之打印99乘法表
    Python之编写登录接口
    Python之文件操作
    第三章:文件与异常
    FineUI 修改config表属性
    FineUI Grid中WindowField根据列数据决定是否Enalble
    表之间不同字段的数据复制
  • 原文地址:https://www.cnblogs.com/hqsalanhuang/p/14993889.html
Copyright © 2020-2023  润新知