uf草图操作
#include <uf_sket.h>
#include <uf_curve.h>
#include <uf_part.h>
char name[30] = "Sketch_001";//草图名称
tag_t sketch_id;
UF_SKET_initialize_sketch ( name, &sketch_id );//初始化草图
int option = 2;//草图位置由坐标系确定
double matrix[9];
tag_t object[2];
int reference[2];
int plane_dir = 1;
matrix[0] = 1;//X轴
matrix[1] = 0;
matrix[2] = 0;
matrix[3] = 0;//Y轴
matrix[4] = 1;
matrix[5] = 0;
matrix[6] = 0;//用来确定草图的坐标系的原点
matrix[7] = 0;
matrix[8] = 0;
UF_SKET_create_sketch ( name, option, matrix, object, reference, plane_dir, &sketch_id );//创建新的草图
tag_t line_tag1;
UF_CURVE_line_s line_coords1;
line_coords1.start_point[0] = 0.0;
line_coords1.start_point[1] = 0.0;
line_coords1.start_point[2] = 0.0;
line_coords1.end_point[0] = 10.0;
line_coords1.end_point[1] = 10.0;
line_coords1.end_point[2] = 0.0;
UF_CURVE_create_line ( &line_coords1, &line_tag1 );//生成直线1
tag_t line_tag2;
UF_CURVE_line_s line_coords2;
line_coords2.start_point[0] = 15.0;
line_coords2.start_point[1] = 0.0;
line_coords2.start_point[2] = 0.0;
line_coords2.end_point[0] = 25.0;
line_coords2.end_point[1] = 10.0;
line_coords2.end_point[2] = 0.0;
UF_CURVE_create_line ( &line_coords2, &line_tag2 );//生成直线2
int count = 2;
tag_t addObject[2];
addObject[0] = line_tag1;
addObject[1] = line_tag2;
UF_SKET_add_objects ( sketch_id, count, addObject );//将直线添加到草图
UF_SKET_con_type_t dim_type = UF_SKET_horizontal_dim;//水平尺寸类型
UF_SKET_dim_object_s dim_object1;
UF_SKET_dim_object_s dim_object2;
double dim_origin[3];
tag_t dim_tag;
dim_object1.object_tag = line_tag1;
dim_object1.object_assoc_type = UF_SKET_end_point;
dim_object1.object_assoc_mod_value = UF_SKET_first_end_point;
dim_object2.object_tag = line_tag2;
dim_object2.object_assoc_type = UF_SKET_end_point;
dim_object2.object_assoc_mod_value = UF_SKET_first_end_point;
dim_origin[0] = 0.0;
dim_origin[1] = 20.0;
dim_origin[2] = 0.0;
UF_SKET_create_dimension ( sketch_id, dim_type, &dim_object1, &dim_object2, dim_origin, &dim_tag );//创建尺寸
int num_dim_obj = 2;//
UF_SKET_dim_object_s dim_objs[2];
tag_t con_tag;
dim_type = UF_SKET_parallel_dim;//平行尺寸类型
dim_objs[0].object_tag = line_tag1;
dim_objs[0].object_assoc_type = UF_SKET_end_point;
dim_objs[0].object_assoc_mod_value = UF_SKET_first_end_point;
dim_objs[1].object_tag = line_tag2;
dim_objs[1].object_assoc_type = UF_SKET_end_point;
dim_objs[1].object_assoc_mod_value = UF_SKET_first_end_point;
dim_origin[0] = -20.0;
dim_origin[1] = 0.0;
dim_origin[2] = 0.0;
UF_SKET_create_dimensional_constraint ( sketch_id, dim_type, num_dim_obj, dim_objs, dim_origin, &con_tag );//创建尺寸约束
UF_SKET_con_type_t con_type = UF_SKET_parallel;//平行约束类型
UF_SKET_con_geom_s con_geoms[2];
int num_con_geoms = 2;
tag_t geom_con_tag;
con_geoms[0].geom_tag = line_tag1;
con_geoms[1].geom_tag = line_tag2;
UF_SKET_create_geometric_constraint ( sketch_id, con_type, num_con_geoms, con_geoms, &geom_con_tag );//创建几何约束
int num_exps;
tag_t *expression_tags;
UF_SKET_ask_exps_of_sketch ( sketch_id, &num_exps, &expression_tags );//查询草图中的表达式
int num_cons;
tag_t *con_tags;
UF_SKET_ask_geo_cons_of_sketch ( sketch_id, &num_cons, &con_tags );//查询草图中的几何约束
UF_SKET_update_sketch ( sketch_id );//更新草图
UF_SKET_terminate_sketch();//关闭草图
UF_free( expression_tags );
UF_free( con_tags );
_____________________________________________________________________________ _
中磊UG二次开发教程 梅雷著 qq1821117007
学UG就上UG网 http://www.9sug.com/ |