Creo secondary development: model item acquisition, creation and deletion

Model items classification

The model item promodellitem is a data handle that contains the type type, an integer id, and the parent item handle owner.
ProGeomitem is an instance of promodelite, which is used to represent the data handle DHandle of geometry.
The data structure of promodellitem is as follows

typedef struct pro_model_item
{
	ProType type;
	int id;
	ProMdl owner;
} ProModelitem,ProGeomitem, ProExtobj, ProFeature, ProProcstep,
  ProSimprep, ProExpldstate, ProLayer, ProDimension, ProDtlnote,
  ProDtlsyminst, ProGtol, ProCompdisp, ProDwgtable, ProNote,
  ProAnnotationElem, ProAnnotation, ProAnnotationPlane, 
  ProSymbol, ProSurfFinish, ProMechItem, ProMaterialItem, ProCombstate,
  ProLayerstate

It can be seen from the above definition that the model item can be geometric item, external object, feature, process step, simplified representation, explosion state, layer, geometry, two-dimensional annotation, symbol instance, geometric tolerance, model display, table, model annotation, annotation item, annotation, plane, symbol, surface roughness, mechanism item, material, combination state, layer state, etc.

Initialization of model items

  • Initialize by id: promodeleminit()
  • Initialize by name: promodelembynameinit()
  • Initialization through interactive selection: ProSelectionModelitemGet
  • Convert through specific examples: ProCsysToGeomitem();
    ProPointToGeomitem();
    ProSurfaceToGeomitem();
    ...
  • Get through model item traversal: ProSolidSurfaceVisit();
    ProSolidCsysVisit();
    ProMdlLayerVisit();
    ProMdlLayersCollect();
    ProSolidFeatVisit();
    ProFeatureGeomitemVisit();
    ...

Creation of model items

There are many ways to model items

  1. Create ProFeatureCreate() directly
    Create features by building ProElementTree feature element tree. There are many features created in this way. The corresponding header files are as follows
    ProAnalysis.h
    ProAsmcomp.h
    ProBeltFeat.h
    ProChamfer.h
    ProContact3dFeat.h
    ProDamperFeat.h
    ProDesignatedArea.h
    ProDraft.h
    ProDtmAxis.h
    ProDtmCrv.h
    ProDtmCsys.h
    ProDtmPln.h
    ProDtmPnt.h
    ProElemId.h
    ProExtrude.h
    ProFeatIntr.h
    ProFixture.h
    ProFlatSrf.h
    ProForeignCurve.h
    ProHole.h
    ProMfgoper.h
    ProMerge.h
    ProMirror.h
    ProMove.h
    ProNcseq.h
    ProNcseqElem.h
    ProPattern.h
    ProProcstep.h
    ProReplace.h
    ProRevolve.h
    ProRib.h
    ProRound.h
    ProShell.h
    ProSmtFlangeWall.h
    ProSmtFlatWall.h
    ProSmtForm.h
    ProSolidify.h
    ProSmtPunchQuilt.h
    ProStdSection.h
    ProSurfReg.h
    ProSweep.h
    ProThicken.h
    ProTrim.h
    ProToolElem.h
    ProValue.h
    ProWcell.h
    Some of them are model geometry items. When creating, you should deeply understand the specific composition of the feature element tree to be created. If you don't know what the specific structure of the feature element tree to be created is, you can manually create a feature of the same type, then obtain the handle of the feature through interactive selection, extract the feature element tree, and export it as an xml file for viewing, Note which elements are required and which are optional. The interface functions used here are:
    ProFeatureElemtreeExtract
    ProElemtreeWrite

    However, for some features, the Toolkit interface does not provide the corresponding element tree to build. We can create udf features to create any features or feature combinations we need.

  2. Create through udf
    It is sometimes troublesome to build a feature element tree to create features. You can create udf to create features directly. As long as you pass the reference required by udf, set the corresponding variable parameters and change the size. The interface functions used here are:
    ProUdfdataPathSet();
    ProUdfdataVarparamAdd();
    ProUdfdataUdfvardimAdd();
    ProUdfCreate();

  3. Private interface creation
    ProDimensionCreate();
    ProCableCreate();

Deletion of model items

  1. When a model item is a feature, it can be deleted directly
    ProFeatureDelete()

  2. Non feature items can be deleted with a dedicated interface
    ProDimensionDelete();
    ProParameterDelete();

Sample code

There are many types of point features, such as sketch points, offset coordinate system points, domain points, datum points, etc. the following takes the creation of the simplest domain points as an example
Look at this file to see which elements of its feature element tree need to be built

================================================================================
Element Id                     Element Name             Data Type
================================================================================
|--PRO_E_FEATURE_TYPE          Feature Type             PRO_VALUE_TYPE_INT
|--PRO_E_DPOINT_TYPE           Datum Point Type         PRO_VALUE_TYPE_INT
|--PRO_E_STD_FEATURE_NAME      Feature Name             PRO_VALUE_TYPE_WSTRING
|--PRO_E_DPOINT_FIELD_REF      Placement Reference      PRO_VALUE_TYPE_SELECTION

Build according to the above elements,

#include <ProDtmPnt.h>
//Build model tree
ProElement elemtree;
ProElementAlloc(PRO_E_FEATURE_TREE,&elemtree);

	//PRO_E_FEATURE_TYPE, set the feature type to field point
ProElement feattypeElem;
ProElementAlloc(PRO_E_FEATURE_TYPE,&feattypeElem);
ProElementIntegerSet(feattypeElem,PRO_FEAT_DATUM_POINT);
ProElemtreeElementAdd(elemtree,NULL,feattypeElem);

	//PRO_E_STD_FEATURE_NAME, set the domain point feature name
ProElement nameElem;
ProElementAlloc(PRO_E_STD_FEATURE_NAME,&nameElem);
ProElementWstringSet(nameElem,L"Pt");
ProElemtreeElementAdd(elemtree,NULL,nameElem);

	//PRO_E_DPOINT_FIELD_REF to set the domain point reference surface
ProElement refElem;
ProElementAlloc(PRO_E_DPOINT_FIELD_REF,&refElem);
ProReference ref;

ProSelection psrfSel;
ProSelection *psels;
int nsel;
ProSelect("surface",1,NULL,NULL,NULL,NULL,&psels,&nsel);
if(nsel<1)return;
ProSelectionCopy(psels[0],&psrfSel);

ProSelectionToReference(psrfSel,&ref);
ProElementReferenceSet(refElem,ref);
ProElemtreeElementAdd(elemtree,NULL,refElem);


ProMdl pcurMdl;
ProMdlCurrentGet(&pcurMdl);
ProModelitem pmdlItem;
ProMdlToModelitem(pcurMdl,&pmdlItem);
ProSelection pMdlSel;
ProSelectionAlloc(NULL,&pmdlItem,&pMdlSel);

ProFeatureCreateOptions crtOpt[]={PRO_FEAT_CR_NO_OPTS};
ProFeature pFieldPtFeat;
ProErrorlist errlist;
//Create domain point feature
ProFeatureCreate(pMdlSel,elemtree,crtOpt,1,&pFieldPtFeat,&errlist);

Keywords: 3d visualstudio

Added by bprof on Mon, 03 Jan 2022 15:53:43 +0200