8 Jul, 2019

## Making Use of Resource Tables

We can use EKL code to call reusable features Actions, Powercopies, UDFs, and Engineering Templates. To do this, we need to define them as Resources by adding them to a Resource Table. Resources can be inserted from any Representation in a Resource Table. However the Resource Table itself has to be inside the same Representation where the calling EKL code exists. Alternatively, we can add items, at a Collaborative Space level, to a KnowledgeResource. This can be done from the DataSetup app while logging in as Owner or Administrator to the Default collaborative space.

The main benefit from adding resources to Resource Tables and KnowledgeResource Tables is that they allow us to collect items from different Representations in a single location. I posted an earlier example where I defined and called custom EKL functions with the help of a Resource Table. I’ll show a few more example today.

### Calling Actions From A Resource Table

We can add Actions to a resource table and call them using the function: AccessResource( resourceName, resourceType). Let’s take a look.

Let’s reuse the Action we created in this previous post, (which builds a tree) and call it from a local Resource Table:

This is the code for the Action above

let treeAction(AdvisorAction)
treeAction.Run()


### Calling Actions From A KnowledgeResource Table

In this example, we’ll call an Action from a KnowledgeResource, that is available the Collaborative Space. We’ll write a simple Action that print to the screen the names of nested VPMs.

//get the root
let root(VPMReference)
root = GetEditorRoots("VPMReference").GetItem(1)

let refs,repRefs, all(List)
//get the nested physical products
refs =root.Query("VPMReference","")

//get nested representation references
repRefs =root.Query("VPMRepReference","")

//join both lists
all = refs + repRefs

//for each item
let item(Feature)
for item inside all{
//notify is a method that will bring up a yellow pop-up
//to the top right corner of a CATIA window with text inside.
Notify( item.Name)
}


Let’s add it action to the KnowledgeResources table in DataSetup, which was appended to the Corporate Collaborative Space.

Calling The Resource
Now let’s call it:

let print(AdvisorAction)
print.Run()


The main idea here is that Actions can be stored in other Representations, then be collected in a single Resource table or a KnowledgeResource table for later use.

### Instantiating UDFs And Engineering Templates

We can Instantiate PowerCopies, UDFs and Engineering Templates using the function InstantiateTemplate(templateNameInResource, parent) when the calling EKL code is an Actions. In the case of KnowledgePatterns, the funtion to use is CreateOrModifyTemplate( templateName, parent, KnowledgePatternList, index). Note that Engineering Templates can not be called from a KnowledgePattern. Let’s take a look:

Here is the code for calling the UDF above:

let myUDF(UserFeature)
myUDF = InstantiateTemplate("myUDF", Geometrical Set.2 )
EndModifyTemplate(myUDF)

//note that if the UDF requires inputs, we'll need to
//set them before the EndModifyTemplate method.
//we set inputs using the function myUDF.SetAttributeObject(udfInputName, input)


Here is the code for instantiating an Engineering Template:

let root(VPMReference)
root = GetEditorRoots("VPMReference").GetItem(1)

let temp(Feature)
temp = InstantiateTemplate("myTemplate", root)
temp.SetAttributeObject("XY", xy plane )
EndModifyTemplate(temp)


Note that we call UDFs, PowerCopies, and Engineering Templates from a DataSetup Resource Table in a similar fashion the PrintAssembly example.

### Inserting a VPM From a Resource Table

We can also instantiate copies of a Physical Product in assembly from a Resource Table. This is useful when the goal is to simply insert several instances of a single assembly and possibly apply assembly constraints as shown by Guido. For example, a Window Panel on a building, or a Robot assembly on a factory floor. Inserting a Physical Product requires locating the host VPMReference then calling its method: ManageInstance("nameInTable", "", "NewName").

The first variable is the name of the resource in the Resource Table. This second argument is used (as a query) only when looking up a VPMReference from a Catalog that is inside a Resource Table. I omitted this example because it is a special use case, and because the Resource Tables offers greater flexibility. So I passed an empty string for the second argument. The third argument is the name of the new instance when inserted. This name needs to be unique for each instance. If the parent already contains an instance with a similar name, then nothing will be inserted.

This is the code from the example above:

let root(VPMReference)
//get the root
root = GetEditorRoots("VPMReference").GetItem(1)

//insert an instance using the resource myVPM and call it MynewVPM
root.ManageInstance("myVPM", "", "MyNewVPM")


Tags: , , , ,