找回密码 注册 QQ登录
开思网工业级高精度在线3D打印服务

iCAx开思网

CAD/CAM/CAE/设计/模具 高清视频【积分说明】如何快速获得积分?在线3D打印服务,一键上传,自动报价 
查看: 17192|回复: 6
打印 上一主题 下一主题

ug 二次开发的问题

[复制链接]
跳转到指定楼层
1
发表于 2006-6-16 20:05:45 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
这几天写一个函数,具体的功能是创建一个新的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",&current_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",&current_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;
}


以下附件是源文件及新生成的文件,
希望能得到高手指点。菜鸟先在这里谢过了!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 赞一下!赞一下!
2
 楼主| 发表于 2006-6-16 20:32:10 | 只看该作者

马上注册,结交更多同行朋友,交流,分享,学习。

您需要 登录 才可以下载或查看,没有帐号?注册

x
3
发表于 2006-7-24 23:00:39 | 只看该作者

马上注册,结交更多同行朋友,交流,分享,学习。

您需要 登录 才可以下载或查看,没有帐号?注册

x
4
发表于 2006-8-8 13:07:18 | 只看该作者

马上注册,结交更多同行朋友,交流,分享,学习。

您需要 登录 才可以下载或查看,没有帐号?注册

x
5
发表于 2006-8-8 14:50:34 | 只看该作者

马上注册,结交更多同行朋友,交流,分享,学习。

您需要 登录 才可以下载或查看,没有帐号?注册

x
6
发表于 2006-8-8 16:04:25 | 只看该作者

马上注册,结交更多同行朋友,交流,分享,学习。

您需要 登录 才可以下载或查看,没有帐号?注册

x
7
发表于 2006-8-11 17:49:44 | 只看该作者

马上注册,结交更多同行朋友,交流,分享,学习。

您需要 登录 才可以下载或查看,没有帐号?注册

x
您需要登录后才可以回帖 登录 | 注册

本版积分规则

3D打印手板模型快速制作服务,在线报价下单!

QQ 咨询|手机版|联系我们|iCAx开思网  

GMT+8, 2024-9-22 17:35 , Processed in 0.030978 second(s), 13 queries , Gzip On, Redis On.

Powered by Discuz! X3.3

© 2002-2024 www.iCAx.org

快速回复 返回顶部 返回列表