NX二次开发-UFUN创建图纸水平尺寸标注UF_DRF_create_horizontal_dim

时间:2024-04-15 09:02:26
NX9+VS2012

#include <uf.h>
#include <uf_curve.h>
#include <uf_draw.h>
#include <uf_drf.h>
#include <uf_obj.h>
#include <uf_part.h>
#include <NXOpen/UI.hxx>
#include <NXOpen/MenuBar_MenuBarManager.hxx>



UF_initialize();

//创建点
double p1[3] = {10,0,0};
tag_t p1Tag = NULL_TAG;
UF_CURVE_create_point(p1,&p1Tag);

double p2[3] = {100,0,0};
tag_t p2Tag = NULL_TAG;
UF_CURVE_create_point(p2,&p2Tag);

//创建直线
UF_CURVE_line_t Line_coords;
Line_coords.start_point[0] = p1[0];
Line_coords.start_point[1] = p1[1];
Line_coords.start_point[2] = p1[2];
Line_coords.end_point[0] = p2[0];
Line_coords.end_point[1] = p2[1];
Line_coords.end_point[2] = p2[2];
tag_t Line = NULL_TAG;
UF_CURVE_create_line(&Line_coords, &Line);

//切换到制图模块
theUI->MenuBarManager()->ApplicationSwitchRequest("UG_APP_DRAFTING");

//新建工程图(A4图纸)
char* DrawingName = "ABC";//设置图纸名字
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);

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);

//更新视图
UF_DRAW_update_one_view(DrawingTag, TopDrawViewTag);

//创建水平尺寸标注
UF_DRF_object_t object1;
object1.object_tag = p1Tag;
object1.object_view_tag = TopDrawViewTag;
object1.object_assoc_type = UF_DRF_end_point;
object1.object_assoc_modifier = UF_DRF_first_end_point;
UF_DRF_object_t object2;
object2.object_tag = p2Tag;
object2.object_view_tag = TopDrawViewTag;
object2.object_assoc_type = UF_DRF_end_point;
object2.object_assoc_modifier = UF_DRF_first_end_point;
UF_DRF_text_t drf_text;
drf_text.user_dim_text = NULL;
drf_text.lines_app_text = 0;
drf_text.appended_text = NULL;
double dimension_3d_origin[3] = {155,146,0};
tag_t dimension_tag = NULL_TAG;
UF_DRF_create_horizontal_dim(&object1, &object2, &drf_text, dimension_3d_origin, &dimension_tag);

UF_terminate();

Caesar卢尚宇
2020年9月18日