【Creo5.0二次开发参数化】选择装配
通过用户选择装配平面,自动装配
装配函数
/*------------------------------------------------------------------*\
Application includes
\*-------------------------------------- ---------------------------*/
#include <TestError.h>
#include <ProMessage.h>
#include <ProSolid.h>
#include "GetDimension.h"
#include <stdio.h>
#include "MCFdialog.h"
#include <ProModelitem.h>
#include <ProAsmcomp.h> // 新添的头文件
#include <ProWstring.h>
/// <summary>
/// 通过用户选择装配平面,自动装配
/// </summary>
/// <param name="asm_model"> 组装模型</param>
/// <param name="comp_model">装配元件模型</param>
/// <returns></returns>
ProError UserAssembleByDatums(ProAssembly asm_model,ProSolid comp_model)
{ProError status;ProName comp_datums[3];ProMatrix identity_matrix = { { 1.0, 0.0, 0.0, 0.0 },{0.0, 1.0, 0.0, 0.0},{0.0, 0.0, 1.0, 0.0},{0.0, 0.0, 0.0, 1.0} };ProAsmcomp asmcomp;ProAsmcompconstraint* constraints;ProAsmcompconstraint constraint;int i;ProBoolean interact_flag = PRO_B_FALSE;ProModelitem asm_datum, comp_datum;ProSelection asm_sel, comp_sel;ProAsmcomppath comp_path;ProIdTable c_id_table;c_id_table[0] = -1;//Set up the arrays of datum names //参考平面,这里的名称要和自己的装配元件的平面名称一样,才能找到ProStringToWstring(comp_datums[0], "FRONT");ProStringToWstring(comp_datums[1], "TOP");ProStringToWstring(comp_datums[2], "RIGHT");//Package the component initially//把装配元件添加在组装元件之中,identity_matrix表示加载的初始位置,(在空间上)ProAsmcompAssemble(asm_model, comp_model, identity_matrix, &asmcomp);//Prepare the constraints arrayProArrayAlloc(0, sizeof(ProAsmcompconstraint), 1,(ProArray*)&constraints);//用户选择装配平面//每选择一个装配平面,就和一个元件平面组成一个约束for (i = 0; i < 3; i++){//Find the component datum 获取平面模型status = ProModelitemByNameInit(comp_model, PRO_SURFACE,comp_datums[i], &comp_datum);if (status != PRO_TK_NO_ERROR){interact_flag = PRO_B_TRUE;continue;}//Allocate the referencesProSelectionAlloc(NULL, &comp_datum, &comp_sel);int n_sel = 0;ProSelection* sel;//用户选择平面status = ProSelect("surface", 1, NULL, NULL, NULL, NULL, &sel, &n_sel);if (status != PRO_TK_NO_ERROR || n_sel < 0)return (PRO_TK_USER_ABORT);ProSelectionCopy(sel[0], &asm_sel);//Allocate and fill the constraint.填充约束,循环三次,三个元件平面和三个用户选择的平面ProAsmcompconstraintAlloc(&constraint);ProAsmcompconstraintTypeSet(constraint, PRO_ASM_ALIGN);ProAsmcompconstraintAsmreferenceSet(constraint, asm_sel,PRO_DATUM_SIDE_YELLOW);ProAsmcompconstraintCompreferenceSet(constraint, comp_sel,PRO_DATUM_SIDE_YELLOW);ProArrayObjectAdd((ProArray*)&constraints, -1, 1, &constraint);} //把三个约束放进组装里完成装配status = ProAsmcompConstraintsSet(NULL, &asmcomp, constraints);ProSolidRegenerate((ProSolid)asmcomp.owner, PRO_REGEN_CAN_FIX);if (interact_flag){ProAsmcompConstrRedefUI(&asmcomp);}return (PRO_TK_NO_ERROR);
}
测试函数
//选择装配,从当前内存或路径通过模型名称选择一个模型,调用装配函数
void UserAssembleTest() {// 在当前内存中或路径下找到 对应名称的模型的句柄ProError status;ProMdlType model_type = PRO_MDL_PART;ProMdl* session_mdls, find_mdl;int mdls_counts;ProName target_name;ProAssembly assembly;ProMdlCurrentGet((ProMdl*)&assembly);ProStringToWstring(target_name, "PRT0002");ProBoolean was_found = PRO_B_FALSE;//在当前内存中查找匹配的模型,工作区,找不到试试设置工作区status = ProSessionMdlList(model_type, &session_mdls, &mdls_counts);if (status == PRO_TK_NO_ERROR){ProName mdl_name;for (int i = 0; i < mdls_counts; i++){status = ProMdlNameGet(session_mdls[i], mdl_name);AfxMessageBox(mdl_name);int compare_result = 1;ProWstringCompare(target_name, mdl_name, PRO_VALUE_UNUSED,&compare_result);if (compare_result == 0){//找到调用装配find_mdl = &session_mdls[i];UserAssembleByDatums(assembly, (ProSolid)session_mdls[i]);// ProMdlDisplay(session_mdls[i]);was_found = PRO_B_TRUE;}}ProArrayFree((ProArray*)&session_mdls);}// if not found, try to retrieve it from diskif (was_found == PRO_B_FALSE){status = ProMdlnameRetrieve(target_name, (ProMdlfileType)model_type, &find_mdl);if (status == PRO_TK_NO_ERROR){// ProMdlDisplay(find_mdl);}}}
【Creo5.0二次开发参数化】选择装配相关推荐
- CREO5.0二次开发+VS2019配置详解
CREO5.0+VS2019配置更新 一.CREO5.0 配置 二.Visual Studio 2019配置 新建MFC DLL项目 文件>新建>项目,选择MFC DLL,如下图所示 项目 ...
- scratch3.0 二次开发-基本介绍(第一章)
scratch3.0系列章节列表 scratch3.0 二次开发-基本介绍(第一章) scratch3.0二次开发运行scratch-gui项目并了解工程结构(第二章) scratch3.0二次自定义 ...
- c# cad二次开发 通过选择txt文件将自动转换成多段线
c# cad二次开发 通过选择txt文件将自动转换成多段线,txt样式如下 using System; using System.Collections.Generic; using System.T ...
- PROE4.0二次开发基视频教程从入门到精通教程
PROE4.0二次开发基视频教程从入门到精通教程 链接:https://pan.baidu.com/s/19UVFQz351Qa4tpWfPw3jRg 提取码:x7g8
- 泛微 e-cology 9.0 二次开发
泛微 e-cology 9.0 二次开发 1.前端开发环境搭建(ecode代码编辑器) 请访问地址:链接 2.后端开发环境搭建 请访问地址:链接 3.E9流程表单前端接口API 请访问地址:链接
- wap六感程序二次开发_Cscms v4.0 二次开发y2002音乐网站程序
Cscms v4.0 二次开发y2002音乐网站程序 源码简介: 修复了多处问题,比网上流传的版本要完整很多. 程序包括pc+wap,页面功能和原y2002基本一样. 程序比较完整了,但还是会有bug ...
- NX二次开发-UFUN遍历装配树根下面的所有子组件UF_ASSEM_ask_part_occ_children
NX二次开发-UFUN遍历装配树根下面的所有子组件UF_ASSEM_ask_part_occ_children NX9+VS2012#include <uf.h> #include < ...
- NX二次开发-UFUN获得装配树根tag UF_ASSEM_ask_root_part_occ
NX二次开发-UFUN获得装配树根tag UF_ASSEM_ask_root_part_occ NX9+VS2012#include <uf.h> #include <uf_asse ...
- 最新微信hook3.0二次开发C#源码介绍
江南鹤微信hook二次开发源代码,hook部分是基于c++进行开发,运行稳定,无隐含bug,接收和发送消息的速度达到毫秒级.调用部分是c#进行开发的. 本套代码出自拥有10年开发经验的大神级程序猿之手 ...
最新文章
- SSH框架总结(框架分析+环境搭建+实例源代码下载)
- 抽象类 VS 接口 (3)
- 目测这个APP要火啦,只有一个功能就要干倒小咖秀?
- spring mvc重定向_Spring的Web MVC –重定向到内存泄漏
- android monitor不能查看/data目录
- 口述完SpringMVC执行流程,面试官就让同事回家等消息了
- 大爷与支付宝同名,曾想状告阿里巴巴侵权,现在过得怎么样
- 数据库添加一个列的唯一约束
- LINUX下解决netstat查看TIME_WAIT状态过多问题
- 9. grouped product
- Java——可能的文本题
- oracle 九阴真精,《九阴真经》真的很强吗?其实它杂而不精,顶级高手都不愿意用...
- NLP算法-情绪分析-snowNLP算法库
- html5 获取本机号码,如何获取本机手机号码
- 数据分析学习总结笔记06:T检验的原理和步骤
- win7计算机不能设置双屏怎么回事,win7系统怎么设置双屏显示 win7电脑双屏显示功能使用方法...
- 京东淘宝天猫API销量接口
- 百度地图--绘制自定义铁路线
- javaee学习之路(十五)JSP编程总结
- 100比例怎么用计算机算,1:100的 比例怎么算