|
马上注册登录,享用更多网站功能!
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
嗯,五一劳动节,劳动了7天,比较光荣的完成了一点活。
我的娱乐项目就是在坛子里淘帖子了。
发现有很多同仁在在这里问道关于自动装配的问题。
我的课题在探索方法之初,我也做了一个很简单的例子。
拿出来献丑了,这都是难者不会,会者不难的东西吧。
希望给有疑问的一点有些启发,高手就不要笑话我了。
例子是做两个圆柱自动装配的例子。
先贴一下代码。
//打开第一个零件:
int CHANGE_add1_0_act_cb ( int dialog_id,
void * client_data,
UF_STYLER_item_value_type_p_t callback_data)
{
char * part1="D:\\ugexam\\ugexam\\a.prt";
char * refset_name1=NULL;
double origin1[ 3 ]={0.0,0.0,0.0};
char * instance_name1="a";
double csys_matrix1[ 6 ]={1.0,0.0,0.0,0.0,1.0,0.0};
int layer1=0;
tag_t instance1;
int ret;
char message[133];
UF_PART_load_status_t error_status1;
/* Make sure User Function is available. */
if ( UF_initialize() != 0)
return ( UF_UI_CB_CONTINUE_DIALOG );
/* ---- Enter your callback code here ----- */
//创建一个新的文件,再里面逐个增加零件,在产生配合条件进行装配
//UF_UI_open_listing_window();
UF_CALL(UF_PART_new(part_name1, UF_PART_ENGLISH, [$part))]
ret = UF_ASSEM_add_part_to_assembly (part, part1, refset_name1, instance_name1, origin1,
csys_matrix1, layer1, [$instance1, &error_status1 )]
if(ret != 0)
{
UF_get_fail_message(ret,message);
}
UF_terminate ();
/* Callback acknowledged, do not terminate dialog */
return (UF_UI_CB_CONTINUE_DIALOG);
/* or Callback acknowledged, terminate dialog. */
/* return ( UF_UI_CB_EXIT_DIALOG ); */
}
//在第一个零件中加入第二个零件。
int CHANGE_add2_1_act_cb ( int dialog_id,
void * client_data,
UF_STYLER_item_value_type_p_t callback_data)
{
char * part2="D:\\ugexam\\ugexam\\b.prt";
char * refset_name2=NULL;
double origin2[ 3 ]={0.0,0.0,0.0};
char * instance_name2="b";
double csys_matrix2[ 6 ]={1.0,0.0,0.0,0.0,0.0,1.0};
int layer2=0;
tag_t instance2;
UF_PART_load_status_t error_status2;
/* Make sure User Function is available. */
if ( UF_initialize() != 0)
return ( UF_UI_CB_CONTINUE_DIALOG );
/* ---- Enter your callback code here ----- */
UF_CALL(UF_ASSEM_add_part_to_assembly (part, part2, refset_name2, instance_name2, origin2,
csys_matrix2, layer2, [$instance2, &error_status2 ))]
UF_terminate ();
/* Callback acknowledged, do not terminate dialog */
return (UF_UI_CB_CONTINUE_DIALOG);
/* or Callback acknowledged, terminate dialog. */
/* return ( UF_UI_CB_EXIT_DIALOG ); */
}
//实现自动装配
int CHANGE_action_3_act_cb ( int dialog_id,
void * client_data,
UF_STYLER_item_value_type_p_t callback_data)
{
int ret;
char * name1="ENDFACE1";
char * name2="ENDFACE2";
char * name3="CYCLE1";
char * name4="CYCLE2";
tag_t first_plan,second_plan,cylinder_face1,cylinder_face2;
tag_t from_part_occ;
tag_t to_part_occ;
tag_t from_part_ins;
tag_t to_part_ins;
logical is_occ;
tag_t cylinder_from_part_occ;
tag_t cylinder_to_part_occ;
tag_t cylinder_from_part_ins;
tag_t cylinder_to_part_ins;
//logical cylinder_is_occ;
//提示所显示的实例的名称
char part_name[ 256 + 1 ];
char refset_name[ 30 + 1 ];
char instance_name[ 30 + 1 ];
double origin[ 3 ];
double csys_matrix[ 9 ];
double transform[ 4 ][ 4 ] ;
char message[133];
//======
//char tt[10];
//======
UF_ASSEM_mc_status_t status;
UF_ASSEM_mc_structure_state_t struct_status;
UF_ASSEM_dof_t dof;
UF_ASSEM_mating_condition_t ftf;
//UF_ASSEM_mating_condition_p_t mc_data;
/* Make sure User Function is available. */
if ( UF_initialize() != 0)
return ( UF_UI_CB_CONTINUE_DIALOG );
/* ---- Enter your callback code here ----- */
first_plan=NULL_TAG;
second_plan=NULL_TAG;
cylinder_face1=NULL_TAG;
cylinder_face2=NULL_TAG;
UF_OBJ_cycle_by_name (name1, [$first_plan)]
UF_OBJ_cycle_by_name (name2, [$second_plan)]
// UF_DISP_set_highlight(first_plan,1);
// UF_DISP_set_highlight(second_plan,1);
UF_OBJ_cycle_by_name (name3, [$cylinder_face1)]
UF_OBJ_cycle_by_name (name4, [$cylinder_face2)]
//====================================================================
//第一种匹配条件:选取UF_ASSEM_v16_mate和UF_ASSEM_planar_face进行匹配
//====================================================================
///////////////////////////第一个平面//////////////////////
//UF_MODL_ask_face_data (first_plan,[$type,point,dir,box,&radius,&rad_data,&norm_dir)]
ret=UF_ASSEM_ask_parent_component (first_plan, [$from_part_occ)]//获取父标志
is_occ=UF_ASSEM_is_occurrence(from_part_occ);//确定父标志类型
//TRUE = if object occurrence or a part occurrence.
//FALSE = if object is a prototype object
from_part_ins=UF_ASSEM_ask_inst_of_part_occ (from_part_occ);//获取part occurrence中instance的tag
ret=UF_ASSEM_ask_component_data (from_part_occ,part_name,refset_name,instance_name,
origin, csys_matrix, transform);
///////////////////////////第二个平面//////////////////////
ret=UF_ASSEM_ask_parent_component (second_plan, [$to_part_occ)]
to_part_ins=UF_ASSEM_ask_inst_of_part_occ (to_part_occ);
ret=UF_ASSEM_ask_component_data (to_part_occ,part_name,refset_name,instance_name,
origin, csys_matrix, transform);
//========================================================================
//第二种匹配条件:选取UF_ASSEM_center和UF_ASSEM_cylindrical_face进行匹配
//========================================================================
///////////////////////////第一个圆柱面//////////////////////
ret=UF_ASSEM_ask_parent_component (cylinder_face1, [$cylinder_from_part_occ)]
cylinder_to_part_ins=UF_ASSEM_ask_inst_of_part_occ (cylinder_from_part_occ);
ret=UF_ASSEM_ask_component_data (cylinder_to_part_occ,part_name,refset_name,instance_name,
origin, csys_matrix, transform);
///////////////////////////第二个圆柱面//////////////////////
ret=UF_ASSEM_ask_parent_component (cylinder_face2, [$cylinder_to_part_occ)]
cylinder_to_part_ins=UF_ASSEM_ask_inst_of_part_occ (cylinder_to_part_occ);
ret=UF_ASSEM_ask_component_data (cylinder_to_part_occ,part_name,refset_name,instance_name,
origin, csys_matrix, transform);
//构造配合关系
//=======================
UF_ASSEM_init_mc ([$ftf)] //初始化
//=======================
ftf.mated_object=from_part_ins;
ftf.name=NULL;
ftf.user_name=FALSE;
ftf.constraints[0].from_status = UF_ASSEM_ok;
ftf.constraints[0].to_status = UF_ASSEM_ok;
ftf.constraints[0].mate_type = UF_ASSEM_v16_mate;
ftf.constraints[0].from_type = UF_ASSEM_planar_face;
ftf.constraints[0].to_type = UF_ASSEM_planar_face;
ftf.constraints[0].from = UF_ASSEM_ask_prototype_of_occ (first_plan);
ftf.constraints[0].from_part_occ = from_part_occ;
ftf.constraints[0].to = UF_ASSEM_ask_prototype_of_occ (second_plan);
ftf.constraints[0].to_part_occ = to_part_occ;
ftf.constraints[0].offset = NULL_TAG;
ftf.constraints[0].name = "face to face";
ftf.constraints[0].user_name = TRUE;
//**********************************************
ftf.constraints[1].from_status = UF_ASSEM_ok;
ftf.constraints[1].to_status = UF_ASSEM_ok;
ftf.constraints[1].mate_type = UF_ASSEM_center; //选择同轴匹配类型
ftf.constraints[1].from_type = UF_ASSEM_cylindrical_face;//定义为选取圆周面匹配
ftf.constraints[1].to_type = UF_ASSEM_cylindrical_face;
ftf.constraints[1].from = UF_ASSEM_ask_prototype_of_occ (cylinder_face1);//获取选取对象原型的tag
ftf.constraints[1].from_part_occ = cylinder_from_part_occ; //匹配对象的part occurrence的tag
ftf.constraints[1].to = UF_ASSEM_ask_prototype_of_occ (cylinder_face2);
ftf.constraints[1].to_part_occ = cylinder_to_part_occ;
ftf.constraints[1].offset = NULL_TAG; //定义距离,可利用表达式控制
ftf.constraints[1].name = "center to center";
ftf.constraints[1].user_name = TRUE;
ftf.constraints[1].sub_type = UF_ASSEM_center_1_to_1;//选取角度和同轴对齐的适当子类型
//************************************************
ftf.num_constraints=2;
ftf.suppressed=FALSE;
ret=UF_ASSEM_solve_mc ([$ftf, &status, &dof, transform)]//条件计算
UF_get_fail_message (ret,message);
if (ret==0||status==UF_ASSEM_mc_solved)
{
ret=UF_ASSEM_apply_mc_data ([$ftf, &struct_status, &status )]//执行匹配
UF_DISP_refresh();
UF_MODL_update();
}
UF_terminate ();
/* Callback acknowledged, do not terminate dialog */
return (UF_UI_CB_CONTINUE_DIALOG);
/* or Callback acknowledged, terminate dialog. */
/* return ( UF_UI_CB_EXIT_DIALOG ); */
}
嗯,很早以前做的例子,很久没试了。
发帖有点不大灵光,先发了。有问题及时告诉一声,我会赶紧改的。 |
|