Element Trees: Sections
A section is a parametric two-dimensional cross section used to define the shape of three-dimensional features, such as extrusions. In Creo Parametric, you create a section interactively using Sketcher mode. In a Creo TOOLKIT application, you can create sections completely programmatically using the functions described in this section.
Overview
A section is a parametric two-dimensional model used to define the shape of three-dimensional features in parts and assemblies. When using Creo Parametric interactively, you create a section using Sketcher mode. In a Creo TOOLKIT application, you can create sections completely programmatically using the functions described in this section.
Sections fall into two types: 2D and 3D. Both types are represented by the object ProSection (an opaque handle) and manipulated by the same functions.
The difference between the types arises out of the context in which the section is being used, and affects the requirements for the contents of the section and also of the feature element tree in which it is placed when creating a sketched feature.
Put simply, a 2D section is self-contained, whereas a 3D section contains references to 3D geometry in a parent part or assembly.
You can use Intent Datums such Intent Axis, Intent Point, Intent Plane, and Intent Coordinate System as references for sketcher dimensions. You can use Intent Point and Intent Axis to create sections using projections.
In a Creo TOOLKIT application, you can work with a section either in an Intent Manager or a non-Intent Manager mode. In the non-Intent Manager mode, if you make any changes to the section, you must solve and regenerate the section to apply the changes. On the other hand, in the Intent Manager mode, all the changes are applied immediately.
You can create section constraints programmatically using the Intent Manager property. This corresponds to creating sections within the Intent Manager mode in Creo Parametric.
This section is concerned with 2D sections, which are the simplest. The extra steps required to construct a 3D section are described in the section Element Trees: Sketched Features, which follows this one.
Creating Section Models
A 2D section, because it is self-contained, may be stored as a Creo Parametric model file. It then has the extension .sec.
The steps required to create and save a section model using Creo TOOLKIT follow closely those used in creating a section interactively using Sketcher mode in Creo Parametric.
To Create and Save a Section Model
1. Allocate the two-dimensional section and define its name.
2. Add section entities (lines, arcs, splines, and so on) to define the section geometry, in section coordinates.
3. Add section dimensions that parametrically drive the shape of the entities.
4. Solve and regenerate the section.
5. Save the section.
When you are creating a section that is to be used in a sketched feature, Steps 1 and 5 will be replaced by different techniques. these techniques are described fully in the section Element Trees: Sketched Features.
The steps are described in more detail in the following sections.
Allocating a Two-Dimensional Section
Functions Introduced:
A two-dimensional section is identified in Creo TOOLKIT by an opaque pointer called ProSection. This type, and the functions in this section, are declared in the include file ProSection.h.
The function ProSection2DAlloc() allocates memory for a new, standalone section and outputs a ProSection handle to identify it. All the other Creo TOOLKIT functions that operate on sections take this ProSection as their first input argument.
The function ProSectionNameSet() enables you to set the name of a section. Calling this function places the section in the Creo Parametric namelist and enables it to be recognized by Creo Parametric as a section model in the database.
The following code fragment shows how to use these two functions.
    ProSection    section;
    ProName       wname;


    ProSection2DAlloc (&section);
    ProStringToWstring (wname, "demo");
    ProSectionNameSet (section, wname);
Such sections created programmatically are in the non-Intent Manager mode by default.
To free a section allocated with ProSection2DAlloc(), you must use ProSectionFree().
Setting the Mode of a Section
Functions Introduced:
Use the function ProSectionIntentManagerModeGet() to check if the Intent Manager property is ON or OFF for the specified section.
Use the function ProSectionIntentManagerModeSet() to set the Intent Manager property to ON or OFF for the specified section. This function must be called before using the other Creo TOOLKIT functions to access sections with the Intent Manager property set to ON.
Copying the Current Section
Functions Introduced:
Use the function ProSectionActiveGet() to create a copy of the section that you are using currently; this copy is created within the same Sketcher session. The mode of such a section depends on the current Sketcher mode. Starting from Pro/ENGINEER Wildfire 5.0, the Intent Manager mode is the default sketcher mode. Use the function ProSectionFree() to free the memory allocated to the section obtained with the function ProSectionActiveGet().
Use the function ProSectionActiveSet() to set the specified section as the current active Sketcher section.
Note
The function call ProSectionActiveSet() makes the Undo and Redo menu options available in Creo Parametric.
Section Constraints
Functions Introduced:
The function ProSectionConstraintsIdsGet() returns an array of section constraint identifiers that currently exist in the specified section.
Note
You must solve the section first by calling the function ProSectionSolve() to get the section constraints. Because adding or deleting section entities might invalidate the current list of section constraint identifiers, you must solve the section again to get the up-to-date list.
If a section has not been fully dimensioned with dimensions created explicitly by the user, the Sketcher will make assumptions in order to solve the section. If the Sketcher can assume enough constraints to find a unique solution to the section, it solves the section successfully.
However, you might want to disable certain Sketcher constraints to have more control over the way the section is dimensioned and solved. To do this, use the function ProSectionConstraintDeny() to deny a certain section constraint.
Note
The function ProSectionConstraintDeny() is not supported for sections that have the Intent Manager property set to ON.
The function ProSectionConstraintsGet() returns information about the specified section constraint. It takes as input the section handle and the constraint identifier for which the information is requested. The function returns details about the section constraint including its type, status, and references. The constraint types are defined in the include file ProSecConstr.h. The following table lists the possible constraint types.
Constraint Type
Description
PRO_CONSTRAINT_SAME_POINT
Make the points coincident.
PRO_CONSTRAINT_HORIZONTAL_ENT
Make the entity horizontal.
PRO_CONSTRAINT_VERTICAL_ENT
Make the entity vertical.
PRO_CONSTRAINT_PNT_ON_ENT
Place the point on the entity.
PRO_CONSTRAINT_TANGENT_ENTS
Make the entities tangent.
PRO_CONSTRAINT_ORTHOG_ENTS
Make the entities perpendicular.
PRO_CONSTRAINT_EQUAL_RADII
Make the arcs or circles of equal radius.
PRO_CONSTRAINT_PARALLEL_ENTS
Make the entities parallel.
PRO_CONSTRAINT_EQUAL_SEGMENTS
Make the segments of equal length.
PRO_CONSTRAINT_COLLINEAR_LINES
Make lines co-linear.
PRO_CONSTRAINT_90_ARC
Make the arcs 90 degrees.
PRO_CONSTRAINT_180_ARC
Make the arcs 180 degrees.
PRO_CONSTRAINT_HORIZONTAL_ARC
Make the arcs horizontal.
PRO_CONSTRAINT_VERTICAL_ARC
Make the arcs vertical.
PRO_CONSTRAINT_SYMMETRY
Impose symmetry.
PRO_CONSTRAINT_SAME_COORD
Assume the endpoints and centers of arcs to have the same coordinates.
The possible types of constraint status are as follows:
•  PRO_TK_CONSTRAINT_DENIED—The constraint is denied. This gives you more control over the section.
•  PRO_TK_CONSTRAINT_ENABLED—The constraint is enabled. The Sketcher uses the predefined assumption.
Use the function ProSectionConstraintCreate() to create constraints between entities in the specified section. Use the function ProSectionConstraintDelete() to delete the specified section constraint.
Note
The function ProSectionConstrainCreate() works only if the Intent Manager property of the specified section is set to ON.
Solving and Regenerating a Section
Functions Introduced:
Although the action of the Regenerate command in Sketcher mode is seen as a single operation by the Creo Parametric user, it is in fact composed of two distinct actions. These two operations are invoked separately from a Creo TOOLKIT application. The two operations are as follows:
•  Solving—Calculating the way in which the geometry of the entities is driven by the dimensions. It is at this stage that Sketcher constraints are applied, under- or over-dimensioning is discovered and reported, and values are assigned to new dimensions.
•  Regenerating—Reconstructing the geometry of the section to obey the current dimension values.
You invoke these stages using the functions ProSectionSolve() and ProSectionRegenerate(), respectively.
Note
The ProSectionSolve() and ProSectionRegenerate() are not supported for sections that have the Intent Manager property set to ON.
You must solve a programmatically-created section before using it to build three-dimensional geometry. You need to regenerate the section only if you have explicitly modified the dimension values since you solved the section.
When you create a section interactively using Sketcher mode, you normally adjust the values of dimensions after the first regeneration, because the initial values assigned to them correspond to the free-hand, initial sketch and are therefore not exact. When you create a section with Creo TOOLKIT , the entities are usually created with exactly the geometry needed in the finished section. Therefore, although solving is always necessary, it is not usually necessary to explicitly reset dimension values or regenerate the section.
Solving a section in Creo TOOLKIT involves applying the same constraints used in interactive Sketcher mode. Creo TOOLKIT , like the Sketcher, identifies situations of near symmetry in the section, assumes them to be intended as exact symmetry, and constrains them to be symmetrical in future regenerations. For example, lines that are nearly the same length are assumed to be intended to be the same length, and are therefore constrained to be so.
The function ProSectionSolveRigid() solves the specified section by fixing the coordinates of all the section entities with respect to a coordinate system. In this way, the section entities do not have to be solved individually. To use this function, a coordinate system within the section must exist; the function uses the first coordinate system found in the section.
Note
You must ensure that the added section entities are correct because potential errors will not be solved and may show up only during later stages.
When there are a lot of section entities, this function dramatically reduces the amount of time required to solve a section.
Note
The function ProSectionSolveRigid() is not supported for sections that have the Intent Manager property set to ON.
Epsilon is the tolerance value, which is used to set the proximity for automatic finding of constraints. Use the function ProSectionEpsilonSet() to set the value for epsilon. For example, if your section has two lines that differ in length by 0.5, set the epsilon to a value less than 0.5 to ensure that ProSectionSolve() does not constrain the lines to be the same length. To get the current epsilon value for the section, use the function ProSectionEpsilonGet().
Please note the following important points related to epsilon:
•  Epsilon determines the smallest possible entity in a section. If an entity is smaller than epsilon, then the entity is considered to be a degenerate entity. Degenerate entity is an entity which cannot be solved. It causes solving and regenerating of the section to fail. For example, a circle with radius 0 or line with length 0 are considered as degenerate entities.
•  There are many types of constraints, and epsilon has a different meaning for each type. For example, consider two points. For the constraint PRO_CONSTRAINT_SAME_POINT, epsilon is the minimum distance between the two points beyond which the points will be treated as separate points. If the distance between the two points is within the epsilon value, the two points are treated as coincident points.
•  Creo Parametric has a default value set for epsilon. This value is also used in the Sketcher user interface.
•  If the input geometry is accurate and the user does not want the solver to change it by adding constraints, then set the value of epsilon to 1E-9.
•  If the input geometry is nearly accurate and the user wants the solver to guess the intent by adding constraints and further aligning the geometry, then in this case epsilon should reflect the maximal proximity between geometry to be constrained.
•  You cannot set the value of epsilon to zero.
The functions ProSecdimValueGet() and ProSecdimValueSet() enable you to access the value of a dimension. If you change dimension values, you must call ProSectionRegenerate() to recalculate the new section shape.
Automatic Section Dimensioning
Function Introduced:
The function ProSectionAutodim() is used to automatically add needed dimensions to a section to make it fully constrained. It takes as input a ProSection handle and a pointer to the opaque structure called ProWSecerror. Before calling this function, be sure to allocate the pointer to ProWSecerror using ProSecerrorAlloc(). Any errors resulting from the call to the function ProSectionAutodim() are stored in the ProWSecerror structure. To free the allocated memory, call the function ProSecerrorFree().
The ProSectionAutodim() function can be used on a section where no dimensions have been created yet, as well as on a partially dimensioned section.
If dimensions have been added successfully, the function ProSectionAutodim() also solves the input section.
Note
The function ProSectionAutodim() is not supported for sections that have the Intent Manager property set to ON.
Adding Section Entities
Functions Introduced:
The function ProSectionEntityAdd() takes as input the ProSection that identifies the section, and a pointer to a user-visible structure called Pro2dEntdef, which defines the entity.
The Pro2dEntdef structure is a generic structure that contains only a field indicating the type of entity. For each type of entity, there is a dedicated structure that has the entity type as its first field; these structures are named Pro2dLinedef, Pro2dArcdef, and so on. The Creo TOOLKIT application builds up the structure appropriate to the entity to be added, and inputs it to ProSectionEntityAdd() by casting its address to (Pro2dEntdef*). The entity structures are declared in the include file Pro2dEntdef.h.
The function ProSectionEntityAdd() outputs an integer that is the identifier of the new entity within the section. The Creo TOOLKIT application needs these values because they are used to refer to entities when adding dimensions.
The following code fragment demonstrates how to add a single line entity.
    Pro2dLinedef   line;
    int            line_id;

    line.type    = PRO_2D_LINE;
    line.end1[0] = 0.0;
    line.end1[1] = 0.0;
    line.end2[0] = 10.0;
    line.end2[1] = 0.0;

    ProSectionEntityAdd (section,
        (Pro2dEntdef*)&line, &line_id);
The function ProSectionEntityDelete() enables you to delete a section entity from the specified section.
The function ProSectionEntityReplace() enables you to replace an existing entity from the specified section with another entity in the same section. This functionality enables you to redefine an existing section programmatically.
To use the function ProSectionEntityReplace(), you must first add the new entity to the section (to get its identifier), then replace the old entity identifier with the new one.
Accessing Selection Reference of the Entity
Functions Introduced:
The function ProSectionEntityGetSelected() provides the references of the selected entity. The input arguments of this function are:
•  handle—The section handle.
•  entity_id—The identifier of the section entity.
•  pnt_type—Specifies the type of point selection on the entity. The valid values are:
  PRO_ENT_WHOLE—Specifies the whole entity.
  PRO_ENT_START—Specifies the start point of the entity.
  PRO_ENT_END—Specifies the end point of the entity.
  PRO_ENT_CENTER—Specifies the center of the entity.
  PRO_ENT_LEFT_TANGENT—Specifies the point on the entity, where the normalized param value is 0.5.
  PRO_ENT_RIGHT_TANGENT—Specifies the point on the entity, where the normalized param value is 0.0.
  PRO_ENT_TOP_TANGENT—Specifies the point on the entity, where the normalized param value is 0.25.
  PRO_ENT_BOTTOM_TANGENT—Specifies the point on the entity, where the normalized param value is 0.75.
•  pnt—Specifies the location of the point on the entity geometry.
•  idx_pnt—Specifies the index of interpolation point relative to pnt_type, if the section entity is a spline. In this case the value of the argument pnt is ignored. Specify PRO_VALUE_UNUSED if the entity is not a spline.
This function creates the selection object programmatically for use in functions that require selection references of entities as the input.
Construction Entities
Functions Introduced:
Use the function ProSectionEntityIsConstruction() to determine if the specified entity is a construction entity. Construction entities are used for reference and are not used to create feature geometry.
The function ProSectionEntityConstructionSet() sets the specified entity to be of type construction.
Modifying Entities
Functions Introduced:
The function ProSectionEntityIntersectionGet() returns the intersection points between the two section entities. Use the function ProArrayFree() to free the memory.
The function ProSectionEntityParamEval() to find the corresponding normalized parameter on the curve, given the XY point.
The function ProSectionEntityCorner() trims the selected entities to each other. The selected entities may not intersect with each other. The entities may be trimmed by either cutting them or extending them.
Use the function ProSectionEntityDivide() to divide a section entity into two or more new entities. If the entity is dimensioned then delete the dimensions before dividing it.
Adding Section Dimensions
Functions Introduced:
When you create a dimension interactively in Sketcher mode, you select entities and points on entities and Creo Parametric deduces from those picks what type of dimension is being added. When you add a dimension using the function ProSecdimCreate(), you must specify the dimension type. The dimension types are defined in the include file ProSecdimTypes.h. The following table lists the possible values.
Constant
Description
PRO_TK_DIM_LINE
Length of a line
PRO_TK_DIM_LINE_POINT
Distance between a line and a vertex
PRO_TK_DIM_RAD
Radius of an arc or a circle
PRO_TK_DIM_DIA
Diameter of an arc or a circle
PRO_TK_DIM_LINE_LINE
Distance between two lines
PRO_TK_DIM_PNT_PNT
Distance between two points
PRO_TK_DIM_PNT_PNT_HORIZ
Distance between two points (X coordinates)
PRO_TK_DIM_PNT_PNT_VERT
Distance between two points (Y coordinates)
PRO_TK_DIM_AOC_AOC_TAN_HORIZ
Horizontal distance between two arcs or circles
PRO_TK_DIM_AOC_AOC_TAN_VERT
Vertical distance between two arcs or circles
PRO_TK_DIM_ARC_ANGLE
Angle of an arc
PRO_TK_DIM_LINES_ANGLE
Angle between two lines
PRO_TK_DIM_LINE_AOC
Distance between a line and an arc or a circle
PRO_TK_DIM_LINE_CURVE_ANGLE
Angle between a spline and a line
PRO_TK_DIM_3_PNT_ANGLE
Angular dimension defined by three points
PRO_TK_DIM_DIA_LINEAR
Linear diameter dimension
PRO_TK_DIM_PNT_PNT_ORI
Distance between two points in specified orientation
PRO_TK_DIM_AOC_AOC_ORI
Distance between two arcs or circles in specified orientation
PRO_TK_DIM_TOT_INC_ANG
Total included angle
PRO_TK_DIM_ANG_POLAR
Angle between the x-axis and a vector. The vector is defined by two points
The function ProSecdimCreate() takes several input arguments, including the following:
•  int entity_ids[]—An array of integers that are the identifiers of the section entities to which the dimension refers.
•  ProSectionPointType point_types[]—A dimension can reference a vertex (the end of an entity), the center of an arc or a circle, a line or circle itself (the whole entity), or tangent points on an arc or a circle. To specify these types of dimension reference points, specify the appropriate point type constant for each dimension in the entity_ids array. These constants are listed in the include file ProSecdimType.h.
•  int num_ids—The number of section dimension identifiers in the entity_ids array. This is typically 1 or 2 (line length versus a point-to-point dimension).
•  ProSecdimType dim_type—The type of section dimension to create, as listed in the ProSecdimType.h file.
•  Pro2dPnt place_pnt—The two-dimensional location of the dimension label. This is equivalent to the middle mouse button pick when you are using Sketcher mode.
Note that the position of this label can sometimes determine the exact role of the dimension. For example, a dimension of type PRO_TK_DIM_LINES_ANGLE may refer to the acute or obtuse angle between two lines, depending on where the label is positioned.
The ProSecdimCreate() function outputs the identifier of the dimension, which is needed to identify the dimension if its value needs to be changed at a later time.
Note
The dimensions do not need to be given values to create a complete and correct section of any form. See Solving and Regenerating a Section for a detailed explanation of the assignment of values.
The following code fragment shows how to create a dimension for the length of a line entity.
    int                   line_id[1], width_dim;
    Pro2dPnt              point;
    ProSectionPointType   pnt_type[1];

    line_id[0] = 1;
    point[0] = 5.0;
    point[1] = 1.0;
    pnt_type[0] = PRO_ENT_WHOLE;

    ProSecdimCreate (section, line_id, pnt_type, 1,
                     PRO_TK_DIM_LINE, point,
                     &width_dim);
The following code fragment shows how to create a dimension for the horizontal distance between two arc ends.
    int                   arc1_id, arc2_id, arc1_end2, arc2_end1, 
                          dist_dim;
    Pro2dPnt              point;
    int                   entities[2];
    ProSectionPointType   pnt_types[2];

    pnt_types[0] = PRO_ENT_START;
    pnt_types[1] = PRO_ENT_END;
    entity[0]    = arc1_end2;
    entity[1]    = arc2_end1;
    point[0]     = 5.0;
    point[1]     = 5.0;

    ProSecdimCreate (section, entities, pnt_types, 2,
                     PRO_TK_DIM_PNT_PNT_HORIZ, point, &dist_dim);
The ProSecdimDiam...() functions extend the dimension creation functionality to include diameters for sections used to create revolved features. Function ProSecdimDiamSet() converts a specified section dimension (between a centerline and another entity) into a diameter dimension. ProSecdimDiamClear() does the opposite, converting a diameter dimension into a regular one. Use function ProSecdimDiamInquire() to determine if a dimension is a diameter dimension.
The function ProSecdimStrengthen() converts a weak dimension to a strong dimension.
You can lock or unlock sketch dimensions. Locking of dimensions avoids modifications to the sections outside the sketcher mode. The function ProSecdimIsLocked() determines whether a sketch dimension is locked. Use the function ProSecdimLockSet() to lock or unlock a specified dimension.
Example 1: Creating Spline Point Dimensions in Sections
The sample code in Ug3DSectSplineDim.c located at <creo_toolkit_loadpoint>/protk_appls/pt_userguide/ptu_featcreat shows how to create a Section dimension between the first and last interpolation point of a Spline.
Error Reporting
Functions Introduced:
Both ProSectionSolve() and ProSectionRegenerate() might result in a list of errors about the entities in the section. These errors are stored in an opaque structure called ProWSecerror. Before calling one of these functions, use ProSecerrorAlloc() to allocate memory for an error structure, then pass the pointer to the error structure to ProSectionSolve() or ProSectionRegenerate().
You can add application-specific section errors to an error structure. To do this, call the function ProSecerrorAdd().
The function ProSecerrorCount() tells you how many error messages are contained in the error structure. The errors themselves are identified by sequential integers, so you can step through the list. Use the function ProSecerrorMsgGet() to get the text of each message. Use the function ProSecerrorItemGet() to get the identifier of the problem entity that caused a specific error message. To free the allocated memory, call the function ProSecerrorFree().
A Creo TOOLKIT application that builds sections generally aims to make them complete and correct without any interactive help from the Creo Parametric user. Therefore, the errors reported by the functions ProSectionSolve() and ProSectionRegenerate() are directed at the Creo TOOLKIT developer as a debugging aid, rather than at the final Creo Parametric user.
The following code fragment shows a call to ProSectionSolve() and an analysis of the errors produced.
ProWSecerror   errors;
int            n_errors, e;
ProError       status;
ProMsg         wmsg;
char           msg[PRO_PATH_SIZE];
int            ent_id;

ProSecerrorAlloc (&errors);
status = ProSectionSolve (section, &errors);
if (status != PRO_TK_NO_ERROR)
{
    ProSecerrorCount (&errors, &n_errors);
    for (e = 0; e < n_errors; e++)
    {
         ProSecerrorMsgGet (errors, e, wmsg);
         ProWstringToString (msg, wmsg);
         ProSecerrorItemGet (errors, e, &ent_id);
         printf ("%s: Problem ID, %d\n", msg, ent_id);
    }
    ProSecerrorFree (&errors);
    return (-1);
}
Retrieving and Saving a Section
Functions Introduced:
To retrieve a section from disk, use the function ProMdlnameRetrieve() with the model type PRO_2DSECTION. You can save a section to a file using the function ProMdlSave().
You can also retrieve or copy a section from a feature. The function ProFeatureNumSectionsGet() finds the number of sections in the specified feature. Given a feature handle and section index, ProFeatureSectionCopy() initializes and returns a section handle to a section copied from the specified feature. Memory for this section is controlled by the Creo TOOLKIT application and must therefore be freed by a call to ProSectionFree().
Example 1: Creating a Section Model
The sample code in UgSectModelCreate.c located at <creo_toolkit_loadpoint>/protk_appls/pt_userguide/ptu_featcreat illustrates how to use all the functions described in this section to create a section model.