/*寻找最大边界组*/
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;
}
【UG\NX二次开发】寻找片体最大边界组
于 2023-11-09 15:14:21 首次发布