Relations
This section describes how to access relations on all models and model items in Creo Parametric using the methods provided in the VB API.
Accessing Relations
In the VB API, the set of relations on any model or model item is represented by the IpfcRelationOwner interface. Models, features, surfaces, and edges inherit from this interface, because each object can be assigned relations in Creo Parametric.
Methods and Properties Introduced:
  • IpfcRelationOwner.RegenerateRelations()
  • IpfcRelationOwner.DeleteRelations()
  • IpfcRelationOwner.Relations
  • IpfcRelationOwner.EvaluateExpression()
  • The method IpfcRelationOwner.RegenerateRelations() regenerates the relations assigned to the owner item. It also determines whether the specified relation set is valid.
    The method IpfcRelationOwner.DeleteRelations() deletes all the relations assigned to the owner item.
    The property IpfcRelationOwner.Relations returns the list of initial relations assigned to the owner item as a sequence of strings.
    The method IpfcRelationOwner.EvaluateExpression() evaluates the given relations-based expression, and returns the resulting value in the form of the IpfcParamValue object. Refer to the section The ParamValue Object in the section Dimensions and Parameters for more information on this object.
    Example 1: Adding Relations between Parameters in a Solid Model
    The sample code in the file pfcRelationsExamples.vb located at <creo_vbapi_loadpoint>/vbapi_examples demonstrates how to add relations between parameters in a solid model.
    Accessing Post Regeneration Relations
    Method and Property Introduced:
  • IpfcModel.PostRegenerationRelations
  • IpfcModel.RegeneratePostRegenerationRelations()
  • IpfcModel.DeletePostRegenerationRelations()
  • The property IpfcModel.PostRegenerationRelations 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 IpfcRelationOwner.RegenerateRelations() and IpfcRelationOwner.DeleteRelations().
    You can regenerate the relation sets post-regeneration in a model using the method IpfcModel.RegeneratePostRegenerationRelations().
    To delete all the post-regeneration relations in the specified model, call the method IpfcModel.DeletePostRegenerationRelations().
    Adding a Customized Function to the Relations Dialog Box in Creo Parametric
    Methods Introduced:
  • IpfcBaseSession.RegisterRelationFunction
  • The method IpfcBaseSession.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.
    •  IpfcRelationFunctionOptions—This object contains the options that determine the behavior of the custom relation function. Refer to the section Relation Function Options for more information.
    •  IpfcRelationFunctionListener—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
    The VB API 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 and Properties Introduced:
  • CCpfcRelationFunctionOptions.Create()
  • IpfcRelationFunctionOptions.ArgumentTypes
  • CCpfcRelationFunctionArgument.Create()
  • IpfcRelationFunctionArgument.Type
  • .IpfcRelationFunctionArgument.IsOptional
  • IpfcRelationFunctionOptions.EnableTypeChecking
  • IpfcRelationFunctionOptions.EnableArgumentCheckMethod
  • IpfcRelationFunctionOptions.EnableExpressionEvaluationMethod
  • IpfcRelationFunctionOptions.EnableValueAssignmentMethod
  • Use the method CCpfcRelationFunctionOptions.Create() to create the IpfcRelationFunctionOptions 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 IpfcRelationFunctionArgument object. By default, this parameter is null, indicating that no arguments are permitted.
    Use the method CCpfcRelationFunctionArgument.Create() to create the IpfcRelationFunctionArgument 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 IpfcParamValueType 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 Parametric 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 IpfcRelationFunctionListener provides the method signatures to implement a custom relation function.
    Methods Introduced:
  • IpfcRelationFunctionListener.CheckArguments
  • IpfcRelationFunctionListener.AssignValue
  • IpfcRelationFunctionListener.EvaluateFunction
  • The method IpfcRelationFunctionListener.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 IpfcRelationFunctionListener.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 IpfcRelationFunctionListener.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 Parametric from evaluating the right hand side of the relation
    Example 2: Adding and Implementing a New Custom Relation Function
    The sample code in the file pfcRelationsExamples.vb located at <creo_vbapi_loadpoint>/vbapi_examples has the function addRelation function, which defines the options for a new custom relation function and registers it in the current session. The RelationListener class contains the CheckArguments, AssignValue and EvaluateFunction listener methods that are called when the custom relation function is used.