NXOpenC++布尔求和命令

2024-01-01 15:32:58

一、概述

????????在进行批量布尔求和时,采用NXOpenC++的方式要比UFun的方式美观的多,个人认为,ufun中UF_MODL_unite_bodies函数采用的是两两进行合并,显示多个步骤,而NXOpenC++采用的是一个工具体和多个目标体进行合并,最终只显示一个步骤。具体原因个人目前不太清楚。

二、布尔求和

NXOpenC++

   NXOpen::Session *theSession = NXOpen::Session::GetSession();
	NXOpen::Part *workPart(theSession->Parts()->Work());
	NXOpen::Part *displayPart(theSession->Parts()->Display());

	vector<tag_t> thecycleTAG;

	//找到工作部件所有的体
	tag_t WorkPartTag1 = UF_PART_ask_display_part();
	tag_t objTag1 = NULL_TAG;
	UF_OBJ_cycle_objs_in_part1(WorkPartTag1, UF_solid_type, &objTag1);

	int type1;
	int subtype1;
	while (objTag1 != NULL_TAG)
	{
		UF_OBJ_ask_type_and_subtype(objTag1, &type1, &subtype1);
		if (!subtype1)
		{
			thecycleTAG.push_back(objTag1);
		}
		UF_OBJ_cycle_objs_in_part1(WorkPartTag1, UF_solid_type, &objTag1);
	}

	// ----------------------------------------------
	//   Menu: 插入(S)->组合(B)->合并(U)...
	// ----------------------------------------------
	NXOpen::Features::BooleanFeature *nullNXOpen_Features_BooleanFeature(NULL);
	NXOpen::Features::BooleanBuilder *booleanBuilder1;
	booleanBuilder1 = workPart->Features()->CreateBooleanBuilderUsingCollector(nullNXOpen_Features_BooleanFeature);	
	//建模公差
	booleanBuilder1->SetTolerance(0.001);
	//选择布尔类型——求和BooleanTypeUnite
	booleanBuilder1->SetOperation(NXOpen::Features::Feature::BooleanTypeUnite);
	//目标体的设置
	NXOpen::Body *body1(dynamic_cast<NXOpen::Body *>(NXOpen::NXObjectManager::Get(thecycleTAG[0])));
	bool added1;
	added1 = booleanBuilder1->Targets()->Add(body1);
	//工具体设置	
	NXOpen::ScCollector *scCollector2;//定义一个工具收集器
	scCollector2 = workPart->ScCollectors()->CreateCollector();

	std::vector<NXOpen::Body *> bodies1;//获得工具体的body
	for (int i = 1; i < thecycleTAG.size(); i++)
	{
		NXOpen::Body *body(dynamic_cast<NXOpen::Body *>(NXOpen::NXObjectManager::Get(thecycleTAG[i])));
		bodies1.push_back(body);
	}

	NXOpen::BodyDumbRule *bodyDumbRule1;
	bodyDumbRule1 = workPart->ScRuleFactory()->CreateRuleBodyDumb(bodies1, true);

	std::vector<NXOpen::SelectionIntentRule *> rules1(1);
	rules1[0] = bodyDumbRule1;
	scCollector2->ReplaceRules(rules1, false);
	//设置目标体
	booleanBuilder1->SetToolBodyCollector(scCollector2);

	//创建、销毁
	NXOpen::NXObject *nXObject1;
	nXObject1 = booleanBuilder1->Commit();
	booleanBuilder1->Destroy();

UFUN

    std::vector<NXOpen::TaggedObject *> selectbodys = selection0->GetSelectedObjects();
		//TaggedObject转化tag_t
		std::vector<tag_t> body_ZX, body_FX;
		for (int i = 0; i < (int)selectbodys.size(); i++)
		{
			body_ZX.push_back(selectbodys[i]->Tag());
			body_FX.push_back(selectbodys[i]->Tag());
		}

		std::reverse(body_FX.begin(), body_FX.end());//反向排序

		//进行循环
		int j = 0;
		for (int i = 0; i < (int)body_ZX.size(); i++)
		{
			for ( j =0 ; j < (int)body_FX.size(); j++)
			{
				if (body_ZX[i] != body_FX[j])
				{
					findbodyTAG = NULL_TAG;
					findBody(body_ZX[i]); //找体

					if (findbodyTAG != NULL_TAG)
					{
						creatUnite(body_FX[j], body_ZX[i]); //通过判断求和
					}
				}
			}
			if ((int)body_FX.size() > 1)//反向减一
			{
				body_FX.pop_back();
			}
			j = (int)body_FX.size();
		}

原模型

NXOpenC++

UFUN

文章来源:https://blog.csdn.net/weixin_47753171/article/details/135317825
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。