【UG\NX二次开发】找到片体上除最大外轮廓以外的片体边界(破面边)

/*找到片体上除最大外轮廓以外的片体边界(破面边)*/
int FindBreakFaceEdges(tag_t sheetBody, vector<tag_t>& BreakFaceEdges)
{
	try
	{
		vector <tag_t> max_bnd_edges;//最大边界组的所有边
		double max_bnd_Length = 0.0;//最大边界组的长度
		FindMaxBnd(sheetBody, max_bnd_edges, max_bnd_Length);

		uf_list_p_t edges_list;
		UF_MODL_ask_body_edges(sheetBody, &edges_list);
		int egde_count = 0;
		UF_MODL_ask_list_count(edges_list, &egde_count);
		for (int k = 0; k < egde_count; ++k)
		{
			tag_t EdgeTag;
			UF_MODL_ask_list_item(edges_list, k, &EdgeTag);
			uf_list_p_t face_list;
			UF_MODL_ask_edge_faces(EdgeTag, &face_list);
			int face_count = 0;
			UF_MODL_ask_list_count(face_list, &face_count);
			if (face_count == 1)
			{
				vector<tag_t>::iterator it = find(max_bnd_edges.begin(), max_bnd_edges.end(), EdgeTag);
				if (it == max_bnd_edges.end())
				{
					BreakFaceEdges.push_back(EdgeTag);
					UF_DISP_set_highlight(EdgeTag, 1);
				}
			}
		}
	}
	catch (exception& ex)
	{
		UF_UI_open_listing_window();
		UF_UI_write_listing_window("找片体的破面边失败\n");
		return 1;
	}
	return 0;
}

/*寻找最大边界组*/
int FindMaxBnd(tag_t sewBody, vector <tag_t> &max_bnd_edges, double &max_bnd_Length)
{
	try
	{

		max_bnd_edges.clear();//最大边界组的所有边
		max_bnd_Length = 0.0;//最大边界组的长度
		int num_bnd = 0, *num_edges, count = 0;//边界组个数,边的个数
		tag_t* edge_tags;//所有边界组的所有边

		UF_CALL(UF_MODL_ask_body_boundaries(sewBody, &num_bnd, &num_edges, &edge_tags));
		if (num_bnd != 0)
		{
			//遍历所有边界组
			for (int i = 0; i < num_bnd; i++)
			{
				double this_bnd_Length = 0.0;//当前边界组总长度
				vector <tag_t> this_bnd_edges;//当前边界组中的所有边
				//遍历当前边界组内的所有边长度
				for (int j = count; j < count + num_edges[i]; j++)
				{
					this_bnd_edges.push_back(edge_tags[j]);//保存边
					//UF_DISP_set_highlight(edge_tags[j], 1);
					double length = 0.0;
					Edge* edge = dynamic_cast<Edge*>(NXOpen::NXObjectManager::Get(edge_tags[j]));
					length = edge->GetLength();
					/*sprintf(buffer, "num_edges[%d]:edge_tags[%d]:length = %f\n", i, j, length);
					UF_UI_write_listing_window(buffer);*/
					this_bnd_Length += length;//长度累加
				}
				/*sprintf(buffer, "num_edges[%d]:this_bnd_Length = %f\n", i, this_bnd_Length);
				UF_UI_write_listing_window(buffer);*/
				//记录最大边界组的长度和边
				if (this_bnd_Length - max_bnd_Length > 0.01 || i == 0)
				{
					max_bnd_Length = this_bnd_Length;
					max_bnd_edges.clear();
					for (int j = 0; j < this_bnd_edges.size(); j++)
						max_bnd_edges.push_back(this_bnd_edges[j]);
				}
				count += num_edges[i];
			}
			UF_free(edge_tags);
			UF_free(num_edges);
		}
		else
		{
			UF_UI_open_listing_window();
			UF_UI_write_listing_window("找不到边界\n");
			return 1;
		}
		return 0;
	}
	catch (exception& ex)
	{
		UF_UI_open_listing_window();
		UF_UI_write_listing_window("找不到边界\n");
		return 1;
	}
	return 0;
}

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

社恐猫

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值