iCAx开思工具箱
标题:
关于装配的问题:大家一起来找错误
[打印本页]
作者:
tari
时间:
2004-5-15 15:00
标题:
关于装配的问题:大家一起来找错误
下面是我写的一段关于装配的简单代码:实现功能就是自动将螺栓装配到孔中,可惜小弟刚学二次开发,里面错误多多,希望大家指正,附件里是源代码如果能把它调好,发表出来让大家学习,就更感激不尽了,^_^
作者:
tari
时间:
2004-5-15 15:18
刚刚忘了发测试部件,呵呵
作者:
ptjmy
时间:
2004-5-17 16:31
我已经调通了,代码如下:
#include "uf.h"
#include "uf_exit.h"
#include "uf_ui.h"
#include "uf_modl.h"
#include "uf_assem.h"
#include "uf_part.h"
#include "uf_object_types.h"
#include "uf_obj.h"
#include "uf_defs.h"
//----------------------------------------------------------------------------
// Activation Methods
//----------------------------------------------------------------------------
tag_t UF_open_part()
{
char filter_string[132]="*";
char filename[132];
int response;
int rc=0;
char msg[132];
tag_t part1;
rc=UF_UI_create_filebox("Open File","打开文件",filter_string," ",filename,[$response)]
if(rc)
{
UF_get_fail_message(rc,msg);
printf("error=%s\n",msg);
}
if(response==UF_UI_OK)
{
char partname[132];
UF_PART_load_status_t error_status;
strcpy(partname,filename);
UF_PART_open(partname,[$part1,&error_status)]
if(part1==NULL_TAG)
{
uc1601("打开part错误",1);
UF_PART_close_all();//退出之前关闭所有part
UF_terminate();
}
else
{ UF_PART_save();
UF_PART_set_display_part(part1);
}
}
return part1;
}
// Unigraphics Startup
// This entry point activates the application at Unigraphics startup
extern "C" DllExport void ufsta( char *param, int *returnCode, int rlen )
{
/* Initialize the API environment */
int errorCode = UF_initialize();
if ( 0 == errorCode )
{
/* TODO: Add your application code here */
tag_t parent_part;
parent_part=UF_open_part();
char *child_part_name="E:\\my_first_UG\\application\\bb.prt";
char *refset_name=NULL;
char instance_name[]="bb";
double origin[3]={0,0,0};
double csys_matrix[9]={1,0,0,0,1,0,0,0,1};
int layer=0;
tag_t instance;
UF_PART_load_status_t error_status;
UF_ASSEM_add_part_to_assembly(parent_part,child_part_name,refset_name,instance_name,
origin,csys_matrix,layer,[$instance,&error_status)]
tag_t child_part;
child_part=UF_PART_ask_part_tag(child_part_name);
tag_t first_plan;
tag_t second_plan;
tag_t feature=NULL_TAG;
int type3=UF_feature_type;
uf_list_p_t face_list=NULL;
uf_list_p_t p1=NULL;
int type1;
int n=0,n1=0;
UF_OBJ_cycle_objs_in_part(child_part,type3,[$feature)]
while(feature!=NULL_TAG)
{
UF_MODL_ask_feat_faces(feature,[$face_list)]
p1=face_list;
do
{
UF_MODL_ask_face_type(p1->eid,[$type1)]
if(type1==UF_MODL_CYLINDRICAL_FACE) n1++;
if(type1==UF_MODL_PLANAR_FACE) n++;
if(n==1) {first_plan=p1->eid;UF_DISP_set_highlight(first_plan,1);}
if(n1==2) {second_plan=p1->eid;UF_DISP_set_highlight(second_plan,1);}
p1=p1->next;
}while(p1!=NULL);
UF_OBJ_cycle_objs_in_part(child_part,type3,[$feature)]
}
tag_t *from_part_occ;
UF_ASSEM_ask_occs_of_part(parent_part,child_part,[$from_part_occ)]
tag_t from_part_ins=UF_ASSEM_ask_inst_of_part_occ(*from_part_occ);
char part_name[132+1];
double transform[4][4];
UF_ASSEM_ask_component_data(*from_part_occ,part_name,
refset_name,instance_name,origin,csys_matrix,transform);
char message[133];
message[0]='\0';
strcpy(message,"please select third plane");
UF_UI_selection_options_t opts;
UF_UI_mask_t mask;
int response;
tag_t view;
double cursor[3];
int unhightlight=0;
opts.other_options=0;
opts.reserved=NULL;
opts.num_mask_triples=2;
opts.mask_triples=[$mask]
opts.mask_triples->object_type=UF_face_type;
opts.mask_triples->object_subtype=UF_bounded_plane_subtype;
opts.mask_triples->solid_type=UF_UI_SEL_FEATURE_ANY_FACE;
opts.scope=UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY;
int type;
double point[3];
double dir[3];
double box[6];
double radius;
double rad_data;
int norm_dir;
tag_t third_plan;
do
{
int irc=UF_UI_select_single(message,[$opts,&response,&third_plan,cursor,&view)]
UF_MODL_ask_face_data(third_plan,[$type,point,dir,box,&radius,&rad_data,&norm_dir)]
if(type!=22)
{
uc1601("please select another plane",1);
UF_DISP_set_highlight(third_plan,0);
}
}
while(!(type==22[$&response==5))]
if(response!=5)
{
uc1601("not select plane",1);
UF_terminate();
return;
}
message[0]='\0';
strcpy(message,"please select fourth plane");
opts.other_options=0;
opts.reserved=NULL;
opts.num_mask_triples=1;
opts.mask_triples=[$mask]
opts.mask_triples->object_type=UF_face_type;
opts.mask_triples->object_subtype=UF_cylinder_subtype;
opts.mask_triples->solid_type=UF_UI_SEL_FEATURE_ANY_FACE;
opts.scope=UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY;
tag_t fourth_plan;
do{
int irc=UF_UI_select_single(message,[$opts,&response,&fourth_plan,cursor,&view)]
UF_MODL_ask_face_data(fourth_plan,[$type,point,dir,box,&radius,&rad_data,&norm_dir)]
if(type!=16)
{
uc1601("please select another plane",1);
UF_DISP_set_highlight(fourth_plan,0);
}
}
while(!(type==16[$&response==5))]
if(response!=5)
{
uc1601("not select plane",1);
UF_terminate();
return;
}
tag_t to_part_occ;
to_part_occ=UF_ASSEM_ask_root_part_occ(parent_part);
UF_ASSEM_mating_condition_t ftf;
UF_ASSEM_init_mc([$ftf)]
ftf.mated_object=from_part_ins;
ftf.part_occurrence=to_part_occ;
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=first_plan;
ftf.constraints[0].from_part_occ=*from_part_occ;
ftf.constraints[0].to=third_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_v16_mate;
ftf.constraints[1].from_type=UF_ASSEM_cylindrical_face;
ftf.constraints[1].to_type=UF_ASSEM_cylindrical_face;
ftf.constraints[1].from=second_plan;
ftf.constraints[1].from_part_occ=*from_part_occ;
ftf.constraints[1].to=fourth_plan;
ftf.constraints[1].to_part_occ=to_part_occ;
ftf.constraints[1].offset=NULL_TAG;
ftf.constraints[1].name="face to face";
ftf.constraints[1].user_name=TRUE;
ftf.num_constraints=2;
ftf.suppressed=FALSE;
UF_ASSEM_mc_status_t status;
UF_ASSEM_mc_structure_state_t struct_status;
UF_ASSEM_dof_t dof;
int 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_DISP_set_highlight(third_plan,0);
UF_DISP_set_highlight(fourth_plan,0);
/* Terminate the API environment */
errorCode = UF_terminate();
}
/* Print out any error messages */
 
rintErrorMessage( errorCode );
}
作者:
murongjun
时间:
2006-2-14 20:24
谢谢,看来你的程序,我终于把我的程序调通了.
作者:
zhb7081
时间:
2006-3-9 18:47
有没有办法自动装配两个相同的零件进去呀,而且这个零件装配的两个地方约束对象都一样,有办法吗?
作者:
xxjy2000
时间:
2010-12-8 09:58
呵呵,谢谢楼主了
作者:
siyilee
时间:
2011-12-19 11:53
很好的学习资料
欢迎光临 iCAx开思工具箱 (https://t.icax.org/)
Powered by Discuz! X3.3