iCAx开思工具箱
标题:
【原创】再续Pro/E的二次开发
[打印本页]
作者:
七剑下天山
时间:
2003-12-30 11:57
标题:
【原创】再续Pro/E的二次开发
利用对话框资源文件创建如图所示的对话框,
作者:
七剑下天山
时间:
2003-12-30 12:00
根据对话框输入的参数,创建如图特征
作者:
七剑下天山
时间:
2003-12-30 12:03
特征由如下草图旋转而成,对话框中参数的含义也在草图中标注出。
作者:
七剑下天山
时间:
2003-12-30 12:04
草图:
作者:
七剑下天山
时间:
2003-12-30 12:06
创建步骤:
(1)新建DLL
作者:
七剑下天山
时间:
2003-12-30 12:07
(2)选择使用共享MFC
作者:
七剑下天山
时间:
2003-12-30 12:09
(3)设置pro/e工作路径(个人情况不同设置也不同)
作者:
七剑下天山
时间:
2003-12-30 12:36
(4)编写代码,程序中有详细的注释,不多解释
/*======================================*\
头文件
\*======================================*/
#include "
roToolkit.h"
#include "
roUtil.h"
#include "
roMenu.h"
#include "
roMenubar.h"
#include "
roUIDialog.h"
#include "
roUIPushbutton.h"
#include "
roUICheckbutton.h"
#include "
roUIList.h"
#include "
roUISpinbox.h"
#include "
roUILabel.h"
#include "ProUIRadiogroup.h"
#include "ProArray.h"
#include "ProUIInputpanel.h"
#include "malloc.h"
#include "stdlib.h"
#include "Pro2dEntdef.h"
#include "ProElement.h"
#include "ProFeatForm.h"
#include "ProFeatType.h"
#include "ProStdSection.h"
#include "ProWindows.h"
#include "ProModelitem.h"
#include "ProRevolve.h"
#include "ProSolid.h"
#include "ProElempath.h"
#include <ProDtmPln.h>
/*===================================*\
函数声明,各函数的功能后面再描述
\*==================================*/
void OK_Action(char*,char*,ProAppData);
void Cancel_Action(char*,char*,ProAppData);
void Check_Action(char*,char*,ProAppData);
void ListSelect_Action(char*,char*,ProAppData);
int ShowDialog();
static uiCmdAccessState AccessDefault(uiCmdAccessMode);
void ListSelectAction(char*,char*,ProAppData);
void CheckEditSetAction(char*,char*,ProAppData);
void usrCreateRevolveFeat(ProGeomitem,ProGeomitem,
ProGeomitem,int*,double);
void usrElemtreeElementAdd(ProElemId,ProElement,void*,
ProValueDataType,ProElement*);
int usrSectionGet(ProFeature*,int,ProSection*);
int usrSectionBuild(ProGeomitem *,ProGeomitem*,
ProSection,int,int*);
int usrCreateSection(ProSection,int,int*);
void usrFeatDel();
void CreatDefDtm();
void UsrGeomitemPlnGet(ProFeature,ProGeomitem *);
int DefaultDtmActFn();
/*==========================================*\
声明全局变量
\*==========================================*/
static int D1[]={60,65,70,75,80},//列表中D1一列的数值
D2[]={45,50,55,60,65}, //D2列的数值
L1[]={100,120,140,160,200},//L1列的数值
L2[]={80,100,120,140,180};//L2列的数值
static int n_line=5;//列表的行数
char *dialog_name="mydlg";//对话框名,资源文件要与之同名
ProGeomitem front,top,right; //参考平面
ProFeature feature;//保存程序创建的特征
int dim[4];//用来保存列表框中被选中的一行的参数值
/*===========================================*\
function: user_initialize()
添加菜单,菜单名为Show Dialog;菜单响应函数为ShowDialog()
\*===========================================*/
extern "C" int user_initialize()
{
ProError status;
ProFileName mf;
uiCmdCmdId cmd_id;
ProStringToWstring(mf,"usrmsg.txt");
status=ProCmdActionAdd("Show Dialog",
(uiCmdCmdActFn)ShowDialog,uiCmdPrioDefault,
AccessDefault,PRO_B_TRUE,PRO_B_TRUE,[$cmd_id)]
status=ProMenubarmenuPushbuttonAdd("Utilities","Show Dialog",
"USER Menu","USER Menu Help",
NULL,PRO_B_TRUE,cmd_id,mf);
return status;
}
/*===============================================================*\
function: user_terminate()
\*===============================================================*/
extern "C" void user_terminate()
{
}
/*==========================================*\
function: ShowDialog()菜单响应函数
\*==========================================*/
int ShowDialog()
{
ProError status;
int Dialog_status;
char** names; //列表框各行的名称,作为程序访问指定行的标识
wchar_t** label;//列表框每一行的标签,标签就是每一行显示的内容
/*----------------------------------
为两个数组分配内存
-----------------------------------*/
ProArrayAlloc(n_line,sizeof(wchar_t*),1,(ProArray*)[$labels)]
ProArrayAlloc(n_line,sizeof(char*),1,(ProArray*)[$names)]
/*----------------------------------
数组中各元素初始化
-----------------------------------*/
for(int i=0;i<n_line;i++)
{
labels
= (wchar_t *)calloc(PRO_NAME_SIZE, sizeof(wchar_t));
names
= (char *)calloc(PRO_NAME_SIZE, sizeof(char));
}
/*---------------------------------------------------
列表框选项名赋值,每一行的名字分别为1、2、3、4、5
----------------------------------------------------*/
names[0]="1";
names[1]="2";
names[2]="3";
names[3]="4";
names[4]="5";
/*---------------------------------------------------------
列表框标签赋值,如果每行有多列各列之间用tab键或者\t隔开,
不是空格
----------------------------------------------------------*/
ProStringToWstring(labels[0],"60 45 100 80");
ProStringToWstring(labels[1],"65 50 120 100");
ProStringToWstring(labels[2],"70\t55\t140\t120");
ProStringToWstring(labels[3],"75\t60\t160\t140");
ProStringToWstring(labels[4],"80\t65\t200\t180");
/*----------------------------------------
把对话框资源加载进内存
----------------------------------------*/
status=ProUIDialogCreate(dialog_name,dialog_name);
if(status!=PRO_TK_NO_ERROR)
{
AfxMessageBox("Dialog Create error!");
return status;
}
/*---------------------------------------
设置列表框选项名
---------------------------------------*/
ProUIListNamesSet(dialog_name,"List1",n_line,names);
/*---------------------------------------
设置列表框各行标签
--------------------------------------*/
ProUIListLabelsSet(dialog_name,"List1",n_line,labels);
/*----------------------------------------
释放内存
----------------------------------------*/
ProArrayFree((ProArray*)[$names)]
ProArrayFree((ProArray*)[$labels)]
/*----------------------------------------
设置微调按钮(SpinBox)的默认值
----------------------------------------*/
ProUISpinboxIntegerSet(dialog_name,"SpinBoxD1",D1[0]);
ProUISpinboxIntegerSet(dialog_name,"SpinBoxD2",D2[0]);
ProUISpinboxIntegerSet(dialog_name,"SpinBoxL1",L1[0]);
ProUISpinboxIntegerSet(dialog_name,"SpinBoxL2",L2[0]);
/*-------------------------------------
设定对话框元件动作函数
---------------------------------------*/
//设置OK按钮的动作函数
ProUIPushbuttonActivateActionSet(dialog_name,"OK",
OK_Action,NULL);
//设置Cancel按钮的动作函数
ProUIPushbuttonActivateActionSet(dialog_name,"Cancel",
Cancel_Action,NULL);
//设置列表框选项的动作函数
ProUIListSelectActionSet(dialog_name,"List1",
ListSelectAction,NULL);
//设置CheckButton的动作函数
ProUICheckbuttonActivateActionSet(dialog_name,
"CheckEditSet",CheckEditSetAction,NULL);
/*------------------------------------
显示激活对话框
------------------------------------*/
status=ProUIDialogActivate(dialog_name,[$Dialog_status)]
if(status!=PRO_TK_NO_ERROR)
{
AfxMessageBox("Dialog Activate error!");
return status;
}
/*------------------------------------
从内存中清除对话框资源
-------------------------------------*/
status=ProUIDialogDestroy(dialog_name);
if(status!=PRO_TK_NO_ERROR)
{
AfxMessageBox("Dialog destroy erroe!");
return status;
}
return TRUE;
}
/*==========================================*\
function: AccessDefault()
\*==========================================*/
static uiCmdAccessState AccessDefault(uiCmdAccessMode
access_mode)
{
return (ACCESS_AVAILABLE);
}
/*===========================================*\
function: Cancel_Action() Cancel按钮的动作函数定义
功能:退出对话框
\*==========================================*/
void Cancel_Action(char* dialog,char* componets,ProAppData data)
{
ProUIDialogExit(dialog_name,1);
}
/*===========================================*\
function: ListSelectAction() 列表框选项的动作函数定义
功能:当选择列表框某一行时,将这一行的各个参数显示
在相应的SpinBox中
\*========================================*/
void ListSelectAction(char* dialog,char* component,
ProAppData data)
{
char** names;//列表框名称
int n_names;//列表框标签
int i;
ProBoolean set;//Checkbutton是否被选中的标志
ProArrayAlloc(0,sizeof(char*),1,(ProArray*)[$names)]//为数组分配内存
//确定选择的列表框选项名
ProUIListSelectednamesGet(dialog,component,[$n_names,&names)]
//n_names表示选择的项数,本例中只能选择一项
if(n_names!=1)
{
return;
}
//获得Checkbutton的状态
ProUICheckbuttonGetState(dialog,"CheckEditSet",[$set)]
//如果Checkbutton被设置,则允许修改SpinBox中的参数
if(set)
{
//将所选列表框中的参数写入Spinbox
i=atoi(names[0])-1;
ProUISpinboxIntegerSet(dialog_name,"SpinBoxD1",D1
);
ProUISpinboxIntegerSet(dialog_name,"SpinBoxD2",D2
);
ProUISpinboxIntegerSet(dialog_name,"SpinBoxL1",L1
);
ProUISpinboxIntegerSet(dialog_name,"SpinBoxL2",L2
);
}
}
/*===========================================*\
function:CheckEditSetAction() Checkbutton动作函数设置
功能:当被设置时允许修改Spinbox中的内容,反之不允许修改
\*===========================================*/
void CheckEditSetAction(char* dialog,char* component,
ProAppData data)
{
ProBoolean set;//状态标志
ProUICheckbuttonGetState(dialog,component,[$set)]//获取Chenkbutton状态
if(set)//如果被设置
{
ProUISpinboxEditable(dialog,"SpinBoxD1");//四个Spinbox
ProUISpinboxEditable(dialog,"SpinBoxD2");//设置为可用
ProUISpinboxEditable(dialog,"SpinBoxL1");//
ProUISpinboxEditable(dialog,"SpinBoxL2");//
ProUISpinboxIncrementSet(dialog,"SpinBoxD1",1);//微调按钮
ProUISpinboxIncrementSet(dialog,"SpinBoxD2",1);//的微调量
ProUISpinboxIncrementSet(dialog,"SpinBoxL1",1);//设置为1
ProUISpinboxIncrementSet(dialog,"SpinBoxL2",1);//
}
else//如果没设置
{
ProUISpinboxReadOnly(dialog,"SpinBoxD1");//四个Spinbox
ProUISpinboxReadOnly(dialog,"SpinBoxD2");//设置位
ProUISpinboxReadOnly(dialog,"SpinBoxL1");//只读
ProUISpinboxReadOnly(dialog,"SpinBoxL2");//
ProUISpinboxIncrementSet(dialog,"SpinBoxD1",0);//微调按钮
ProUISpinboxIncrementSet(dialog,"SpinBoxD2",0);//的微调量
ProUISpinboxIncrementSet(dialog,"SpinBoxL1",0);//设置为0,即
ProUISpinboxIncrementSet(dialog,"SpinBoxL2",0);//微调按钮失去作用
}
}
/*=============================================================*\
function: OK_Action() OK按钮的动作函数设置
功能:读取Spinbox中的参数值,然后调用usrCreateRevolveFeat()创建
旋转特征
\*==========================================================*/
void OK_Action(char* dialog,char* componets,ProAppData data)
{
//获得SpinBox输入
ProUISpinboxIntegerGet(dialog,"SpinBoxD1",[$dim[0])]
ProUISpinboxIntegerGet(dialog,"SpinBoxD2",[$dim[1])]
ProUISpinboxIntegerGet(dialog,"SpinBoxL1",[$dim[2])]
ProUISpinboxIntegerGet(dialog,"SpinBoxL2",[$dim[3])]
if (DefaultDtmActFn())//创建基准面
{
usrFeatDel();//删除旧特征
ProUIDialogExit(dialog,1);//退出对话框
usrCreateRevolveFeat(top,front,right,dim,360);//创建新特征
}
}
/*============================================================*\
function: usrCreateRevolveFeat()
功能:填充旋转特征元素树,以创建旋转特征
\*=============================================================*/
void usrCreateRevolveFeat(ProGeomitem BasePln, //(In)草绘平面
ProGeomitem PlnRef1, //(In)参照平面1
ProGeomitem PlnRef2, //(In)参照平面2
int *dimValue, //(In)截面数据数组
double angle) //(In)旋转角度
{
ProError status;
ProSolid solid;
ProSection section;
ProElement elem_tree, element, stdsec_elem, setup_elem,
angle_elem,anglefrom_elem,angleto_elem, secpln_elem;
ProFeatureCreateOptions opts[1];
ProModelitem modelitem;
ProSelection sel;
ProErrorlist errors;
ProMdlCurrentGet((ProMdl*)[$solid)]
/*------------------------------------------------------------*\
为特征树分配内存
\*------------------------------------------------------------*/
ProElementAlloc(PRO_E_FEATURE_TREE, [$elem_tree)]
/*------------------------------------------------------------*\
向特征树添加特征类型元素
\*-----------------------------------------------------------*/
int ivalue=PRO_FEAT_PROTRUSION;
usrElemtreeElementAdd(PRO_E_FEATURE_TYPE,elem_tree,
[$ivalue,PRO_VALUE_TYPE_INT,&element)]
/*-------------------------------------------------------------*\
向特征树添加特征形式元素
\*------------------------------------------------------------*/
ivalue=PRO_REVOLVE;
usrElemtreeElementAdd(PRO_E_FEATURE_FORM,elem_tree,
[$ivalue,PRO_VALUE_TYPE_INT,&element)]
/*-------------------------------------------------------------*\
向特征树添加标准截面元素
\*------------------------------------------------------------*/
ProElementAlloc(PRO_E_STD_SECTION, [$stdsec_elem)]
ProElemtreeElementAdd(elem_tree, NULL, stdsec_elem);
/*------------------------------------------------------------*\
向特征树添加标准截面设置元素
\*-----------------------------------------------------------*/
ProElementAlloc(PRO_E_STD_SEC_SETUP, [$setup_elem)]
ProElemtreeElementAdd(stdsec_elem, NULL, setup_elem);
/*------------------------------------------------------------*\
向特征树添加草绘平面元素
\*------------------------------------------------------------*/
ProElementAlloc(PRO_E_STD_SECTION_PLANE, [$secpln_elem)]
ProElemtreeElementAdd(setup_elem, NULL, secpln_elem);
/*------------------------------------------------------------*\
向特征树添加草绘平面设置元素
\*-----------------------------------------------------------*/
ProSelectionAlloc(NULL, [$BasePln, &sel)]
usrElemtreeElementAdd(PRO_E_STD_SEC_PLANE,secpln_elem,
[$sel,PRO_VALUE_TYPE_SELECTION,&element)]
ProSelectionFree([$sel)]
/*-----------------------------------------------------------*\
向特征树添加草绘平面视图方向设置元素
\*-----------------------------------------------------------*/
ivalue=PRO_SEC_VIEW_DIR_SIDE_ONE;
usrElemtreeElementAdd(PRO_E_STD_SEC_PLANE_VIEW_DIR,secpln_elem,
[$ivalue,PRO_VALUE_TYPE_INT,&element)]
/*---------------------------------------------------------------*\
向特征树添加草绘平面定位方向设置元素
\*---------------------------------------------------------------*/
ivalue=PRO_SEC_ORIENT_DIR_UP;
usrElemtreeElementAdd(PRO_E_STD_SEC_PLANE_ORIENT_DIR,secpln_elem,
[$ivalue,PRO_VALUE_TYPE_INT,&element)]
/*---------------------------------------------------------------*\
向特征树添加草绘平面定位方向参照面设置元素
\*---------------------------------------------------------------*/
ProSelectionAlloc(NULL, [$PlnRef1, &sel)]
usrElemtreeElementAdd(PRO_E_STD_SEC_PLANE_ORIENT_REF,secpln_elem,
[$sel,PRO_VALUE_TYPE_SELECTION,&element)]
ProSelectionFree([$sel)]
/*---------------------------------------------------------------*\
向特征树添加标准截面草绘元素
\*---------------------------------------------------------------*/
ivalue=PRO_SEC_SKETCH;
usrElemtreeElementAdd(PRO_E_STD_SEC_METHOD,setup_elem,
[$ivalue,PRO_VALUE_TYPE_INT,&element)]
/*---------------------------------------------------------------*\
创建非完全特征
\*---------------------------------------------------------------*/
ProMdlCurrentGet((ProMdl*)[$solid)]
ProMdlToModelitem(solid, [$modelitem)]
ProSelectionAlloc(NULL, [$modelitem, &sel)]
opts[0] = PRO_FEAT_CR_INCOMPLETE_FEAT;
status=ProFeatureCreate(sel, elem_tree, opts, 1, [$feature, &errors)]
if(status!=PRO_TK_NO_ERROR)
AfxMessageBox("create incomplete feature error");
ProSelectionFree([$sel)]
/*---------------------------------------------------------------*\
从数据库中获得截面元素
\*---------------------------------------------------------------*/
usrSectionGet([$feature,PRO_E_STD_SECTION,§ion)]
/*---------------------------------------------------------------*\
构建和求解截面
\*---------------------------------------------------------------*/
usrSectionBuild([$PlnRef1, &PlnRef2, section,0,dimValue)]
/*---------------------------------------------------------------*\
将草绘器元素添加到特征元素树中
\*---------------------------------------------------------------*/
usrElemtreeElementAdd(PRO_E_SKETCHER,stdsec_elem,
[$section,PRO_VALUE_TYPE_POINTER,&element)]
/*---------------------------------------------------------------*\
旋转角度定义
\*---------------------------------------------------------------*/
ProElementAlloc(PRO_E_REV_ANGLE, [$angle_elem)]
ProElemtreeElementAdd(elem_tree, NULL, angle_elem);
/*---------------------------------------------------------------*\
起始面定义
\*---------------------------------------------------------------*/
ProElementAlloc(PRO_E_REV_ANGLE_FROM, [$anglefrom_elem)]
ProElemtreeElementAdd(angle_elem, NULL, anglefrom_elem);
/*---------------------------------------------------------------*\
旋转形式为给定角度
\*---------------------------------------------------------------*/
ivalue=PRO_REV_ANG_FROM_ANGLE;
usrElemtreeElementAdd(PRO_E_REV_ANGLE_FROM_TYPE,anglefrom_elem,
[$ivalue,PRO_VALUE_TYPE_INT,&element)]
/*---------------------------------------------------------------*\
角度值设置
\*---------------------------------------------------------------*/
double anglefrom=0;
usrElemtreeElementAdd(PRO_E_REV_ANGLE_FROM_VAL,anglefrom_elem,
[$anglefrom,PRO_VALUE_TYPE_DOUBLE,&element)]
/*--------------------------------------------------------------*\
终止面定义
\*---------------------------------------------------------------*/
ProElementAlloc(PRO_E_REV_ANGLE_TO, [$angleto_elem)]
ProElemtreeElementAdd(angle_elem, NULL, angleto_elem);
/*---------------------------------------------------------------*\
终止面类型
\*--------------------------------------------------------------*/
ivalue=PRO_REV_ANG_TO_ANGLE;
usrElemtreeElementAdd(PRO_E_REV_ANGLE_TO_TYPE,angleto_elem,
[$ivalue,PRO_VALUE_TYPE_INT,&element)]
/*---------------------------------------------------------------*\
终止面角度值
\*---------------------------------------------------------------*/
usrElemtreeElementAdd(PRO_E_REV_ANGLE_TO_VAL,angleto_elem,
[$angle,PRO_VALUE_TYPE_DOUBLE,&element)]
/*--------------------------------------------------------------------*\
向特征元素树添加新的角度定义元素后重定义特征
\*--------------------------------------------------------------------*/
status=ProFeatureRedefine(NULL, [$feature, elem_tree, opts, 1, &errors)]
if(status!=PRO_TK_NO_ERROR)
AfxMessageBox("redefine erroe");
if(status==PRO_TK_BAD_INPUTS)
AfxMessageBox("bad,input");
ProSectionFree([$section)]
/*---------------------------------------------------
重新调整窗口
---------------------------------------------------*/
int wnd;
ProWindowCurrentGet([$wnd)]
ProWindowRefit(wnd);
}
/*===============================================================*\
函数: UsrElemtreeElementAdd()
功能:设置特征元素之值,并将特征元素添加到特征元素树中
\*=================================================================*/
void usrElemtreeElementAdd(ProElemId id,//(In)特征元素标识符
ProElement parent, //(In)上级元素
void *value, //(In)特征元素值
ProValueDataType type,//(In)特征元素值类型
ProElement *element //(In)特征元素
)
{
ProValueData value_data;
ProValue pvalue;
value_data.type = type;
//特征元素值类型转换
switch(type)
{
case PRO_VALUE_TYPE_INT :
value_data.v.i = *(int*)value;
break;
case PRO_VALUE_TYPE_DOUBLE :
value_data.v.d = *(double*)value;
break;
case PRO_VALUE_TYPE_POINTER :
value_data.v.p = *(void**)value;
break;
case PRO_VALUE_TYPE_STRING :
value_data.v.s = *(char**)value;
break;
case PRO_VALUE_TYPE_WSTRING :
value_data.v.w = *(wchar_t**)value;
break;
case PRO_VALUE_TYPE_SELECTION :
value_data.v.r = *(ProSelection*)value;
break;
case PRO_VALUE_TYPE_TRANSFORM :
value_data.v.t = *(double***)value;
break;
case PRO_VALUE_TYPE_BOOLEAN :
value_data.v.i = *(int*)value;
break;
}
//设置特征树元素之值
ProElementAlloc(id, element);
ProValueAlloc([$pvalue)]
ProValueDataSet(pvalue, [$value_data)]
ProElementValueSet(*element, pvalue);
//将特征元素添加到特征元素树中
ProElemtreeElementAdd (parent, NULL, *element);
}
/*================================================================*\
FUNCTION : usrSectionGet()
从指定特征的元素树中选出草绘器(PRO_E_SKETCHER)元素之值
\*================================================================*/
int usrSectionGet(ProFeature *feature, //(In) 特征句柄
int elemId, //(In) 截面标识符
ProSection *section) //(Out) 截面元素
{
ProError status;
ProElempath path;
ProElempathItem path_items[2];
ProValue value;
ProValueData value_data;
*section = NULL;
//设置特征截面元素的路径
path_items[0].type = PRO_ELEM_PATH_ITEM_TYPE_ID;
path_items[0].path_item.elem_id = elemId;
path_items[1].type = PRO_ELEM_PATH_ITEM_TYPE_ID;
path_items[1].path_item.elem_id = PRO_E_SKETCHER;
ProElempathAlloc([$path)]
ProElempathDataSet (path, path_items, 2);
//从指定特征中得到路径为path的元素值(非透明的ProValue对象)
status =ProFeatureElemValueGet(feature, path, [$value)]
if(status != PRO_TK_NO_ERROR)
{
AfxMessageBox("get path error");
return(0);}
ProElempathFree([$path)]
//从非透明的ProValue对象得到用户可以访问的数据对象ProValueData
ProValueDataGet(value, [$value_data)]
//获得截面元素指针
*section = (ProSection)value_data.v.p;
return(1);
}
/*==================================================================*\
function: usrSectionBuild()
功能:生成截面草图并求解
\*================================================================*/
int usrSectionBuild(ProGeomitem *refPln1,//(In) 草绘截面参照基准1
ProGeomitem *refPln2, //(In) 草绘截面参照基准2
ProSection section, //(In) 截面元素
int index, //(In) 草图序号
int *dimValue) //(In) 截面数据数组
{
ProSelection sel;
int ent_id;
ProWSecerror serrors;
ProError status;
/*--------------------------------------------------------------------
调用UsrCreateSection()函数作截面草图
--------------------------------------------------------------------*/
if(!usrCreateSection(section,index,dimValue))
{
AfxMessageBox("Section Error!");
return(0);
}
/*--------------------------------------------------------------------
生成参照基准
--------------------------------------------------------------------*/
ProSelectionAlloc(NULL, refPln1, [$sel)]
status=ProSectionEntityFromProjection(section, sel, [$ent_id)]
if(status!=PRO_TK_NO_ERROR)
AfxMessageBox("生成参照基准1出错");
ProSelectionFree([$sel)]
ProSelectionAlloc(NULL, refPln2, [$sel)]
status=ProSectionEntityFromProjection(section, sel, [$ent_id)]
if(status!=PRO_TK_NO_ERROR)
AfxMessageBox("生成参照基准2出错");
ProSelectionFree([$sel)]
/*--------------------------------------------------------------------
自动标注截面
--------------------------------------------------------------------*/
ProSecerrorAlloc([$serrors)]
status=ProSectionAutodim(section, [$serrors)]
if(status!=PRO_TK_NO_ERROR)
AfxMessageBox("自动标注截面出错");
ProSecerrorFree([$serrors)]
return(1);
}
/*===================================================================*\
function: usrCreateSection()
功能:创建截面
\*==============================================================*/
int usrCreateSection(ProSection section,int index,int *dimValue)
{
Pro2dLinedef line[6];
int line_id[6];
double PointX[6],PointY[6];
int i;
switch (index)
{
case 0: //计算截面上各点坐标
PointX[0]=0;
PointY[0]=0;
PointX[1]=PointX[0];
PointY[1]=PointY[0]+dimValue[2]-dimValue[3];
PointX[2]=PointX[0]-dimValue[1]/2;
PointY[2]=PointY[1];
PointX[3]=PointX[2];
PointY[3]=dimValue[2];
PointX[4]=-dimValue[0]/2;
PointY[4]=PointY[3];
PointX[5]=PointX[4];
PointY[5]=PointY[0];
for (i=0;i<6;i++)
{//作草图
line
.end1[0]=PointX
;
line
.end1[1]=PointY
;
line
.end2[0]=PointX[(i==5)?0:i+1];
line
.end2[1]=PointY[(i==5)?0:i+1];
line
.type=PRO_2D_LINE;
ProSectionEntityAdd (section,(Pro2dEntdef*)[$line
, &line_id
)]
}
//旋转轴
line[0].end1[0]=0;
line[0].end1[1]=-10;
line[0].end2[0]=0;
line[0].end2[1]=10;
line[0].type=PRO_2D_CENTER_LINE;
ProSectionEntityAdd (section,(Pro2dEntdef*)[$line[0], &line_id[0])]
break;
default:
break;
}
return (1);
}
/*===================================================================*\
Function: usrFeatDel()(删除当前特征)
\*===============================================================*/
void usrFeatDel()
{
ProSolid solid;
ProMdlCurrentGet((ProMdl*)[$solid)]
ProFeatureDelete(solid, [$feature.id,1,NULL,0)]
ProWindowRepaint(-1);
}
/*============================================================*\
FUNCTION : UsrCreatDefDtm (创建基准面)
\*===============================================================*/
int UsrCreatDefDtm(ProDtmplnConstrType pro_dtmpln_def,
ProName dtm_name,ProGeomitem *pln)
{
ProError status;
ProElement elem_tree,elem_type,elem_consts,elem_const,
elem_const_type;
ProValueData value_data;
ProValue value;
ProModelitem model_modelitem;
ProSelection mdl_sel;
ProFeature feature;
ProErrorlist errors;
ProSolid solid;
/*---------------------------------------------------------------*\
为特征树顶层元素elem_tree分配内存
\*---------------------------------------------------------------*/
ProElementAlloc (PRO_E_FEATURE_TREE, [$elem_tree)]
/*----------------------------------------------------------------*\
向特征树添加特征类型元素elem_ftype
\*----------------------------------------------------------------*/
//设置特征元素之值
ProElementAlloc (PRO_E_FEATURE_TYPE, [$elem_type)]
value_data.type = PRO_VALUE_TYPE_INT;
value_data.v.i = PRO_FEAT_DATUM;
ProValueAlloc ([$value)]
ProValueDataSet (value, [$value_data)]
ProElementValueSet (elem_type, value);
//将特征元素添加到特征元素树中
ProElemtreeElementAdd (elem_tree, NULL, elem_type);
/*----------------------------------------------------------------*\
向特征树添加约束平面集元素elem_consts
\*----------------------------------------------------------------*/
ProElementAlloc (PRO_E_DTMPLN_CONSTRAINTS, [$elem_consts)]
ProElemtreeElementAdd (elem_tree, NULL, elem_consts);
/*----------------------------------------------------------------*\
向约束平面集元素添加子元素elem_const
\*----------------------------------------------------------------*/
ProElementAlloc (PRO_E_DTMPLN_CONSTRAINT, [$ elem_const)]
ProElemtreeElementAdd (elem_consts, NULL, elem_const);
/*----------------------------------------------------------------*\
设置基准面类型元素,并添加到特征树中
\*----------------------------------------------------------------*/
ProElementAlloc (PRO_E_DTMPLN_CONSTR_TYPE, [$elem_const_type)]
value_data.type = PRO_VALUE_TYPE_INT;
value_data.v.i = pro_dtmpln_def;
ProValueAlloc ([$value)]
ProValueDataSet (value, [$value_data)]
ProElementValueSet(elem_const_type, value);
ProElemtreeElementAdd (elem_const, NULL,elem_const_type);
/*----------------------------------------------------------------*\
获得当前模型项的选择对象
\*----------------------------------------------------------------*/
ProMdlCurrentGet((ProMdl*)[$solid)]
ProMdlToModelitem(solid, [$model_modelitem)]
ProSelectionAlloc(NULL, [$model_modelitem, &mdl_sel)]
/*----------------------------------------------------------------*\
创建基准平面
\*----------------------------------------------------------------*/
ProFeatureCreate (mdl_sel, elem_tree, NULL, 0,[$feature,&errors)]
/*----------------------------------------------------------------*\
设置基准面名称
\*----------------------------------------------------------------*/
status=ProModelitemNameSet([$feature,dtm_name)]
/*----------------------------------------------------------------*\
重定义
\*----------------------------------------------------------------*/
status=ProFeatureRedefine(NULL, [$feature, elem_tree, NULL, 0, &errors)]
UsrGeomitemPlnGet(feature,pln);
/*----------------------------------------------------------------*\
释放内存空间
\*----------------------------------------------------------------*/
ProElementFree ([$elem_tree)]
ProSelectionFree ([$mdl_sel)]
return (status);
}
/*====================================================================*\
FUNCTION : CreatDefDtm (创建三个默认基准面)
\*====================================================================*/
void CreatDefDtm()
{
ProName dtm_name;
UsrCreatDefDtm(PRO_DTMPLN_DEF_X,
ProStringToWstring (dtm_name, "RIGHT"),[$right)]
UsrCreatDefDtm(PRO_DTMPLN_DEF_Y,
ProStringToWstring (dtm_name, "TOP"),[$top)]
UsrCreatDefDtm(PRO_DTMPLN_DEF_Z,
ProStringToWstring (dtm_name, "FRONT"),[$front)]
}
/*====================================================================*\
FUNCTION : GemitemAction (获得ProGeomitem指针的动作函数)
\*====================================================================*/
ProError GemitemAction(ProGeomitem* p_geomitems,
ProError status,ProAppData app_data)
{
memcpy(app_data, p_geomitems, sizeof(ProGeomitem));
return(PRO_TK_E_FOUND);
}
/*====================================================================*\
FUNCTION : UsrGeomitemPlnGet (获得基准面ProGeomitem指针)
\*====================================================================*/
void UsrGeomitemPlnGet(ProFeature feature,ProGeomitem *geomitem)
{
ProFeatureGeomitemVisit(&feature, PRO_SURFACE,
(ProGeomitemAction)GemitemAction,NULL,geomitem);
}
/*================================================================*\
FUNCTION: DefaultDtmActFn 创建默认基准面
\*================================================================*/
int DefaultDtmActFn()
{
ProSolid solid;
// ProGeomitem **p_data;
if (ProMdlCurrentGet((ProMdl*)&solid)!=PRO_TK_NO_ERROR)
{
AfxMessageBox("零件文档尚未建立,请先新建零件!");
ProUIDialogExit(dialog_name,1);
return false;
}
if (front.type!=PRO_SURFACE || top.type!=PRO_SURFACE
|| right.type!=PRO_SURFACE)
{//创建默认基准面
CreatDefDtm();
}
return true;
}
作者:
七剑下天山
时间:
2003-12-30 12:45
(5)编写注册文件protk.dat,存储在当前目录(本文是"vc files\Example")
(6) 编写信息文件usrmsg.txt,存储在text目录下(vc files\Example\text)
(7)编写对话框资源文件mydlg.res存储在resource目录下(vc files\Example\text\resource)
作者:
七剑下天山
时间:
2003-12-30 12:47
protk.dat如下所示:
NAME Example
EXEC_FILE ./Example/Debug/Example.dll
TEXT_DIR ./Example/text
STARTUP = DLL
FAIL_TOL = TRUE
DELAY_START FALSE
ALLOW_STOP TRUE
END
作者:
七剑下天山
时间:
2003-12-30 12:47
usrmsg.txt如下所示:
USER Menu
showdialog
#
#
USER Menu Help
show dialog created by user
#
#
作者:
七剑下天山
时间:
2003-12-30 12:49
对话框资源文件mydlg.res如下所示:
!UI对话框示例程序资源文件:Example5_3.res
(Dialog mydlg
(Components
(SubLayout Layout1)!子布局1
(SubLayout Layout2)!子布局2
(Label image) !提示图
(CheckButton CheckEditSet)
(Separator Separator1)
(PushButton OK)
(PushButton Cancel)
)
(Resources
(OK.TopOffset 4)
(OK.BottomOffset 4)
(OK.LeftOffset 4)
(OK.RightOffset 4)
(OK.Bitmap "cl_ok")
(OK.Label "OK")
(Cancel.TopOffset 4)
(Cancel.BottomOffset 4)
(Cancel.LeftOffset 4)
(Cancel.RightOffset 4)
(Cancel.Bitmap "cl_cancel")
(Cancel.Label "Cancel")
(image.Bitmap "example5_3.gif")
(CheckEditSet.Label "允许修改")
(CheckEditSet.Set True)
(.Label "Example")
(.Focus "OK")
(.DefaultButton "OK")
(.StartLocation 5) !中心
(.Layout
(Grid (Rows 1 1 1) (Cols 1)
(Grid (Rows 1) (Cols 1 1)
Layout1
(Grid (Rows 1 1) (Cols 1)
Layout2
(Grid (Rows 1) (Cols 1 1)
image
CheckEditSet
)
)
)
Separator1
(Grid (Rows 1) (Cols 1 1)
OK
Cancel
)
)
)
)
)
(Layout Layout1 !设计参数子布局
(Components
(Label Label_D1)
(Label Label_D2)
(Label Label_L1)
(Label Label_L2)
(SpinBox SpinBoxD1)
(SpinBox SpinBoxD2)
(SpinBox SpinBoxL1)
(SpinBox SpinBoxL2)
)
(Resources
(Label_D1.AttachLeft True)
(Label_D1.LeftOffset 4)
(Label_D1.Label "D1")
(Label_D1.Bitmap "dynmod_diam")
(Label_D2.AttachLeft True)
(Label_D2.LeftOffset 4)
(Label_D2.Label "D2")
(Label_D2.Bitmap "dynmod_diam")
(Label_L1.AttachLeft True)
(Label_L1.LeftOffset 4)
(Label_L1.Label "L1")
(Label_L1.Bitmap "dynmod_linear")
(Label_L2.AttachLeft True)
(Label_L2.LeftOffset 4)
(Label_L2.Label "L2")
(Label_L2.Bitmap "dynmod_linear")
(SpinBoxD1.AttachLeft True)
(SpinBoxD1.TopOffset 4)
(SpinBoxD1.BottomOffset 4)
(SpinBoxD1.LeftOffset 4)
(SpinBoxD1.RightOffset 4)
!(InputPanel_D1.Columns 3)
(SpinBox.InputType 2)
(SpinBox.Digits 2)
(SpinBoxD2.AttachLeft True)
(SpinBoxD2.TopOffset 4)
(SpinBoxD2.BottomOffset 4)
(SpinBoxD2.LeftOffset 4)
(SpinBoxD2.RightOffset 4)
!(InputPanel_D2.Columns 3)
(SpinBoxD2.InputType 2)
(SpinBoxD2.Digits 2)
(SpinBoxL1.AttachLeft True)
(SpinBoxL1.TopOffset 4)
(SpinBoxL1.BottomOffset 4)
(SpinBoxL1.LeftOffset 4)
(SpinBoxL1.RightOffset 4)
!(InputPanel_L1.Columns 3)
(SpinBoxL1.InputType 2)
(SpinBoxL1.Digits 2)
(SpinBoxL2.AttachLeft True)
(SpinBoxL2.TopOffset 4)
(SpinBoxL2.BottomOffset 4)
(SpinBoxL2.LeftOffset 4)
(SpinBoxL2.RightOffset 4)
!(InputPanel_L2.Columns 3)
(SpinBoxL2.InputType 2)
(SpinBoxL2.Digits 2)
(.TopOffset 4)
(.BottomOffset 4)
(.LeftOffset 4)
(.RightOffset 4)
(.Decorated True)
(.Label "设计参数")
(.Layout
(Grid (Rows 1 1 1 1) (Cols 1 1)
Label_D1
SpinBoxD1
Label_D2
SpinBoxD2
Label_L1
SpinBoxL1
Label_L2
SpinBoxL2
)
)
)
)
(Layout Layout2 !参数表子布局
(Components
(List List1)
)
(Resources
(List1.SelectionPolicy 1)
(List1.VisibleRows 5)
(List1.Columns 12)
(List1.ListType 1)
(List1.ColumnLabel "D1 D2 L1 L2")
(List1.TabStops 3 6 9 12)
(.AttachTop True)
(.TopOffset 4)
(.BottomOffset 4)
(.LeftOffset 4)
(.RightOffset 4)
(.Decorated True)
(.Label "参数表")
(.Layout
(Grid (Rows 1) (Cols 1)
List1
)
)
)
)
作者:
七剑下天山
时间:
2003-12-30 12:59
编译连接通过后在Pro/E中进行如下操作:
Utilities>Auxiliary Applications>Register,选择vc files\Example\protk.dat
点击AuxiliaryApplications对话框中的Start,
作者:
七剑下天山
时间:
2003-12-30 12:59
开始
作者:
七剑下天山
时间:
2003-12-30 13:01
可以看到自己做的菜单show dialog了,点击它,就可以看到对话框了
作者:
七剑下天山
时间:
2003-12-30 13:04
不知道为什么程序中有些括号变成了小人头
大家看程序时把它相应的换成括号就行 了
不便之处请见谅
作者:
inwander
时间:
2003-12-31 11:56
是啊,好多人头,建议把对应的文件压缩在一起发上来。这样也不会出错。
作者:
七剑下天山
时间:
2003-12-31 17:09
压缩文件
作者:
pinkwall
时间:
2004-1-5 01:17
proe怎么实现连续对话框??
作者:
shinyxiao
时间:
2004-3-12 21:13
请教:在usrcreatesection()中能用参数方程表示不规则曲线吗?或者用吗办法?
作者:
xmy198746
时间:
2013-10-7 22:59
{:soso_e179:}{:soso_e179:}
作者:
Pro/E普世开发
时间:
2013-10-15 17:18
这么多代码呢啊。大家可以去我们公司主页www.pushingvalue.com去看一看,专业对proe进行二次开发,现在已经开发出了多款软件,比如敏捷标注,敏捷配置,敏捷打印等等,相信肯定会帮到大家的
作者:
达芬奇
时间:
2013-10-21 15:24
已经看了,确实做的不错,已经申请试用Smartdrawing敏捷标注,真是挺方便的,希望国产软件能做的越来越好,支持楼上
欢迎光临 iCAx开思工具箱 (https://t.icax.org/)
Powered by Discuz! X3.3