📄 samp1.c
字号:
/*load head file*/
#include<ProToolkit.h>#include<Pro2dEntdef.h>#include<ProANSI.h>#include<ProAnimate.h>#include<ProArray.h>#include<ProAsmcomp.h>#include<ProAsmcomppath.h>#include<ProAssembly.h>#include<ProAxis.h>#include<ProChamfer.h>#include<ProClCmd.h>#include<ProColor.h>#include<ProComm.h>#include<ProConst.h>#include<ProContour.h>#include<ProContourdata.h>#include<ProCore.h>#include<ProCsys.h>#include<ProCsysdata.h>#include<ProCurve.h>#include<ProCurvedata.h>#include<ProDatumdata.h>#include<ProDisplist.h>#include<ProDtmAxis.h>#include<ProDtmCrv.h>#include<ProDtmCrvSketch.h>#include<ProDtmCsys.h>#include<ProDtmPln.h>#include<ProEdge.h>#include<ProEdgedata.h>#include<ProElemId.h>#include<ProElement.h>#include<ProElempath.h>#include<ProExpldstate.h>#include<ProExtdata.h>#include<ProExtobj.h>#include<ProExtobjCB.h>#include<ProExtobjDisp.h>#include<ProExtobjRef.h>#include<ProExtobjSel.h>#include<ProExtrude.h>#include<ProFaminstance.h>#include<ProFamtable.h>#include<ProFeatForm.h>#include<ProFeatType.h>#include<ProFeature.h>#include<ProFixture.h>#include<ProFlatSrf.h>#include<ProForeignCurve.h>#include<ProGeomitem.h>#include<ProGeomitemdata.h>#include<ProGraphic.h>#include<ProGroup.h>#include<ProHardware.h>#include<ProImportfeat.h>#include<ProIntfData.h>#include<ProItemerr.h>#include<ProLayer.h>#include<ProLayerR19.h>#include<ProMaterial.h>#include<ProMdl.h>#include<ProMenu.h>#include<ProMenuBar.h>#include<ProMessage.h>#include<ProMfg.h>#include<ProMfgoper.h>#include<ProModFeat.h>#include<ProMode.h>#include<ProModelitem.h>#include<ProNcseq.h>#include<ProNcseqElem.h>#include<ProNote.h>#include<ProNotify.h>#include<ProObjects.h>#include<ProParameter.h>#include<ProParamval.h>#include<ProPart.h>#include<ProPattern.h>#include<ProPecktable.h>#include<ProPoint.h>#include<ProProcstep.h>#include<ProQuilt.h>#include<ProQuiltdata.h>#include<ProRelSet.h>#include<ProReplace.h>#include<ProRevolve.h>#include<ProRmdt.h>#include<ProRule.h>#include<ProSecConstr.h>#include<ProSecdim.h>#include<ProSecdimType.h>#include<ProSecerror.h>#include<ProSection.h>#include<ProSelection.h>#include<ProSheetmetal.h>#include<ProSimprep.h>#include<ProSimprepdata.h>#include<ProSizeConst.h>#include<ProSolid.h>#include<ProStdSection.h>#include<ProSurface.h>#include<ProSurfacedata.h>#include<ProSweep.h>#include<ProTool.h>#include<ProToolElem.h>#include<ProToolinput.h>#include<ProUICmd.h>#include<ProUtil.h>#include<ProValue.h>#include<ProVerstamp.h>#include<ProView.h>#include<ProWcell.h>#include<ProWchar.h>#include<ProWindows.h>#include<ProWorkspace.h>#include<ProWstring.h>#include<TestError.h>
#define ASSEMBLY 100
#define PART 200
ProFileName UserMsg;
int UserDatumRefs();
int ProDatumPlaneCreate(ProSelection offset_surface, double offset_dist, int dtm_level);
int UserDatumRefs();
/*--------------------------------------------------------------------*\Application global data\*--------------------------------------------------------------------*/static uiCmdAccessState TestAccessDefault(uiCmdAccessMode access_mode){ return (ACCESS_AVAILABLE);}/*===========================================================================*\ Function : main Purpose : Test the ProToolkitMain() function. main is optional function.\*===========================================================================*/main(argc, argv)int argc;char **argv;{ ProToolkitMain(argc, argv); return(0);}/*====================================================================*\FUNCTION : user_initialize()PURPOSE : Pro/DEVELOP standard initialize - define menu button\*====================================================================*/int user_initialize( int argc, char *argv[], wchar_t errbuf[80]){
ProError status;
uiCmdCmdId cmd_id;
/*----------------------------------------------------------------*\
消息文件
\*----------------------------------------------------------------*/
ProStringToWstring (UserMsg, "msg.txt");
status = ProMessageDisplay (UserMsg, "USER %0s", "Demo of Creating Datum Plane.\n");
/*---------------------------------------------------------------------*\
Add new button to the menu bar
\*---------------------------------------------------------------------*/
status = ProCmdActionAdd("MyCmd",
(uiCmdCmdActFn)UserDatumRefs,
uiProe2ndImmediate, TestAccessDefault,
PRO_B_TRUE, PRO_B_TRUE, &cmd_id);
status = ProMenubarmenuPushbuttonAdd(
"File", "MyCmd", "Create Datum Plane", "Create Datum Plane",
"File.psh_exit", PRO_B_TRUE, cmd_id, UserMsg);
return (0);
}
/*====================================================================*\
FUNCTION : user_terminate()
PURPOSE : To handle any termination actions
\*====================================================================*/
void user_terminate()
{
}
/* =============================================================== *\
Function: UserDatumRefs()
Purpose: Obtain reference surface and offset for datum
plane creation
\* =============================================================== */
int UserDatumRefs()
{
static wchar_t UserMsg[80];
ProError status;
ProSelection *ref_surf;
int sel_num, level_flag;
double offset_value;
wchar_t w_level[PRO_TYPE_SIZE];
char level[PRO_TYPE_SIZE];
/* =============================================================== *\
Prompt user for reference surface ...
\* =============================================================== */
status = ProMessageDisplay(UserMsg, "USER Select a reference surface");
status = ProSelect("surface", 1, NULL, NULL, NULL, NULL, &ref_surf, &sel_num);
ERROR_CHECK("ProSelect()", "UserDatumRefs()", status);
/* =============================================================== *\
... then, offset distance
\* =============================================================== */
status = ProMessageDisplay(UserMsg, "USER Enter the offset value:");
if ((status = ProMessageDoubleRead(NULL, &offset_value))
!= PRO_TK_NO_ERROR)
return(status);
/* =============================================================== *\
... finally, level at which datum is to be created (part vs. asm)
\* =============================================================== */
status = ProMessageDisplay(UserMsg, "USER Create datum plane at part or assembly level (prt or asm):");
status = ProMessageStringRead(PRO_TYPE_SIZE, w_level);
ERROR_CHECK("ProMessageStringRead()", "UserDatumRefs()", status);
ProWstringToString(level, w_level);
if (!strcmp(level, "prt"))
level_flag = PART;
else if (!strcmp(level, "asm"))
level_flag = ASSEMBLY;
else
return(status);
status = ProDatumPlaneCreate(*ref_surf, offset_value, level_flag);
ERROR_CHECK("ProDatumPlaneCreate()", "UserDatumRefs()", status);
return(status);
}
/* =============================================================== *\
Function: ProDatumPlaneCreate()
Purpose: Creates a datum plane as an assembly feature at an
offset distance from a surface on a part
\* =============================================================== */
int ProDatumPlaneCreate(ProSelection offset_surface, double offset_dist, int dtm_level)
{
ProError status;
ProElement elem_tree, elem_ftype, elem_consts, elem_offset;
ProElement elem_const_type, elem_offset_ref, elem_offset_dist;
ProValueData value_data;
ProValue value;
ProModelitem surf_modelitem, model_modelitem;
ProSelection mdl_sel;
ProFeature feature;
ProErrorlist errors;
ProAsmcomppath p_cmp_path;
/* =============================================================== *\
Allocate tree root element
\* =============================================================== */
status = ProElementAlloc(PRO_E_FEATURE_TREE, &elem_tree);
/* =============================================================== *\
Allocate feature type element; add to tree root.
\* =============================================================== */
status = ProElementAlloc(PRO_E_FEATURE_TYPE, &elem_ftype);
value_data.type = PRO_VALUE_TYPE_INT;
value_data.v.i = PRO_FEAT_DATUM;
ProValueAlloc(&value);
ProValueDataSet(value, &value_data);
ProElementValueSet(elem_ftype, value);
ProElemtreeElementAdd(elem_tree, NULL, elem_ftype);
/* =============================================================== *\
Allocate constraints element; add to tree root.
\* =============================================================== */
status = ProElementAlloc(PRO_E_DTMPLN_CONSTRAINTS, &elem_consts);
ProElemtreeElementAdd(elem_tree, NULL, elem_consts);
/* =============================================================== *\
Allocate constraint element; add under constraints element.
\* =============================================================== */
status = ProElementAlloc(PRO_E_DTMPLN_CONSTRAINT, &elem_offset);
status = ProElemtreeElementAdd(elem_consts, NULL, elem_offset);
/* =============================================================== *\
Allocate constraint type element; add under constraint element.
\* =============================================================== */
status = ProElementAlloc(PRO_E_DTMPLN_CONSTR_TYPE, &elem_const_type);
value_data.type = PRO_VALUE_TYPE_INT;
value_data.v.i = PRO_DTMPLN_OFFS;
ProValueAlloc(&value);
ProValueDataSet(value, &value_data);
ProElementValueSet(elem_const_type, value);
status = ProElemtreeElementAdd(elem_offset, NULL, elem_const_type);
/* =============================================================== *\
Allocate constraint ref element; add under constraint element.
\* =============================================================== */
status = ProElementAlloc(PRO_E_DTMPLN_CONSTR_REF, &elem_offset_ref);
value_data.type = PRO_VALUE_TYPE_SELECTION;
value_data.v.r = offset_surface;
ProValueAlloc(&value);
ProValueDataSet(value, &value_data);
ProElementValueSet(elem_offset_ref, value);
status = ProElemtreeElementAdd(elem_offset, NULL, elem_offset_ref);
/* =============================================================== *\
Allocate ref offset value element; add under constraint element.
\* =============================================================== */
status = ProElementAlloc(PRO_E_DTMPLN_CONSTR_REF_OFFSET, &elem_offset_dist);
value_data.type = PRO_VALUE_TYPE_DOUBLE;
value_data.v.d = offset_dist;
ProValueAlloc(&value);
ProValueDataSet(value, &value_data);
ProElementValueSet(elem_offset_dist, value);
status = ProElemtreeElementAdd(elem_offset, NULL, elem_offset_dist);
/* =============================================================== *\
Get assembly component path to part containing offset surface
\* =============================================================== */
status = ProSelectionAsmcomppathGet(offset_surface, &p_cmp_path);
ERROR_CHECK("ProSelectionAsmcomppathGet", "ProDatumPlaneCreate()", status);
switch (dtm_level)
{
case ASSEMBLY:
/* =============================================================== *\
Obtain a ProModelitem handle to the root assembly
\* =============================================================== */
status = ProMdlToModelitem(p_cmp_path.owner, &model_modelitem);
ERROR_CHECK("ProMdlToModelitem", "ProDatumPlaneCreate()", status);
/* =============================================================== *\
Allocate ProSection object for root assembly
\* =============================================================== */
status = ProSelectionAlloc(NULL, &model_modelitem, &mdl_sel);
ERROR_CHECK("ProSelectionAlloc", "ProDatumPlaneCreate()", status);
break;
case PART:
/* =============================================================== *\
Obtain a ProModelitem handle to selected surface
\* =============================================================== */
status = ProSelectionModelitemGet(offset_surface, &surf_modelitem);
ERROR_CHECK("ProSelectionModelitemGet", "ProDatumPlaneCreate()", status);
/* =============================================================== *\
Obtain a ProModelitem to the owner of the selected surface
\* =============================================================== */
status = ProMdlToModelitem(surf_modelitem.owner, &model_modelitem);
ERROR_CHECK("ProMdlToModelitem", "ProDatumPlaneCreate()", status);
/* =============================================================== *\
Allocate ProSection object for part to which selected surface
belongs
\* =============================================================== */
status = ProSelectionAlloc(&p_cmp_path, &model_modelitem, &mdl_sel);
ERROR_CHECK("ProSelectionAlloc", "ProDatumPlaneCreate()", status);
break;
default:
return(0);
}
/* =============================================================== *\
Create datum plane
\* =============================================================== */
status = ProFeatureCreate(mdl_sel, elem_tree, NULL, 0, &feature, &errors);
ERROR_CHECK("ProFeatureCreate", "ProDatumPlaneCreate()", status);
status = ProElementFree(&elem_tree);
ERROR_CHECK("ProElementFree", "ProDatumPlaneCreate()", status);
status = ProSelectionFree(&mdl_sel);
ERROR_CHECK("ProSelectionFree", "ProDatumPlaneCreate()", status);
return(status);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -