Relations
This section describes how to access relations on all models and model items in Creo application using the methods provided in Creo Object TOOLKIT C++.
Accessing Relations
In Creo Object TOOLKIT C++, the set of relations on any model or model item is represented by the pfcRelationOwner interface. Models, features, surfaces, and edges inherit from this interface, because each object can be assigned relations in Creo application.
Methods Introduced:
The method pfcRelationOwner::RegenerateRelations regenerates the relations assigned to the owner item. It also determines whether the specified relation set is valid.
The method pfcRelationOwner::DeleteRelations deletes all the relations assigned to the owner item.
The method pfcRelationOwner::GetRelations returns the list of initial relations assigned to the owner item as a sequence of strings.
The method pfcRelationOwner::SetRelations assigns the sequence of strings as the new relations to the owner item.
The method pfcRelationOwner::EvaluateExpression evaluates the given relations-based expression, and returns the resulting value in the form of the pfcParamValue object. Refer to the section The ParamValue Object in the section Dimensions and Parameters for more information on this object.
The method wfcWRelationOwner::EvaluateExpression has been deprecated. Use the method wfcWRelationOwner::EvaluateExpressionWithUnits instead.
Use the method wfcWRelationOwner::EvaluateExpressionWithUnits if you want the units of the relation to be considered while evaluating the expression. Specify the input argument Consider_units as true to consider the units. In this case, the result of the relation is returned along with its unit as wfcParamValueWithUnits object. Refer to the section The ParamValue Object in the section Dimensions and Parameters for more information on this object.
The method wfcWRelationOwner::UseUnits specifies if units must be considered while solving the specified relation. Use the method wfcWRelationOwner::UnitsUsed to check if units will be considered while solving the relation.
Accessing Post Regeneration Relations
Method Introduced:
The method pfcModel::GetPostRegenerationRelations lists the post-regeneration relations assigned to the model. It can be NULL, if not set.
Note
To work with post-regeneration relations, use the post-regeneration relations attribute in the methods pfcRelationOwner::SetRelations, pfcRelationOwner::RegenerateRelations and pfcRelationOwner::DeleteRelations.
You can regenerate the relation sets post-regeneration in a model using the method pfcModel::RegeneratePostRegenerationRelations.
To delete all the post-regeneration relations in the specified model, call the method pfcModel::DeletePostRegenerationRelations.
Adding a Customized Function to the Relations Dialog Box
Methods Introduced:
The method pfcBaseSession::RegisterRelationFunction registers a custom function that is included in the function list of the Relations dialog box in Creo Parametric. You can add the custom function to relations that are added to models, features, or other relation owners. The registration method takes the following input arguments:
•  Name—The name of the custom function.
•  RelationFunctionOptions—This object contains the options that determine the behavior of the custom relation function. Refer to the section Relation Function Options for more information.
•  RelationFunctionListener—This object contains the action listener methods for the implementation of the custom function. Refer to the section Relation Function Listeners for more information.
Note
Creo Object TOOLKIT C++ relation functions are valid only when the custom 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, these errors can be commented until needed at a later time when the relations functions are reactivated in a Creo Parametric session.
Relation Function Options
Methods Introduced:
Use the method pfcRelationFunctionOptions::Create to create the pfcRelationFunctionOptions object containing the options to enable or disable various relation function related features. Use the methods listed above to access and modify the options. These options are as follows:
•  ArgumentTypes—The types of arguments in the form of the pfcRelationFunctionArgument object. By default, this parameter is null, indicating that no arguments are permitted.
Use the method pfcRelationFunctionArgument::Create to create the pfcRelationFunctionArgument object containing the attributes of the arguments passed to the custom relation function.
These attributes are as follows:
  Type—The type of argument value such as double, integer, and so on in the form of the pfcParamValueType object.
  IsOptional—This boolean attribute specifies whether the argument is optional, indicating that it can be skipped when a call to the custom relation function is made. The optional arguments must fall at the end of the argument list. By default, this attribute is false.
•  EnableTypeChecking—This boolean attribute determines whether or not to check the argument types internally. By default, it is false. If this attribute is set to false, Creo does not need to know the contents of the arguments array. The custom function must handle all user errors in such a situation.
•  EnableArgumentCheckMethod—This boolean attribute determines whether or not to enable the arguments check listener function. By default, it is false.
•  EnableExpressionEvaluationMethod—This boolean attribute determines whether or not to enable the evaluate listener function. By default, it is true.
•  EnableValueAssignmentMethod—This boolean attribute determines whether or not to enable the value assignment listener function. By default, it is false.
Relation Function Listeners
The interface pfcRelationFunctionListener provides the method signatures to implement a custom relation function.
Methods Introduced:
The method pfcRelationFunctionListener::CheckArguments checks the validity of the arguments passed to the custom function. This listener method takes the following input arguments:
•  The owner of the relation being evaluated
•  The custom function name
•  A sequence of arguments passed to the custom function
If the implementation of this method determines that the arguments are not valid for the custom function, then the listener method returns false. Otherwise, it returns true.
The method pfcRelationFunctionListener::EvaluateFunction evaluates a custom relation function invoked on the right hand side of a relation. This listener method takes the following input arguments:
•  The owner of the relation being evaluated
•  The custom function name
•  A sequence of arguments passed to the custom function
You must return the computed result of the custom relation function.
The method pfcRelationFunctionListener::AssignValue evaluates a custom relation function invoked on the left hand side of a relation. It allows you to initialize properties to be stored and used by your application. This listener method takes the following input arguments:
•  The owner of the relation being evaluated
•  The custom function name
•  A sequence of arguments passed to the custom function
•  The value obtained by Creo from evaluating the right hand side of the relation