购买与咨询 NX 二次开发视频教程,请联系微信号:13890821008 QQ号:85585969
//创建型腔和孔
#include <stdio.h>
#include <uf.h>
#include <uf_modl.h>
#include <uf_ui.h>
#include <malloc.h>
/*定义全局变量,用于转递相对定位的目标边*/
tag_t edge_blk[12];
tag_t edge_blend[4];
/*注册型腔定位的用户函数*/
int rpo_routine_pocket(tag_t obj_id)
{
int irc=0,i;
uf_list_p_t edge_list;
int count_list;
tag_t tem_tag,*edge_pock;
edge_pock=(tag_t *)malloc(12*sizeof(tag_t));
tag_t *obj_id_target,*obj_id_tool;
obj_id_target=(tag_t *)malloc(3*sizeof(tag_t));
obj_id_tool=(tag_t *)malloc(3*sizeof(tag_t));
char *constraint_value[]={"0.0","0.0"};
char *constraint_array[]={"PARA_EDGE_PARMS","PARA_EDGE_PARMS"};
int target_qualifier[]={UF_MODL_ENDPOINT_1,UF_MODL_ENDPOINT_1};
int tool_qualifier[]={UF_MODL_ENDPOINT_1,UF_MODL_ENDPOINT_1};
UF_MODL_ask_feat_edges(obj_id,&edge_list );
UF_MODL_ask_list_count(edge_list,&count_list);
for (i=0;i<count_list;i++)
{
UF_MODL_ask_list_item(edge_list,i,&tem_tag);
edge_pock=tem_tag;
}
UF_MODL_delete_list(&edge_list);
obj_id_tool[0]=edge_pock[0];
obj_id_tool[1]=edge_pock[4];
obj_id_target[0]=edge_blk[1];
obj_id_target[1]=edge_blk[0];
irc=UF_MODL_create_rpo_constraints(obj_id,NULL_TAG,NULL_TAG,obj_id_target,
target_qualifier,obj_id_tool,tool_qualifier,constraint_value,constraint_array,2);
free(edge_pock);
free(obj_id_target);
free(obj_id_tool);
if (irc == 0)
return (0);
else
return (1);
}
//孔定位的用户函数
int rpo_routine_hole(tag_t obj_id)
{
int irc,i;
int count_list;
tag_t tem_tag;
tag_t edge_tool[5];
uf_list_p_t edge_list;

●●●请先
登陆 或
注册 后查看●●●
obj_id_target[0]=edge_blend[2];
obj_id_tool[0]=edge_tool[1];
irc=UF_MODL_create_rpo_constraints(obj_id,NULL_TAG,NULL_TAG,obj_id_target,
target_qualifier,obj_id_tool,tool_qualifier,constraint_value,constraint_array,1);
if (irc == 0)
return (0);
else
return (1);
}
/*UG/OPEN API内部环境的入口函数*/
void ufusr(char *param, int *retcode, int paramLen)
{
if (!UF_initialize())
{
/*定义创建块的参数*/
UF_FEATURE_SIGN sign = UF_NULLSIGN;
double block_orig[3] = {0.0,0.0,0.0};
char *block_len[3] = {"100","60","40"};
tag_t blk_fea,blk_obj,tem_tag,face_blk[6];
uf_list_p_t face_list,edge_list;
int count_list;
int i;
/*定义创建型腔的参数*/
double pock_loc[3] = {25.0,30.0,40.0};
double pock_dir[3] = {0.0,0.0,-1.0};
double pock_x_dir[3]= {1.0,0.0,0.0};
char *pock_len[3]={"50.0","40.0","20.0"};
char *pock_corner={"0.0"};
char *pock_floor={"0.0"};
char *pock_angle={"0.0"};
tag_t pock_id;
/*定义创建边倒圆的参数*/
char *blend_radius="20.0";
uf_list_p_t blend_list,blend_edge_list;
tag_t blend_id;
/*定义创建孔的参数*/
double hole_origin[3] = {60.0,30.0,40.0};
double hole_cyl_dir[3] = {0.0,0.0,-1.0};
char *hole_dia = "25.0";
char *hole_height = "5.0";
char *hole_angle = "0.0";
tag_t hole_id;
/*创建块*/
UF_MODL_create_block1(sign, block_orig, block_len, &blk_fea);
UF_MODL_ask_feat_body(blk_fea,&blk_obj);
/*获得块上面的标识,用于确定成型特征的孔和型腔安置面,
以及孔的穿透面*/
UF_MODL_ask_body_faces(blk_obj,&face_list);
UF_MODL_ask_list_count(face_list,&count_list);
for (i=0;i<count_list;i++)
{
UF_MODL_ask_list_item(face_list,i,&tem_tag);
face_blk=tem_tag;
}
UF_MODL_delete_list(&face_list);
/*获得块上边的标识,用于相对定位*/
UF_MODL_ask_body_edges(blk_obj,&edge_list);
UF_MODL_ask_list_count(edge_list,&count_list);
for (i=0;i<count_list;i++)
{
UF_MODL_ask_list_item(edge_list,i,&tem_tag);
edge_blk=tem_tag;
}
UF_MODL_delete_list(&edge_list);
/*创建型腔,并进行相对定位*/
UF_MODL_register_rpo_routine(rpo_routine_pocket);
UF_MODL_create_rect_pocket(pock_loc,pock_dir,pock_x_dir,pock_len,
pock_corner,pock_floor,pock_angle,face_blk[0],&pock_id );
UF_MODL_unregister_rpo_routine();
/*进行边倒圆*/
UF_MODL_create_list(&blend_list);
UF_MODL_put_list_item(blend_list,edge_blk[6]);
UF_MODL_create_blend(blend_radius,blend_list,0,0,0,0.5,&blend_id);
/*获取倒圆的边,用于孔的相对定位*/
UF_MODL_ask_feat_edges(blend_id,&blend_edge_list);
UF_MODL_ask_list_count(blend_edge_list,&count_list);
for (i=0;i<count_list;i++)
{
UF_MODL_ask_list_item(blend_edge_list,i,&tem_tag);
edge_blend=tem_tag;
}
UF_MODL_delete_list(&blend_edge_list);
/*创建孔,并进行相对定位*/
UF_MODL_register_rpo_routine(rpo_routine_hole);
UF_MODL_create_simple_hole(hole_origin,hole_cyl_dir,hole_dia,
hole_height,hole_angle,face_blk[0],face_blk[1],&hole_id);
UF_MODL_unregister_rpo_routine();
UF_terminate();
}
}