|
马上注册登录,享用更多网站功能!
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
这几天写一个函数,具体的功能是创建一个新的ug文件,并从另一个文件中读取两次部件并且加入新的文件中, 并且组装,利用axis对
axis,设定组装条件,但是中间出现一个问题,就是无法完成既定目标,编译运行,之后得到报告正常,但是打开生成文件之后发现,组装并未成功。
具体代码如下,
// build_try.cpp : Definiert den Einstiegspunkt für die Konsolenanwendung.
//
#include "stdafx.h"
#include <stdio.h>
#include <iostream>
#include <uf.h>
#include <uf_assem.h>
#include <uf_assem_types.h>
#include <uf_part.h>
#include <uf_weight.h>
#include <uf_modl.h>
#include <uf_obj.h>
#include <afx.h>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int i;
double origin[3];
double csys_matrix[6];
double transform[4][4];
int result;
tag_t AssemblyTag;
/**************************example2*****************************/
tag_t temp_tag;
/**************************example2*****************************/
UF_PART_load_status_t error_status;
UF_initialize();
int units = 1;
int layer = -1;
origin[0]=0.0;
origin[1]=0.0;
origin[2]=0.0;
csys_matrix[0]=1.0;
csys_matrix[1]=0.0;
csys_matrix[2]=0.0;
csys_matrix[3]=0.0;
csys_matrix[4]=1.0;
csys_matrix[5]=0.0;
tag_t part1;
tag_t part2;
tag_t MyPartTag1;
tag_t MyPartTag2;
UF_ASSEM_mating_condition_t mc_data;
// mc_data = new(UF_ASSEM_mating_condition_s);
// UF_ASSEM_mating_condition_t mc_data;
UF_ASSEM_init_mc(&mc_data);
UF_ASSEM_mc_structure_state_t struct_status;
UF_ASSEM_mc_status_e status;
/*********************************************************************/
result = UF_PART_new("v:\\test.prt",units,&AssemblyTag);
if (result)
cout<<("Make new assembly ......... failed\n");
else
cout<<("Make new assembly ......... OK\n");
// first part
result = UF_ASSEM_add_part_to_assembly (AssemblyTag, "v:\\test1.prt", "","ex1", origin, csys_matrix, layer, &part1, &error_status );
if (result)
cout<<("Adding ......... failed\n");
else
{
cout<<("Adding ......... OK\n");
cout<<"mytag is:"<<part1<<endl;
}
// second part
temp_tag = UF_PART_ask_part_tag("test.prt");
cout<<endl;
cout<<"************temp***********"<<endl;
cout<<"my part file name is:"<<"test.prt"<<endl;
cout<<"temptag is:"<<temp_tag<<endl;
cout<<"************temp***********"<<endl;
cout<<endl;
origin[0]=0.0;
origin[1]=0.0;
origin[2]=0.0;
csys_matrix[0]=0.0;
csys_matrix[1]=1.0;
csys_matrix[2]=0.0;
csys_matrix[3]=-1.0;
csys_matrix[4]=0.0;
csys_matrix[5]=0.0;
result = UF_ASSEM_add_part_to_assembly (AssemblyTag, "v:\\test1.prt", "",
"ex2", origin, csys_matrix, layer, &part2, &error_status );
if (result)
cout<<("Adding ......... failed\n");
else
{
cout<<("Adding ......... OK\n");
cout<<"mytag is:"<<part2<<endl;
}
result=UF_MODL_edit_exp("test1:1=120");
if (result)
cout<<("Changing parameter ......... failed\n");
else
cout<<("Changing parameter ......... OK\n");
cout<<endl;
cout<<endl;
cout<<"************show information of the parts***********"<<endl;
tag_t *occ_tag;
tag_t *part_occs;
char part_n[133], refset_name[31], instance_name[31];
UF_ASSEM_ask_occs_of_part (NULL_TAG,temp_tag,&part_occs );
i = 0;
UF_free(part_occs);
cout<<"************show information of the parts***********"<<endl;
cout<<endl;
cout<<endl;
//initial constraint condition
//UF_ASSEM_init_mc(mc_data);
mc_data.user_name = FALSE;
mc_data.name = NULL;
mc_data.mated_object = part1;
mc_data.constraints[0].mate_type = UF_ASSEM_v16_align;
mc_data.constraints[0].from_status = UF_ASSEM_ok;
mc_data.constraints[0].to_status = UF_ASSEM_ok;
mc_data.constraints[0].offset = NULL_TAG;
mc_data.constraints[0].from_type = UF_ASSEM_datum_axis;
mc_data.constraints[0].to_type = UF_ASSEM_datum_axis;
//get the axis name
tag_t current_tag = NULL;
tag_t current_tag_parent = NULL;
result=UF_OBJ_cycle_by_name ("1_Achse-z",¤t_tag);
current_tag_parent=UF_ASSEM_ask_part_occurrence(current_tag);
mc_data.constraints[0].from=current_tag;
mc_data.constraints[0].from_part_occ=current_tag_parent;
result=UF_OBJ_cycle_by_name ("1_Achse-z",¤t_tag);
current_tag_parent=UF_ASSEM_ask_part_occurrence(current_tag);
mc_data.constraints[0].to=current_tag;
mc_data.constraints[0].to_part_occ=current_tag_parent;
mc_data.constraints[0].offset=NULL_TAG;
mc_data.constraints[0].name=NULL;
mc_data.constraints[0].user_name=FALSE;
mc_data.num_constraints = 1;
mc_data.suppressed = FALSE;
// UF_ASSEM_mc_status_t status;
UF_ASSEM_dof_t dof;
result=UF_ASSEM_apply_mc_data (&mc_data,&struct_status,&status);
if (result)
cout<<("Set mating condition ............. failed \n");
else
cout<<("Set mating condition ............. OK \n");
result=UF_PART_save();
if (result)
cout<<("Save assembly ............. failed \n");
else
cout<<("Save assembly ............. OK \n");
/*********************************************************************/
UF_terminate();
cout<<"success"<<endl;
cin>>i;
return 0;
}
以下附件是源文件及新生成的文件,
希望能得到高手指点。菜鸟先在这里谢过了! |
|