iCAx开思工具箱
标题:
【求助】关于装配,源码寻求错误
[打印本页]
作者:
xyftxwd
时间:
2004-7-12 16:00
标题:
【求助】关于装配,源码寻求错误
我想做装配方面的,可是下列代码执行正确,却不见装配
//打开第一个零件
tag_t p_part = NULL_TAG;
p_part = UF_open_part();
//获得第一个零件的第一个平面
tag_t first_first_plane;
int first_first_type;
char *message = "请选择第一个零件的第一个平面";
UF_UI_selection_options_t opts;
UF_UI_mask_t mask;
int response;
tag_t view;
opts.other_options=0;
opts.reserved=NULL;
opts.num_mask_triples=1;
opts.mask_triples=[$mask]
opts.mask_triples->object_type = UF_face_type;//UF_face_type; UF_edge_type
opts.mask_triples->object_subtype=UF_all_subtype;//UF_all_subtype;
opts.mask_triples->solid_type=UF_UI_SEL_FEATURE_ANY_FACE ;//UF_UI_SEL_FEATURE_ANY_EDGE UF_UI_SEL_FEATURE_ANY_FACE;
opts.scope=UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY;//;
double cursor[3];
double point[3];
double dir[3];
double box[6];
double radius;
double rad_data;
int norm_dir;
int irc = 0;
do{
irc=UF_UI_select_single(message, [$opts, &response, &first_first_plane, cursor, &view)]
if(irc == 0)
{
//irc = UF_MODL_ask_face_type(first_first_plane,[$first_first_type)]
irc = UF_MODL_ask_face_data(first_first_plane,[$first_first_type,point,dir,box,&radius,&rad_data,&norm_dir)]
if(first_first_type == 22)
AfxMessageBox("第一个零件的第一个平面选择成功");
else
UF_DISP_set_highlight(first_first_plane,0);
}
}while(first_first_type != 22);
//打开第二个零件
tag_t c_part = NULL_TAG;
CString child_part_name;
child_part_name = Get_part_name();//得到文件名
char *refset_name=NULL;
char instance_name[]="temp";//
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;
int reAss = 0;
reAss = UF_ASSEM_add_part_to_assembly(p_part,child_part_name,refset_name,instance_name,
origin,csys_matrix,layer,[$instance,&error_status)]
c_part=UF_PART_ask_part_tag((LPSTR)(LPCTSTR)child_part_name);
//获得第二个零件的第一个平面
tag_t second_first_plane;
int second_first_type;
message = "请选择第二个零件的第一个平面";
do{
irc=UF_UI_select_single(message, [$opts, &response, &second_first_plane, cursor, &view)]
if(irc == 0)
{
irc = UF_MODL_ask_face_type(second_first_plane,[$second_first_type)]
if(second_first_type == first_first_type)
AfxMessageBox("第二个零件的第一个平面选择成功");
else
{
AfxMessageBox("请选择另一个平面");
UF_DISP_set_highlight(second_first_plane,0);
}
}
}while(!(second_first_type == first_first_type[$&response==5))]
if(response!=5)
{
AfxMessageBox("不能选择平面");
UF_terminate();
return;
}
tag_t *from_part_occ;
irc = UF_ASSEM_ask_occs_of_part(p_part,c_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];
//irc = UF_ASSEM_ask_component_data(*from_part_occ,part_name,refset_name,instance_name,origin,csys_matrix,transform);
tag_t to_part_occ;
to_part_occ = UF_ASSEM_ask_root_part_occ(p_part);
tag_t to_part_ins=UF_ASSEM_ask_inst_of_part_occ(to_part_occ);
//irc = UF_ASSEM_ask_component_data(to_part_occ,part_name,refset_name,instance_name,origin,csys_matrix,transform);
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;//; second_first_type
ftf.constraints[0].to_type=UF_ASSEM_planar_face;//;first_first_type
ftf.constraints[0].from=second_first_plane;
ftf.constraints[0].from_part_occ=*from_part_occ;
ftf.constraints[0].to=first_first_plane;
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.num_constraints=1;
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)]
char strmessage[133];
if (ret != 0)
UF_get_fail_message(ret,strmessage);
if(ret==0||status==UF_ASSEM_mc_solved)
{
ret=UF_ASSEM_apply_mc_data([$ftf,&struct_status,&status)]
UF_DISP_refresh();
ret = UF_MODL_update();
UF_DISP_refresh();
if (ret ==0)
AfxMessageBox("成功!");
}
作者:
tari
时间:
2004-7-12 16:36
两个零件都是part,没有装配体吧
from_part_occ你用下面的函数试试
from_part_occ=UF_ASSEM_ask_part_occ_of_inst(to_part_occ,instance);
from_part_ins=instance
作者:
guxiongfei
时间:
2004-7-13 15:17
int ret=UF_ASSEM_solve_mc([$ftf,&status,&dof,transform)]
这个函数有错误代码返回吗?调用ug的函数最好看看由什么错误信息返回
作者:
xyftxwd
时间:
2004-7-13 19:00
to tari:
还是不行,其最后的结果还是一样。
to guxiongfei:
j没有错误代码返回,其中的transform,dof的值已经改变,可是不能最后正确显示。
作者:
tari
时间:
2004-7-13 19:14
你两个都是part,不是装配体,并在同一个目录吗?
没有返回错误值,发现问题不是一件容易的事
作者:
xyftxwd
时间:
2004-7-13 22:47
是的,都是part,不是装配体,是在同一个目录,是不是一个目录有关系吗?我不清楚。
我这个是仿照以前的一个做的,文件名好像叫:assem_river。以前可以装配的,不知道现在怎么了,一运行就出错。那是一个螺钉装配到一个孔的例子。后悔当初没有保存好原文件。从哪个贴子下载的我都忘了。
作者:
guxiongfei
时间:
2004-7-14 10:26
你的程序是internal还是external的?清华那书上的例子是对的,你对照一下吧。
作者:
xyftxwd
时间:
2004-7-22 14:40
请问您做过吗?能否给我一个成功的例子啊?
作者:
xyftxwd
时间:
2004-8-8 10:05
怎么做装配这么难呢?
欢迎光临 iCAx开思工具箱 (https://t.icax.org/)
Powered by Discuz! X3.3