Core: Relations
This section describes how to access relations on all models and model items in Creo Parametric using the functions provided in Creo TOOLKIT.
Relations
Functions Introduced:
Superseded Functions:
The object ProRelset represents the entire set of relations on any model or model item. It is an opaque handle whose contents can be accessed only through the functions described in this section.
Creo TOOLKIT can only access the relations of the models and model item types as listed in the table below:
Model Types
Description
PRO_PART
Part
PRO_ASSEMBLY
Assembly
PRO_DRAWING
Drawing
PRO_REPORT
Report
PRO_DIAGRAM
Diagram
PRO_DWGFORM
Format
PRO_UDF
User-defined feature
PRO_FEATURE
Feature
PRO_SURFACE
Surface
PRO_EDGE
Edge
PRO_WELD_PARAMS
Weld parameters
PRO_BND_TABLE
Bend table
PRO_EXTOBJ
External objects
PRO_PATREL_FIRST_DIR
Pattern direction 1
PRO_PATREL_SECOND_DIR
Pattern direction 2
PRO_RELOBJ_QUILT
Quilt
PRO_RELOBJ_CRV
Curve
PRO_RELOBJ_COMP_CRV
Compound curve
PRO_RELOBJ_ANNOT_ELEM
Annotation Element
PRO_RELOBJ_NC_STEP_OBJECT
NC Step Table Entry
PRO_RELOBJ_NC_STEP_MODEL
NC Step Table Model
The function ProModelitemToRelset() outputs a ProRelset object that contains the set of initial relations owned by the given model item. (Note that not all model items can have relations sets associated with them—only the types listed in the table.)
Use the function ProRelsetPostregenerationInit() to initialize the post-regeneration data object ProRelset. The object contains post-regeneration relations in the specified model.
Note
According to your requirement you can pass the initial relations, or the post-regeneration relations data object, ProRelset as input to the functions ProRelsetRelationsGet(), ProRelsetRelationsSet(), ProRelsetRegenerate() and ProRelsetDelete().
To get the relations of a feature pattern, the model item type should be either PRO_PATREL_FIRST_DIR or PRO_PATREL_SECOND_DIR, and the identifier should be that of the dimension on the pattern leader that drives the pattern in that direction. To find the identifiers of the pattern dimension, use the functions described in the section Manipulating Patterns.
The function ProSolidRelsetVisit() enables you to visit all the relation sets on every model item in a model. Like other visit functions, it calls a user-supplied action function for each relation set, although there is no filter function. If the user-supplied function returns any status other than PRO_TK_NO_ERROR, visiting will stop. The model types PRO_PART, PRO_ASSEMBLY, and PRO_DRAWING are supported.
The function ProRelsetToModelitem() outputs the model item that is the owner of the specified ProRelset.
You can regenerate a relation set using the function ProRelsetRegenerate(). This function also determines whether the specified relation set is valid. If an error occurred, the function returns a status other than PRO_TK_NO_ERROR.
To create a new relation set for a model item, use the function ProRelsetCreate(). If a relation set already exists for that item, the function returns PRO_TK_E_FOUND.
To delete all the relations in a specified relation set, call the function ProRelsetDelete().
The function ProRelsetRelationsGet() extracts the text of a set of relations described by a ProRelset object. This function takes two arguments: the ProRelset for the relation set and a preallocated expandable array. The elements of the expandable array are of type ProLine (wide strings).
The function ProRelsetRelationsSet() creates a ProRelset object from an expandable array of ProLine objects that describes the relations as text. For details of the syntax and use of relations, see the Creo Parametric help.
Note
Existing relations will be overwritten by a call to ProRelsetRelationsSet().
The function ProRelationEvalWithUnits() evaluates a line of a relation set and outputs the resulting value in the form of a ProParamvalue structure. Specify the input argument consider_units as true if you want the units of the relation to be considered while evaluating the relation. In this case, the result of the relation is returned along with its unit. See the section Core: Parameters for a description of this data structure. The use of special pattern relation symbols such as memb_v or idx1 is not supported; instead, replace these symbols with the corresponding dimension value or number, and evaluate them individually.
The function ProRelationEvalWithUnits() cannot be used for referencing external symbols.
In Creo Parametric 8.0.0.0 and later, the function ProRelationEvalWithUnits() is deprecated. Use the function ProRelationEvalWithUnitsRefResolve() instead.
The function ProRelationEvalWithUnitsRefResolve() evaluates the expression that is specified on the right side of a relation line and returns the value in the form of ProParamvalue structure. Relations with symbols that are referenced by parameters or dimensions on a different model can be evaluated using the function ProRelationEvalWithUnitsRefResolve(). Specify the input argument consider_units as true if you want the units of the relation to be considered while evaluating the relation. In this case, the result of the relation is returned along with its unit. See the section Core: Parameters for a description of this data structure. The use of special pattern relation symbols such as memb_v or idx1 is not supported; instead, replace these symbols with the corresponding dimension value or number, and evaluate them individually.
The function ProRelsetUnitsSensitiveSet() specifies that units must be considered while solving the specified relation. Use the function ProRelsetIsUnitsSensitive() to check if units must be considered while solving the relation.
Adding a Customized Function to the Relations Dialog in Creo Parametric
Functions Introduced:
The function ProRelationFunctionRegister() registers a custom function that is visible to users in the Creo Parametric relations dialog. To register a custom function you may supply the following:
•  An array of expected arguments. The arguments are described by their type (double, integer, etc) and attributes indicating if the argument can be skipped when the user calls the relations function. These optional arguments must fall at the end of the argument list.
•  A Boolean indicating whether or not to check argument types internally. If the Boolean is set not to check the argument types internally, Creo Parametric does not need to know the contents of the arguments array. The custom function you create must handle all the user errors in this situation.
•  An arguments check function, which can be used to verify the input arguments.
•  A read function, which provides the value of the function when used in the right-hand side of a relation. For example
d12  =  ptk_user_function (0.5, 5, true, inch)
•  A write function, which receives the value when the function is used in the left-hand side of the relation. For example:
ptk_user_function (assigned_value) = 14.0;
•  All the callback functions are optional and may be NULL.
Note
Creo TOOLKIT registered relations are valid only when the function has been registered by the application. If the application is not running or not present, models that contain user-defined relations cannot evaluate these relations. In this situation, the relations are marked as errors, however, they can be commented until needed at a later time when the relation functions are reactivated.
The function type ProRelationReadFunction() is called when a custom relation function is used on the right-hand side of the relation. You should output the computed value of the custom relation function which is used to complete evaluation of the relation.
The function ProRelationWriteFunction(), is called when a custom function is used on the left hand side of a relation. The value of the right-hand side of the relation is provided as an input. You can use this type of function to initialize properties to be stored and used by your Creo TOOLKIT application.
The function ProRelationArgscheckFunction() performs the argument check function for a custom relation function. Return PRO_TK_NO_ERROR to indicate that the arguments passed to the relation are valid. Any other error causes an error to be displayed in the Relations dialog.
The following example creates three externally defined functions to be available in the relations dialog:
ptk_set_a and ptk_set_b are used from the left-hand side of relations to initialize double values to stored "A" and "B" variables.
ptk_eval_ax_plus_b returns the computation of Ax+B, where x is an input to the function.
These functions are available only while the Creo TOOLKIT application is running. Models can be saved with relations referencing these functions, but these models will have relation errors if retrieved while the application is not running.
Code Example
The sample code in the file UgCustomRelationFunction.c located at <creo_toolkit_loadpoint>/protk_appls/pt_userguide/ptu_param shows how to use the "Write" function for the assignment of the parameters used for calculation.