CATPackageGenerativeKnowledgeTypes Types: TemplateInstance

This type lets you handle templates (user features, power copies, and engineering templates) that are instantiated through a script (objects returned by the InstantiateTemplate and CreateorModifyTemplate functions).

This page discusses:

Inheritance Path

ObjectType
 Feature
  TemplateInstanceelem 

Attributes

Name used in EKL NLS Name Type Comment
ComponentsToReplace ComponentsToReplace List Returns a list of the components for which the engineering template expects a replacing reference.
CreatedInstances CreatedInstances List Returns the list of the duplicated roots. For engineering templates only.
InputNames InputNames List Returns the list containing the name of the inputs you must valuated on the template.
OutputNames OutputNames List When working with:
  • User features: returns the name of the outputs identified by the user feature. It can be accessed using the GetAttribute function on the created instance.
  • Power Copies: returns the list of the power copy components (those contained in the template before the instantiation). It can be accessed on the created instances.
ParameterNames ParameterNames List Returns the list containing the name of the parameters published on the template.
RootContext RootContext Feature Lets you specify the root of the current assembly. This information can be used when valuating inputs for creating contextual imports. If this information is missing, you cannot select an input located outside the instantiation destination.

Methods

The following methods are associated with this type:

Example

let templateFeature(Feature)

templateFeature = InstantiateTemplate("UDF",destination)

if templateFeature == NULL
{
                Message("Instantiation failed on UDF")
}
else
{
                let udfInstance(TemplateInstance)
                let lInputNames(List)
                let lParamNames(List)
                set udfInstance = templateFeature // Cast to TemplateInstance for specific attributes
                
                if udfInstance.InputNames.Size() <> 5 OR udfInstance.InputNames->GetItem(1) <> "Point.5" OR udfInstance.InputNames->GetItem(2) <> "Point.2"
                {
                                Message("Invalid inputs on UDF TemplateInstance")
                }
                if udfInstance.ParameterNames.Size() <> 3
                {
                                Message("Invalid parameters on UDF TemplateInstance")
                }
                if udfInstance.OutputNames.Size() <> 2
                {
                                Message("Invalid outputs on UDF TemplateInstance")
                }

                udfInstance->SetAttributeObject("Point.1",p1 )
                udfInstance->SetAttributeObject("Point.2",p2)
                udfInstance->SetAttributeObject("Point.3",p3)
                udfInstance->SetAttributeObject("Point.4",p4)
                udfInstance->SetAttributeObject("Point.5",p5)
                
                EndModifyTemplate(udfInstance)
}

ImportManager

You can import features from a representation into another with the option of keeping the position in the new instance or keeping a link to the original feature. The two main import options are: as reference and contextual import.

Table 1. Attributes
Name Input/Output Type Comment
SourcePathString In Feature/String The input feature or path string to be copied (mandatory).
TargetPathString In Feature/String The location where the result feature is created (mandatory).
ImportResult Out Feature The copied feature.
ImportWithLink In Boolean Creates a link between the source and result features.
IsImportContextual In Boolean Keeps the source feature position when creating the result feature (default to FALSE).
ExecutionStatus Out Integer
  • 0 if the creation is successful
  • 1 if the creation is successful but with warnings
  • ≥2 if errors are detected
ExecutionMessage Out String The message that contains warnings and errors.
CreateImport Function Creates the new feature and valuates the result feature, the execution status, and the message.

Create Import as Reference

To create an import as reference, meaning without taking the source feature spatial transformation into account, provide the SourcePathString, TargetPathString, valuate the options and get the result. For example:

// Create the manager
let KnowlImportManager(ImportManager)
KnowlImportManager = new(“KnowledgeImportManager”, “ImportManager”, NULL)

// Get the source feature to copy and target location, either by code or by selection
// let sourceToCopy, target (Feature)

// Give them to the manager
KnowlImportManager.SourcePathString = sourceToCopy
KnowlImportManager.TargetPathString = target

// Create the import
KnowlImportManager.CreateImport()

// Display the return code
let exitStatus(Integer)
let exitMsg(String)
existStatus = KnowlImportManager.ExecutionStatus
exitMsg = KnowlImportManager.ExecutionMessage

Notify(“Import exited with status: #”, exitStatus)
Notify(“Message: #”, exitMsg)

// Get the import result
if exitStatus <= 1
{
	let importResult(Feature)
importResult = KnowlImportManager.ImportResult
	Message(“Feature created is #”, importResult.Name)
}

Create a Contextual Import

To create a contextual import, meaning taking the spatial transformation of the source feature into account within the if required occurrence, modify the script above. Provide the feature path strings and the occurrence containing both representations. For example:

let rootOccurrence(ProductOccurrence) // can also be a VPMReference
// Get the root occurrence
// ...
KnowlImportManager.PathRoot = rootOccurrence 
KnowlImportManager.SourcePathString = “path\to\source”
KnowlImportManager.TargetPathString = “path\to\target”
KnowlImportManager.IsImportContextual = TRUE

Link the Source Feature and the Result Feature

Link the source feature and the result feature by using the following script:

// Keep link with source 
KnowlImportManager.ImportWithLink = TRUE

TemplateInstantiationOptionsType

This type lets you select the instantiation destination during power copy and user feature instantiation in EKL scripts.

Inheritance Path

ObjectType
 Feature
  TemplateInstantiationOptionsType

Attributes

Name Required Type Comment
InsideInstantiationMode

Integer
  • 0 for After destination.
  • 1 for Inside destination.

Notes:
  • The possible instantiation mode depends on the destination feature. When the destination is a feature, the Inside destination is unavailable, thereby making After the default value.
  • Based on your selected EKL instantiation options, the correct Inside or After destination is applied according to the selected destination.
  • In cases where neither Inside nor After options are available, the instantiation is performed Inside the first valid destination or a warning appears.

Example

let templateInstance(Feature)
let instantiationDestination(Feature)
[...] /* Gather inputs here */

let templOption(TemplateInstantiationOptionsType)
templOption = new("TemplateInstantiationOptionsType", "TemplOptionName", NULL)
templOption.InsideInstantiationMode = 0

templateInstance = InstantiateTemplate("UserFeatureName", instantiationDestination, templOption)

if templateInstance <> NULL 
{
[...] /* Gather inputs here with templateInstance->SetAttributeObject */
}

Example of CreateOrModifyTemplate (only for Knowledge Patterns)

let templateInstance(Feature)
let instantiationDestination(Feature)
[...] /* Gather inputs here */

let templOption(TemplateInstantiationOptionsType)
templOption = new("TemplateInstantiationOptionsType", "TemplateOptionName", NULL)
templOption.InsideInstantiationMode = 1

templateInstance = CreateOrModifyTemplate("UserFeatureName", instantiationDestination, `Relations\Knowledge Pattern.1\List.1`, templOption)

if templateInstance <> NULL 
{
[...] /* Gather inputs here with templateInstance->SetAttributeObject */
}