Feature Creation
 
There are many kinds of feature in Creo Parametric and each one can contain a large and varied amount of information. All this information must be complete and consistent before a feature can be used in regeneration and give rise to geometry. This raises several problems for programmatic creation of features through an API.
It is necessary to build all the information needed by a feature into a data structure before passing that whole structure to Creo Parametric. However, the object-oriented style of Creo TOOLKIT requires that such a data structure is not directly visible to the application. Therefore, Creo TOOLKIT defines this structure as a workspace object that can be allocated and filled using special functions for that purpose, but that is not part of the Creo Parametric database.
There are three steps in creating a feature in Creo Parametric:
1. Allocate the workspace structure.
2. Fill the workspace structure.
3. Pass the workspace structure to Creo Parametric to create the feature.
Note:
 
Creating sketched features requires a few more steps. For detailed information, see the section Element Trees: Sketched Features.
The procedure described above allows a feature of arbitrary complexity to be built up in a sequence of manageable steps, with the maximum of error checking along the way.
Although it is not yet possible to create all feature types using Creo TOOLKIT, the workspace structure must be capable of defining any feature type so the range of features can be extended without affecting the techniques already in use. For this reason, the workspace structure for feature creation takes the form of a tree of data elements. This has the advantage of being simple for simple features, yet is flexible enough to provide for all possible feature types without introducing new principles.
The root and branch points in the tree are called “elements,” and the complete tree is called the “feature element tree.” Each element is modeled by the object ProElement, which is a pointer to an opaque structure.
The feature element tree contains all the information required to define the feature. This includes the following:
All options and attributes, such as the material side and depth type for an extrusion or slot, placement method for a hole, and so on.
All references to existing geometry items, such as placement references, “up to” surfaces, sketching planes, and so on.
References to Sketcher models used for sections in the feature.
All dimension values.
Note:
 
Because Creo TOOLKIT is the same toolkit used to build Creo Parametric, improvements to Creo Parametric may require the definition of the element tree to be altered for some features. PTC will make every effort to maintain upward compatibility. However, there may be cases where the old application will not run with the new version of Creo Parametric, unless you rewrite the application's code to conform to the new definition of the feature tree.
Note that although the values of dimensions used by the feature are in the element tree, there are no descriptions of, or references to, the dimension objects themselves. The only exception is as follows: for an element tree for a feature already in the Creo Parametric database, you can ask the identifier of the dimension used for a particular element using the function ProFeatureElemDimensionIdGet(). This is explained in detail in the section Feature Inquiry. For more general functions that access dimensions, see the section Core: Relations.
Each element in the tree is assigned an element ID, which is really a description of the role it is playing in this feature—the kind of information it is supplying. It is called an element ID because no two elements at the same level in the tree will have the same identifier, unless they belong to an array element, so the element ID also acts as a unique identifier.
The possible element roles are values in an enumerated type called ProElemId, declared in ProElemId.h. Example values are as follows:
PRO_E_FEATURE_TYPE
PRO_E_FEATURE_FORM
PRO_E_EXT_DEPTH
PRO_E_THICKNESS
PRO_E_4AXIS_PLANE
There are four different element types:
Single-valued
Multivalued
Compound
Array
A single-valued element can contain various types of value. The simplest is an integer used to define, for example, the type of the feature, or one of the option choices, such as the material side for a thin protrusion. The value can be a wide string (for example, the name of the feature), or a double (for example, the depth of a blind extrusion). If the element defines a reference to an existing geometry item in the solid, its value contains an entire ProSelection object so it can refer to anything in an entire assembly.
A multivalued element contains several values of one of these types. Multivalued elements occur at the lowest level of the element tree—the “leaves.” An example is the element with the identifier PRO_E_FIXT_COMPONENTS in a Fixture Setup feature in Creo NC. That element specifies the components in the assembly that belong to the fixture; in general, there can be any number of such components, so the element contains several component identifiers.
A compound element is one that acts as a branch point in the tree. It does not have a value of its own, but acts as a container for elements further down in the hierarchy.
An array element is also a branch point, but one that contains many child elements of the same element ID. An example of this is the PRO_E_DTMPLN_CONSTRAINTS element in a datum plane feature, which contains an array of elements of type PRO_E_DTMPLN_CONSTRAINT (note the singular), each of which is a compound element whose contents describe one of the constraints that determine the position of the datum plane.
The feature element tree enables you to build a complex feature in stages, with only a small set of functions. However, the form of the tree required for a particular feature needs to be clearly defined so you know exactly what elements and values to add, and so Creo TOOLKIT can check for errors each time you add a new element to the tree.
Creo TOOLKIT documents the necessary contents of the element tree for each type of feature that can be created programmatically. It does this through two types of description:
Feature element tree
Feature element table
The feature element tree defines the structure of the tree, specifying the element ID (or role) for the elements at all levels in the tree, and which elements are optional.
The feature element table defines the following for each of the element IDs in the tree:
A description of its role in the feature
The value type it has (that is, whether it is single value or compound; or an array of integer, double, or string)
The range of values valid for it in this context
Each type of feature that can be created using Creo TOOLKIT has its own header file that contains the feature element tree and table, in the form of code comments. The header files for the feature types that can be created in the current version are as follows:
Header File
Feature Type
ProAnalysis.h
External Analysis
ProAsmcomp.h
Assembly component, mechanism connection
ProChamfer.h
Chamfer or corner chamfer
ProDataShareFeat.h
General merge (merge, cutout, inheritance), copy geom., publish geom., shrinkwrap
ProDraft.h
Draft
ProDtmAxis.h
Datum axis
ProDtmCrv.h
Datum curve
ProDtmCsys.h
Datum coordinate system
ProDtmPln.h
Datum plane
ProDtmPnt.h
Datum point
ProExtrude.h
Extruded protrusion, cut, surface, surface trim, thin, sheetmetal wall, or sheetmetal cut
ProFixture.h
Fixture (for Creo NC)
ProFlatSrf.h
Fill surface or sheetmetal flat wall
ProForeignCurve.h
Foreign datum curve
ProHole.h
Hole
ProMerge.h
Merge
ProMirror.h
Mirror (geometry only)
ProMove.h
Move and copy (geometry only)
ProMfgoper.h
Manufacturing operation
ProNcseq.h
Manufacturing Creo NC sequence
ProProcstep.h
Process step
ProReplace.h
Surface replacement feature
ProRevolve.h
Revolved protrusion, cut, surface, surface trim or thin
ProRib.h
Rib
ProRound.h
Round
ProShell.h
Shell
ProSmtFlangeWall.h
Sheetmetal flange wall
ProSmtFlatWall.h
Sheetmetal flat wall
ProSolidify.h
Solidify
ProStdSection.h
Standard section
ProSweep.h
Simple swept protrusion, cut
ProThicken.h
Thicken
ProTrim.h
Trim
ProWcell.h
Manufacturing workcell
The feature element tree for the Fixture Setup feature defined in the header file ProFixture.h is deprecated. Use the element tree defined in the header file ProMfgFeatFixture.h instead. For more information, please refer to the section Manufacturing Holemaking Step.
The first two elements are common to all features. The root of a feature tree is always a compound element with the identifier PRO_E_FEATURE_TREE. The first element within the root always specifies the feature type; it is a single-valued element with the element ID PRO_E_FEAT_TYPE, whose value is one of the integers in the list of feature types in ProFeatType.h. In this case, the element table shows that the value must be PRO_FEAT_FIXSETUP.
The next element in a fixture setup gives the name of the feature; its element ID is PRO_E_FEAT_NAME, and it contains a single wide string. The element tree shows that this is optional.
The PRO_E_FIXT_COMPONENTS is a multivalued element, with the value type integer, which contains the identifiers of the assembly components that belong to the fixture.
The last element in a fixture setup is PRO_E_SETUP_TIME, which contains a double.
As you build the elements into the workspace element tree, Creo TOOLKIT checks the correctness of their types against the structure described by the element tree and table in the corresponding header file. This makes it easy to diagnose errors when you are creating features. The geometrical correctness is checked only when you try to create the feature in the Creo Parametric database.
The following sections of this section describe the functions used to build an element tree and create a feature. The sections are as follows:
Feature Element Values—Introduces the object ProValue, used to represent the value of a feature element.
Feature Element Paths—Introduces the object ProElempath, used to describe the location of an element in an element tree.
Feature Elements—Introduces the ProElement functions used to build and analyze an element tree.
Feature Element Diagnostics—Introduces the ProElementDiagnostics functions used to obtain the diagnostics for a feature element.
Calling ProFeatureCreate()—Describes the ProFeatureCreate() function in detail.
Example of Complete Feature Creation—Shows how to use functions from the other sections to perform all the steps needed to create a feature.
這是否有幫助?