1. 程式人生 > 實用技巧 >NX二次開發-UFUN建立圖紙豎直尺寸標註UF_DRF_create_vertical_dim

NX二次開發-UFUN建立圖紙豎直尺寸標註UF_DRF_create_vertical_dim

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); double p3[3] = {0,100,0}; tag_t p3Tag = NULL_TAG; UF_CURVE_create_point(p3,&p3Tag); //建立直線 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); //建立直線 UF_CURVE_line_t Line_coords1; Line_coords1.start_point[0] = p1[0]; Line_coords1.start_point[
1] = p1[1]; Line_coords1.start_point[2] = p1[2]; Line_coords1.end_point[0] = p3[0]; Line_coords1.end_point[1] = p3[1]; Line_coords1.end_point[2] = p3[2]; tag_t Line1 = NULL_TAG; UF_CURVE_create_line(&Line_coords1, &Line1); //切換到製圖模組 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_DRF_object_t object1A; object1A.object_tag = p1Tag; object1A.object_view_tag = TopDrawViewTag; object1A.object_assoc_type = UF_DRF_end_point; object1A.object_assoc_modifier = UF_DRF_first_end_point; UF_DRF_object_t object2A; object2A.object_tag = p3Tag; object2A.object_view_tag = TopDrawViewTag; object2A.object_assoc_type = UF_DRF_end_point; object2A.object_assoc_modifier = UF_DRF_first_end_point; UF_DRF_text_t drf_textA; drf_textA.user_dim_text = NULL; drf_textA.lines_app_text = 0; drf_textA.appended_text = NULL; double dimension_3d_originA[3] = {79,160,0}; tag_t dimension_tagA = NULL_TAG; UF_DRF_create_vertical_dim(&object1A, &object2A, &drf_textA, dimension_3d_originA, &dimension_tagA); UF_terminate(); Caesar盧尚宇 2020年9月18日