NX二次开发中,其他一些有用函数的使用大全
7,裁剪片体
tag_t*trim_objects;
trim_objects =new tag_t;
trim_objects =bound_id;
voidtrim_sheet()
{
UF_MODL_vector_t projection_method ;
projection_method.reverse_vector=0;
projection_method.vector_type=UF_MODL_VECTOR_DIRECTION;
UF_MODL_vector_defined_by_union_tdir1;
UF_MODL_vector_direction_t dir2;
dir2.xyz =dir;
dir2.xyz =dir;
dir2.xyz =dir;
dir1.direction=dir2;
projection_method.defined_by=dir1;
double point_coords ;
point_coords=center;
point_coords=center;
point_coords=center;
int gap_point_count ;
double *gap_points;
tag_t feature_obj_eid;
UF_MODL_create_trimmed_sheet(sel_sheet,edge_count,trim_objects,&projection_method,
0,1,point_coords,0.1,&gap_point_count,&gap_points,&feature_obj_eid);
}
8,offset偏移
char distance_str[] = {"10.0"};//偏移的距离
intnum_curves;
tag_t *offset_curves;
UF_CURVE_offset_distance_data_toffset_distance;
offset_distance.distance= distance_str;
offset_distance.rough_type=1;
UF_STRING_t input_string;
input_string.id=curve_id;//加入想要偏移的线
input_string.num=1; //偏移矢量方向数量
input_string.string=&string_count;//偏移线的数量
intstring_dir=UF_MODL_CURVE_START_FROM_END;
input_string.dir=&string_dir;
UF_CURVE_offset_data_toffset_data;
offset_data.offset_def.distance_type1= &offset_distance;
offset_data.input_curves= &input_string;
offset_data.approximation_tolerance= 0.01;
offset_data.string_tolerance=0.001;
offset_data.offset_def.distance_type1= &offset_distance;
offset_data.offset_type= UF_CURVE_OFFSET_DISTANCE_TANGENT;
UF_CALL(UF_CURVE_create_offset_curve(&offset_data,
&num_curves,&offset_curves));
9,创建平面
UF_STRING_tgenerator;
UF_STRING_p_tge = &generator;
UF_MODL_init_string_list(ge);
UF_MODL_create_string_list(1,12,ge);
ge->string= 1;
ge->dir= 1;//指定线从开始到结束
ge->id= arc_id;//指定边界的id
doubletol;
tol =.001;//直线公差
tol = .5* (PI/180);//圆弧公差
tol =.02;//不起作用
UF_CALL(UF_MODL_create_bplane(ge,tol,&bplane));
10,选择
1),点选择
tag_t point_tag;
double point;
UF_UI_POINT_base_method_tbase_method=UF_UI_POINT_INFERRED ;
intpoint_res;
UF_CALL(UF_UI_point_construct("选择起点",&base_method,&point_tag,
point,&point_res));
if(point_res=UF_UI_OK&&NULL_TAG!=point_tag)
{
}
2),向量选择
intmode = UF_UI_INFERRED ;
intdisp_flag = UF_UI_DISP_TEMP_VECTOR;
double vec;
double vec_pnt;
int res_vec = 0;
UF_initialize();
ifail=UF_UI_specify_vector( "Choose aVector",&mode,disp_flag,
vec,vec_pnt,&res_vec);
if( ifail != 0 || res_vec!= UF_UI_OK )
{
UF_UI_ONT_refresh();
printf("No vector selected \n" );
}
else
{
printf("Vect base (%f, %f, %f), direction (%f, %f, %f) \n",
vec_pnt,vec_pnt, vec_pnt, vec, vec, vec );
}
3),平面选择
tag_t plane_eid=NULL_TAG;
double orientation ={0,0,0,0,0,0,0,0,0};
double origin = {0,0,0};
double pts = {0,0,0,0,0,0};
int i, error_code = 0;
int mode, display, response;
mode = 1;
display = 0;
UF_initialize();
error_code = UF_UI_specify_plane(
"Select Plane", &mode, display,
&response, orientation, origin,&plane_eid);
if ( !error_code && response != 1&& response != 2)
{
for (i=0; i<3; i++)
pts = origin + orientation;
for (i=3; i<6; i++)
pts = origin + orientation;
FTN(uf5374)(origin,pts,&pts,&plane_eid);
}
11,临时点,线
void display_temporary_point_line (double point1, double point2)
{
UF_DISP_view_type_twhich_views = UF_DISP_USE_WORK_VIEW;
UF_OBJ_disp_props_tcolor;
color.layer= 201;
color.color= 186;
color.blank_status= UF_OBJ_NOT_BLANKED;
color.line_width= UF_OBJ_WIDTH_NORMAL;
color.font=0;
color.highlight_status= FALSE;
UF_DISP_poly_marker_tmarker_type = UF_DISP_POINT;
UF_DISP_display_temporary_point ( NULL,which_views, point1, &color, marker_type);
UF_DISP_display_temporary_point ( NULL,which_views, point2, &color, marker_type);
UF_DISP_display_temporary_line ( NULL,which_views, point1, point2, &color);
}
12,WCS与绝对坐标转换
voidcycs_wcs(double point[])
{
tag_twcs_id,matrix_id;
double matrix[ 9 ];
//wcs_origin:工作坐标系原点,vec:工作坐标系轴向量,point_origin:点到原点的矢量
double wcs_origin ,vec,point_origin;
//1,得到工作坐标系
UF_CSYS_ask_wcs(&wcs_id);
UF_CSYS_ask_csys_info(wcs_id,&matrix_id,wcs_origin);
UF_CSYS_ask_matrix_values(matrix_id,matrix);
//2,得到工作坐标系轴向量
UF_MTX3_x_vec (matrix,vec);
UF_MTX3_y_vec (matrix,vec);
UF_MTX3_z_vec (matrix,vec);
for(int i=0;i<3;i++)
{
double tol;
//3,得到点到工作坐标系原点矢量
UF_VEC3_unitize(vec,0.000001,&tol,vec);
//4,得到点到工作坐标系原点矢量
point_origin=point-wcs_origin;
}
for(int j=0;j<3;j++)
{
UF_VEC3_dot(point_origin,vec,&point);
}
}
13,三点求圆心
#include<iostream.h>
#include<math.h>
int main()
{
int x1,y1,x3,y3;
double a,b,c,d,e,f;
doubler,k1,k2,x,y,x2,y2;
cout<<"请输入x1,y1,x2,y2,x3,y3"<<endl;
cin>>x1>>y1>>x2>>y2>>x3>>y3;
if((y1==y2)&&(y2==y3))
{
cout<<"三点不构成圆!"<<endl;
return 0;
}
if((y1!=y2)&&(y2!=y3))
{
k1=(x2-x1)/(y2-y1);
k2=(x3-x2)/(y3-y2);
}
if(k1==k2)
{
cout<<"三点不构成圆!"<<endl;
return 0;
}
a=2*(x2-x1);
b=2*(y2-y1);
c=x2*x2+y2*y2-x1*x1-y1*y1;
d=2*(x3-x2);
e=2*(y3-y2);
f=x3*x3+y3*y3-x2*x2-y2*y2;
x=(b*f-e*c)/(b*d-e*a);
y=(d*c-a*f)/(b*d-e*a);
cout<<"圆心为("<<x<<","<<y<<")"<<endl;
r=sqrt((x-x1)*(x-x1)+(y-y1)*(y-y1));
cout<<"半径为"<<r<<endl;
return 0;
}
14,查找圆心
UF_EVAL_p_tevaluator ;
UF_EVAL_arc_t arc;
UF_EVAL_initialize(obj_tag,&evaluator);
UF_EVAL_ask_arc(evaluator,&arc);
UF_VEC3_copy(arc.center,point);
15, message_box
void message_box(int *res_mes)
{
UF_UI_message_buttons_sbuttons;
buttons.button1=TRUE;
buttons.button2=FALSE;
buttons.button3=TRUE;
buttons.label1="OK";
buttons.label3="CANEL";
buttons.response1=UF_UI_OK;
buttons.response3=UF_UI_CANCEL;
char *string_msg;
char*material_msg="ALL selcted objects will be removed";
string_msg =material_msg;
UF_CALL(UF_UI_message_dialog("",
UF_UI_MESSAGE_WARNING,
&material_msg,
1,
TRUE,
&buttons,
res_mes ));
}
16,选择过滤
static int init_add_face( UF_UI_selection_p_t select, void *client_data)
{
int nums = 1;
UF_UI_mask_t masks[] ={
UF_solid_type, 0,UF_UI_SEL_FEATURE_ANY_FACE};
if(
(UF_UI_set_sel_mask(select,UF_UI_SEL_MASK_CLEAR_AND_ENABLE_SPECIFIC,nums,masks)==0)
&&(UF_UI_set_sel_procs(select,filter_proc_circle,NULL,client_data)==0)
)
{
return(UF_UI_SEL_SUCCESS);
}
else
{
return(UF_UI_SEL_FAILURE);
}
}
int find_tag(
void * client_data,//用以传输过滤资料
tag_t object//现在鼠标所选物体ID
)
{
user_data *obj;
obj=(user_data*)client_data;
int find_face=true;//接受
char *string1;
string1=newchar;
string1=UF_TAG_ask_handle_of_tag(object);
for(int i=0;i<过滤的数目;i++)
{
char *string2;
string2=newchar;
string2=UF_TAG_ask_handle_of_tag(物体ID);
if(strcmp(string1,string2)==0)
{
find_face=FALSE;//不接受
}
delete []string2;
}
delete []string1;
return find_face;
}
z支持z支持z支持z支持z支持z支持z支持z支持z支持z支持z支持z支持z支持z支持z支持z支持z支持z支持z支持z支持z支持
页:
[1]