PLM之家NX二次开发:第二次课后附加作业
•使用ufun完成以下功能1.新建一个部件文件,比如:c:\plmhome.prt
2.在部件中创建一个圆柱体,通过圆柱体创建圆柱体的中心线
3.查询中心线的起点和终点,并输出到信息窗口
4.保存部件
5.关闭部件
•提示:使用到的函数:
UF_PART_new,UF_PART_save,UF_PART_close_allUF_MODL_create_cyl1,uf_curve_create_line,uf_curve_ask_line,UF_UI_open_listing_window,UF_UI_write_listing_window
tag_t newPartTag = NULL_TAG;
tag_t cylTag = NULL_TAG;
tag_t bodyTag = NULL_TAG;
double cylOrigin = {20, 30, 40};
char cylDiam = "50";
double cylDirection = {0, 0 ,1};
double height = 60;
char cylHeight;
sprintf_s(cylHeight, sizeof(cylHeight), "%f", height);
//创建part
UF_CALL(UF_PART_new("D:\\leaf.part", 1, &newPartTag));
//创建圆柱
UF_CALL(UF_MODL_create_cyl1(UF_NULLSIGN, cylOrigin, cylHeight, cylDiam, cylDirection, &cylTag));
//获取圆柱特征所在的体
UF_CALL(UF_MODL_ask_feat_body(cylTag,&bodyTag));
//获取体上的边
uf_list_p_t edge_list ;
UF_CALL(UF_MODL_ask_body_edges(bodyTag, &edge_list));
//得到边的数量
int edgeCount = 0;
UF_CALL(UF_MODL_ask_list_count(edge_list, &edgeCount));
//打印边的数量
char cCount;
sprintf_s(cCount, sizeof(cCount), "cylinder实体上的边的数量:%d",edgeCount);
uc1601(cCount, 1);
int error;
double (*point_coords);
point_coords= (double (*)) UF_allocate_memory(edgeCount * sizeof(double ), &error );
//获取圆柱的上两条边的圆心
int i = 0;
tag_t curveOriginTag = NULL_TAG;
for (i; i < edgeCount; i++)
{
UF_CALL(UF_MODL_ask_list_item(edge_list, i, &curveOriginTag));
UF_CALL(UF_CURVE_ask_centroid(curveOriginTag, point_coords));
}
//将圆心存放到直线起始点的链表中
UF_CURVE_line_p_t line_coords;
line_coords= (UF_CURVE_line_p_t ) UF_allocate_memory(edgeCount * sizeof(double ), &error );
line_coords->start_point = point_coords;
line_coords->start_point = point_coords;
line_coords->start_point = point_coords;
line_coords->end_point = point_coords;
line_coords->end_point = point_coords;
line_coords->end_point = point_coords;
tag_t lineTag = NULL_TAG;
//创建直线
UF_CALL(UF_CURVE_create_line(line_coords, &lineTag));
//打印直线的端点
char msg;
sprintf_s(msg, sizeof(msg), "创建的直线的起点是:%f、%f、%f,\n终点是:%f、%f、%f.",
line_coords->start_point,
line_coords->start_point,
line_coords->start_point,
line_coords->end_point,
line_coords->end_point,
line_coords->end_point);
UF_CALL(UF_UI_open_listing_window());
UF_CALL(UF_UI_write_listing_window(msg));
//UF_CALL(UF_UI_close_listing_window());
//释放动态内存
UF_MODL_delete_list(&edge_list);
UF_free(point_coords);
UF_free(line_coords);
UF_PART_save();
UF_PART_close_all();
页:
[1]