Element Trees: Sketched Features
This section describes the Creo Object TOOLKIT C++ methods that enable you to work with sketched features.
Sketched features are features that require one or more sections to completely define the feature, such as extruded and revolved protrusions.
This section outlines the necessary steps to programmatically create sketched features using Creo Object TOOLKIT C++.
Overview
The section Feature Element Tree explains how to create a simple feature using the feature element tree, and the documentation in the section Element Trees: Sections explains how to create a section. This section explains how to put these methods together, with a few additional techniques, to create features that contain sketched sections.
Creating Features Containing Sections
The section Feature Element Tree explained that to create a feature from an element tree, you must build the tree of elements using the wfcElementTree object, and then call wfcWSolid::WCreateFeature to create the feature using the tree. If the feature is to contain a sketch, the sequence is a little more complex.
As explained in the section Element Trees: Sections, a 2D section stored in a model file can be allocated by calling wfcWSession::CreateSection2D. Instead, the Creo application must allocate as part of the initial creation of the sketched feature, a section that will be part of a feature. The allocation is done by calling wfcWSolid::WCreateFeature with an element tree which describes at minimum the feature type and form, in order to create an incomplete feature. In creating the feature, the Creo application calculates the location and orientation of the section, and allocates the wfcSection object. This section is then retrieved from the value of the PRO_E_SKETCHER element that is found in the element tree extracted from the created feature. Fill the empty section using wfcSection related methods.
After adding the section contents and the remaining elements in the tree, add the new information to the feature using wfcWFeature::RedefineFeature.
To Create Sketched Features Element Trees
1. Build an element tree but do not include the element PRO_E_SKETCHER.
2. Call wfcWSolid::WCreateFeature with the option wfcFEAT_CR_INCOMPLETE_FEAT to create an incomplete feature.
3. Extract the value of the element PRO_E_SKETCHER created by the Creo application from an element tree extracted using wfcWFeature::GetElementTree on the incomplete feature.
4. Using that value as the wfcSection object create the necessary section entities.
5. Add any other elements not previously added to the tree, such as extrusion depth. The depth elements may also be added before the creation of incomplete feature (before step 2).
6. Call wfcWFeature::RedefineFeature with the completed element tree.
Example 1: Creating a Sweep Feature
The sample code in OTKXCreateSweep.cxx located at <creo_otk_loadpoint_app>/otk_examples/otk_examples_feat illustrates how to create a sweep using the Creo Object TOOLKIT C++ methods.
Creating Features with 2D Sections
Sketched features using 2D sections do not require references to other geometry in the Creo model. Some examples of where 2D sections are used are:
•  Base features, sometimes called first features. This type of feature must be the first feature created in the model.
•  Sketched hole features.
To create 2D sketched features, follow the steps outlined in the section To Create Sketched Features Element Trees.
Note
For 2D sketched features, you need not specify section references or use projected 3D entities. Entities in a 2D section are dimensioned to themselves only. A 2D section does not require any elements in the tree to setup the sketch plane or the orientation of the sketch. Thus, the PRO_E_STD_SEC_SETUP_PLANE subtree is not included.
Creating Features with 3D Sections
A 3D section needs to define its location with respect to the existing geometrical features. The subtree contained in the element PRO_STD_SEC_SETUP_PLANE defines the location of the sketch plane edge entities; any other 2D entities in the sketch must be dimensioned to those entities, so that their 3D location is fully defined.
3D Section Location in the Owning Model
Method Introduced:
The Creo application decides where the section will be positioned in 3D for all the features except the first feature and sketched hole feature.
If the section is 3D, the feature tree elements below PRO_E_STD_SEC_SETUP_PLANE specifies the sketch plane, the direction from which it is being viewed, an orientation reference, and a direction which that reference represents (TOP, BOTTOM, LEFT or RIGHT). When you call wfcWSolid::WCreateFeature, this information is used to calculate the 3D plane in which the section lies, and its orientation in that plane.
The position of the section origin in the plane is not implied by the element tree, and cannot be specified by the Creo Object TOOLKIT C++ application: position is chosen arbitrarily by Creo application. This is because the interactive user of Creo application never deals in absolute coordinates, and does not need to specify, or even know, the location of the origin of the section. In Creo Object TOOLKIT C++ describe all section entities in terms of their coordinate values, so you need to find out where Creo application has put the origin of the section. This is the role of the method wfcSection::GetLocation.
wfcSection::GetLocation provides the transformation matrix that goes from 2D coordinates within the section to 3D coordinates of the owning part or assembly. This is equivalent to describing the position and orientation of the 2D section coordinate system with respect to the base coordinate system of the 3D model.
wfcSection::GetLocation can be called in order to calculate where to position new section entities so that they are in the correct 3D position in the part or assembly.
Example 2: Manipulating a 3D Section
The sample code in OTKXCreateSection3D.cxx located at <creo_otk_loadpoint_app>/otk_examples/otk_examples_feat illustrates how to use all the methods described in this section to create a section model.