NX9+VS2012 #include <uf.h> #include <uf_draw.h> #include <uf_obj.h> #include <uf_part.h> #include <NXOpen/UI.hxx> #include <NXOpen/MenuBar_MenuBarManager.hxx> UF_initialize(); //新建工程图(A4图纸) char* DrawingName = "Sheet1";//设置图纸名字 UF_DRAW_info_t DrawingInfo;//设置图纸大小、投影视角、视图比例等 DrawingInfo.size_state = UF_DRAW_METRIC_SIZE;//设置图纸类型 DrawingInfo.size.metric_size_code = UF_DRAW_A4;//设置图纸大小 DrawingInfo.drawing_scale = 1.0;//设置比例 DrawingInfo.units = UF_PART_METRIC;//设置单位 DrawingInfo.projection_angle = UF_DRAW_FIRST_ANGLE_PROJECTION;//设置投影视角 tag_t DrawingTag = NULL_TAG; UF_DRAW_create_drawing(DrawingName, &DrawingInfo, &DrawingTag); //导入视图(创建Top视图) //找名字获取视图的Tag tag_t TopViewTag = NULL_TAG; UF_OBJ_cycle_by_name_and_type(UF_PART_ask_display_part(), "Top", UF_view_type, false, &TopViewTag); //导入视图(创建Trimetric视图) //找名字获取视图的Tag tag_t TrimetricViewTag = NULL_TAG; UF_OBJ_cycle_by_name_and_type(UF_PART_ask_display_part(), "Trimetric", UF_view_type, false, &TrimetricViewTag); UF_DRAW_view_info_t TopViewInfo; UF_DRAW_initialize_view_info(&TopViewInfo);//初始化视图信息 double TopDwgPoint[2] = {150.0, 160.0}; tag_t TopDrawViewTag = NULL_TAG; UF_DRAW_import_view(DrawingTag, TopViewTag, TopDwgPoint, &TopViewInfo, &TopDrawViewTag); double TrimetricDwgPoint[2] = {100, 100}; tag_t TrimetricDrawViewTag = NULL_TAG; UF_DRAW_import_view(DrawingTag, TrimetricViewTag, TrimetricDwgPoint, &TopViewInfo, &TrimetricDrawViewTag); //更新所有视图 UF_DRAW_upd_out_of_date_views(DrawingTag); int ModuleId; UF_ask_application_module(&ModuleId);//获取当前所在的模块 if (ModuleId != 1)//此处等于1,是从帮助找到的,在帮助搜DRAFTING,就可以搜到一堆的宏定义,UG_APP_DRAFTING就等于1. { theUI->MenuBarManager()->ApplicationSwitchRequest("UG_APP_DRAFTING");//切换到工程图模块 } UF_terminate(); Caesar卢尚宇 2020年9月12日