NX二次开发-UFUN和NXOpen结合开发中Tag_t对象与TaggedObject对象转换方法

文章详细介绍了在NX二次开发中如何运用UFUN和NXOpen进行块创建、体查找和颜色设置的四个示例,涉及TaggedObject与tag_t对象转换以及特定函数如FeatureCollection和BlockFeatureBuilder的使用。
摘要由CSDN通过智能技术生成
本文通过举四个例子来告诉大家在NX二次开发过程中会经常用到UFUN和NXOpen结合去开发,在UFUN中我们得到的是Tag_t对象,在NXOpen中得到的是TaggedObject对象,这两个是需要进行转换的。
  本文主要知识点为:TaggedObject->tag_t() , NXOpen::NXObjectManager::Get(BodyTag1) , feature1->JournalIdentifier()的用法。
 
     NX11+VS2013
             
     #include <uf.h>
     #include <uf_modl.h>
     #include <uf_obj.h>
     #include <NXOpen\NXObjectManager.hxx>
     #include <NXOpen/Features_BlockFeatureBuilder.hxx>
     #include <NXOpen/Features_FeatureCollection.hxx>
     #include <NXOpen/NXException.hxx>
     #include <NXOpen/Body.hxx>
     #include <NXOpen/BodyCollection.hxx>
     #include <NXOpen/DisplayManager.hxx>
     #include <NXOpen/PartCollection.hxx>
 
     NXOpen::Session *theSession = NXOpen::Session::GetSession();
     NXOpen::Part *workPart(theSession->Parts()->Work());
     NXOpen::Part *displayPart(theSession->Parts()->Display());
 
     UF_initialize();
     
     //方法1:UFUN方式创建块,设置块颜色。
     //UFUN方式创建块
     UF_FEATURE_SIGN Sign = UF_NULLSIGN;
     double Corner_pt[3] = { 0.0, 0.0, 0.0 };
     char *Edge_len[3] = { "100", "100", "100" };
     tag_t BlkTag = NULL_TAG;
     UF_MODL_create_block1(Sign, Corner_pt, Edge_len, &BlkTag);
 
     //UFUN方式特征找体
     tag_t BodyTag = NULL_TAG;
     UF_MODL_ask_feat_body(BlkTag, &BodyTag);
 
     //UFUN方式设置颜色
     UF_OBJ_set_color(BodyTag, 186);
 
 
 
 
 
     //方法2:NXOpen方式创建块,设置块颜色。
     //NXOpen方式创建块
     NXOpen::Features::Feature *nullNXOpen_Features_Feature(NULL);
     NXOpen::Features::BlockFeatureBuilder *blockFeatureBuilder1;
     blockFeatureBuilder1 = workPart->Features()->CreateBlockFeatureBuilder(nullNXOpen_Features_Feature);
 
     std::vector<NXOpen::Body *> targetBodies1(1);
     NXOpen::Body *nullNXOpen_Body(NULL);
     targetBodies1[0] = nullNXOpen_Body;
     blockFeatureBuilder1->BooleanOption()->SetTargetBodies(targetBodies1);
 
     blockFeatureBuilder1->SetType(NXOpen::Features::BlockFeatureBuilder::TypesOriginAndEdgeLengths);//设置创建类型
 
     NXOpen::Point3d originPoint1(100.0, 100.0, 100.0);
     blockFeatureBuilder1->SetOriginAndLengths(originPoint1, "100", "100", "100");//设置原点
 
     blockFeatureBuilder1->SetBooleanOperationAndTarget(NXOpen::Features::Feature::BooleanTypeCreate, nullNXOpen_Body);//设置布尔
 
     NXOpen::Features::Feature *feature1;
     feature1 = blockFeatureBuilder1->CommitFeature();
     
     //NXOpen方式设置颜色
     NXOpen::DisplayModification *displayModification1;
     displayModification1 = theSession->DisplayManager()->NewDisplayModification();
 
     displayModification1->SetNewColor(108);//设置颜色
 
     std::vector<NXOpen::DisplayableObject *> objects1(1);
     NXOpen::Body *body1(dynamic_cast<NXOpen::Body *>(workPart->Bodies()->FindObject(feature1->JournalIdentifier())));
     objects1[0] = body1;
     displayModification1->Apply(objects1);
 
 
 
 
 
     //方法3:UFUN创建块,NXOpen设置颜色
     //UFUN方式创建块
     UF_FEATURE_SIGN Sign1 = UF_NULLSIGN;
     double Corner_pt1[3] = { 200.0, 200.0, 200.0 };
     char *Edge_len1[3] = { "100", "100", "100" };
     tag_t BlkTag1 = NULL_TAG;
     UF_MODL_create_block1(Sign1, Corner_pt1, Edge_len1, &BlkTag1);
 
     //UFUN方式特征找体
     tag_t BodyTag1 = NULL_TAG;
     UF_MODL_ask_feat_body(BlkTag1, &BodyTag1);
 
     //NXOpen方式设置颜色
     NXOpen::DisplayModification *displayModification2;
     displayModification2 = theSession->DisplayManager()->NewDisplayModification();
 
     displayModification2->SetNewColor(128);//设置颜色
 
     std::vector<NXOpen::DisplayableObject *> objects2(1);
     NXOpen::Body *body2(dynamic_cast<NXOpen::Body *>(NXOpen::NXObjectManager::Get(BodyTag1)));
     objects2[0] = body2;
     displayModification2->Apply(objects2);
 
 
 
 
 
     //方法4:NXOpen创建块,UFUN设置颜色
     //NXOpen方式创建块
     NXOpen::Features::Feature *nullNXOpen_Features_Feature1(NULL);
     NXOpen::Features::BlockFeatureBuilder *blockFeatureBuilder2;
     blockFeatureBuilder2 = workPart->Features()->CreateBlockFeatureBuilder(nullNXOpen_Features_Feature1);
 
     std::vector<NXOpen::Body *> targetBodies2(1);
     NXOpen::Body *nullNXOpen_Body1(NULL);
     targetBodies2[0] = nullNXOpen_Body1;
     blockFeatureBuilder2->BooleanOption()->SetTargetBodies(targetBodies2);
 
     blockFeatureBuilder2->SetType(NXOpen::Features::BlockFeatureBuilder::TypesOriginAndEdgeLengths);//设置创建类型
 
     NXOpen::Point3d originPoint2(300.0, 300.0, 300.0);
     blockFeatureBuilder2->SetOriginAndLengths(originPoint2, "100", "100", "100");//设置原点
 
     blockFeatureBuilder2->SetBooleanOperationAndTarget(NXOpen::Features::Feature::BooleanTypeCreate, nullNXOpen_Body1);//设置布尔
 
     NXOpen::Features::Feature *feature2;
     feature2 = blockFeatureBuilder2->CommitFeature();
 
     //UFUN方式特征找体
     tag_t BodyTag2 = NULL_TAG;
     UF_MODL_ask_feat_body(feature2->Tag(), &BodyTag2);
 
     //UFUN方式设置颜色
     UF_OBJ_set_color(BodyTag2, 125);
 
 
     UF_terminate();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值