1. 程式人生 > >NX二次開發-獲取面的法向向量UF_MODL_ask_face_data

NX二次開發-獲取面的法向向量UF_MODL_ask_face_data

NX9+VS2012

#include <uf.h>
#include <uf_modl.h>
#include <uf_obj.h>
#include <uf_ui.h>


UF_initialize();

//建立圓柱
UF_FEATURE_SIGN Sign = UF_NULLSIGN;
double Origin[3] = {0.0, 0.0, 0.0};
char *Height = "100";
char *Diam = "50";
double Direction[3] = {0.0, 0.0, 1.0};
tag_t CylTag = NULL_TAG;
UF_MODL_create_cyl1(Sign, Origin, Height, Diam, Direction, &CylTag);

//特徵找體
tag_t BodyTag = NULL_TAG;
UF_MODL_ask_feat_body(CylTag, &BodyTag);

//體找面
uf_list_p_t FaceList;
UF_MODL_ask_body_faces(BodyTag, &FaceList);

//獲取連結串列數量
int Count;
UF_MODL_ask_list_count(FaceList, &Count);

UF_UI_open_listing_window();
//獲取連結串列裡的tag
for (int i = 0; i < Count; i++)
{
	tag_t FaceTag = NULL_TAG;
	UF_MODL_ask_list_item(FaceList, i, &FaceTag);

	//獲取面的法向
	int Type;
	double Point[3];
	double Dir[3];
	double Box[6];
	double Radius[3];
	double RadData[3];
	int NormDir;
	UF_MODL_ask_face_data(FaceTag, &Type, Point, Dir, Box, Radius, RadData, &NormDir);

	//找圓柱側面
	if (Type == 16)//對比面的型別
	{
		//對圓柱側面設定顏色
		UF_OBJ_set_color(FaceTag, 186);

		//列印面的法向方向
		char msg[256];
		sprintf_s(msg, "面的法向方向為:\nX:%.0f\nY:%.0f\nZ:%.0f\n", Dir[0], Dir[1], Dir[2]);			
		UF_UI_write_listing_window(msg);			
	}
}

//釋放記憶體
UF_MODL_delete_list(&FaceList);

UF_terminate();

Caesar盧尚宇  
[email protected]

在這裡插入圖片描述