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, "程序错误,请检查代码");
}
}

NX二次开发读属性/表达式封装函数的更多相关文章

  1. 【NX二次开发】用户出口函数介绍

    用户出口(User Exit)是NX Open 中的一个重要概念.NX在运行过程中某些特定的位置存在规定的出口,当进程执行到这些出口时,NX会自动检查用户是否在此处已定义了指向内部程序位置的环境变量: ...

  2. NX二次开发-UFUN删除链表函数UF_MODL_delete_list

    NX9+VS2012 #include <uf.h> #include <uf_modl.h> #include <uf_obj.h> #include <u ...

  3. NX二次开发-UFUN输出UF函数使用错误UF_get_fail_message

    #include <uf.h> #include <uf_ui.h> #include <uf_modl.h> UF_initialize(); UF_FEATUR ...

  4. NX二次开发-设置对象名称函数UF_OBJ_set_name

    NX9+VS2012 #include <uf.h> #include <uf_modl.h> #include <uf_obj.h> UF_initialize( ...

  5. NX二次开发-算法篇-vector函数排序(例子:遍历所有点并排序)

    NX9+VS2012 #include <uf.h> #include <uf_ui.h> #include <uf_curve.h> #include <u ...

  6. NX二次开发-UFUN拉伸函数UF_MODL_create_extruded

    NX9+VS2012 //NX二次开发中常用拉伸函数为UF_MODL_create_extruded2,但是此函数不能拉伸片体, //想要拉伸片体用函数UF_MODL_create_extruded. ...

  7. NX二次开发-UFUN拉伸函数UF_MODL_create_extruded2

    NX9+VS2012 //NX二次开发中常用拉伸函数为UF_MODL_create_extruded2,但是此函数不能拉伸片体, //想要拉伸片体用函数UF_MODL_create_extruded. ...

  8. 【NX二次开发】大开眼界,DLL还可以这么调!

    NX二次开发应用程序有交互式.批处理和远程3中模式.交互模式的应用程序(.dll)在NX界面环境下运行.dll以动态链接库的方式被加载到NX的进程空间中.dll可以通过下列几种方式执行. 1.直接激活 ...

  9. NX二次开发-C#使用DllImport调用libufun.dll里的UF函数(反编译.net.dll)调用loop等UF函数

    在写这篇文章的时候,我正在头晕,因为下班坐车回家,有些晕车了.头疼的要死.也吃不下去饭. 版本:NX11+VS2013 最近这一年已经由C++过度到C#,改用C#做应用程序开发和NX二次开发. C#在 ...

  10. NX二次开发-UFUN发射线函数UF_MODL_trace_a_ray的用法

    今天是国庆节,放假休息懒得动,没有出去玩,在家研究一下发射线函数UF_MODL_trace_a_ray.小弟以前在软件公司混的时候,当时我做的那个项目就用到了UF_MODL_trace_a_ray,当 ...

随机推荐

  1. 统计包含关键字的 Key 的数量

  2. pgsql临时表

    with ete as ( SELECT * from table_name ) SELECT * from ete

  3. C#定时任务(Timer)

    新建Timer类 using BaseAsset.Data.Infrastructure; using BaseAsset.Data.Repositories; using BaseAsset.Ent ...

  4. CCF 202012-2 期末预测之最佳阈值

    #include <iostream> #include <bits/stdc++.h> #include <string> using namespace std ...

  5. 定长线程池Demo

    1 import java.util.concurrent.ExecutorService; 2 import java.util.concurrent.Executors; 3 4 /** 5 * ...

  6. Java基础|02.方法的传递机制

    Java基础|02.方法传参机制 0x00 前言 Parameter:参数 java中只有传值,因为地址值也是值 0x01 基础数据类型的传参机制 基本数据类型的值传递,不改变原值.因为调用后会弹栈, ...

  7. jmeter 压测的执行步骤步骤

    一.设置测试参数 如图 Number of Threads:总共起多少个线程. Ramp-UP Period(in seconds):多少秒启动完所有线程. loop Count:循环次数 Sched ...

  8. 字符串转换为Base64,作为token 传入到后台

    一.Base64 转换的方法 function Base64() { // private property _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabc ...

  9. Flink状态后端的对比及机制

    1. Flink状态后端的类型: MemoryStateBackend FsStateBackend RocksDBStateBackend 2. 各状态后端对比: 2.1 MemoryStateBa ...

  10. OO课程第二阶段(实验和期中试题)总结Blog2

    OO课程第二阶段(实验和期中试题)总结Blog2 前言:学习OOP课程的第二阶段已经结束了,在此进行对于知识点,题量,难度的个人看法. 学习OOP课程的第二阶段已经结束了,较第一次阶段学习难度加大,学 ...