一、NXOpen的对象,如何转化成UFU对象
一般新手只会抄袭代码,并不知道代码具体含义,现在将自己在开发中的问题进行说明,网上大都以块为例子,现在以圆柱和球体进行说明。
通过一个示例进行演示:
1、利用NXOpen的函数创建一个圆柱或者球体(NXOpenC++)
2、将整个圆柱或者球体进行染色(利用UFUN的方法)
以上会将NXObject转化为BodyFeature,如果直接用NXObject染色无效(个人人为染色主要是对体进行染色)
//将NXObject转化为BodyFeature
NXOpen::Features::BodyFeature *thebodys = dynamic_cast<NXOpen::Features::BodyFeature *>(nXObject1);
详细代码如下,参考上一篇NX二次开发openC++(二)——NxOpenC++对象与UFUN对象之间的转化(以圆柱和球体为例子)-CSDN博客
//NXOPEN绘制球体——>UFUN上色
NXOpen::Features::Sphere *nullNXOpen_Features_Sphere(NULL);
NXOpen::Features::SphereBuilder *sphereBuilder1;
sphereBuilder1 = workPart->Features()->CreateSphereBuilder(nullNXOpen_Features_Sphere);
sphereBuilder1->Diameter()->SetRightHandSide("100");
NXOpen::Unit *unit1;
unit1 = sphereBuilder1->Diameter()->Units();
NXOpen::Expression *expression1;
expression1 = workPart->Expressions()->CreateSystemExpressionWithUnits("0", unit1);
NXOpen::NXObject *nXObject1;
nXObject1 = sphereBuilder1->Commit();
NXOpen::Expression *expression2(sphereBuilder1->Diameter());
//将NXObject转化为BodyFeature
NXOpen::Features::BodyFeature *thebodys = dynamic_cast<NXOpen::Features::BodyFeature *>(nXObject1);
tag_t object_tag = NULL_TAG;
UF_MODL_ask_feat_body(thebodys->Tag(), &object_tag);
UF_OBJ_set_color(object_tag, 186);
sphereBuilder1->Destroy();
workPart->Expressions()->Delete(expression1);
运行结果如下: