Creating Expressions - Tutorial

About Creating Expressions

This section provides information on creating the different types of expressions. It also contains information on executing copy expressions. The examples uses the classes, subclasses, and the properties available in the Expression Management data model. You can create six types of expressions. They are:

These sections describe how to create these expressions and how to execute copy expressions. This example use the classes, subclasses, and the properties available in the Expression Management data model.

Creating Simple Regular Expressions

You can create a simple regular expression by this example.

Requirement:

To calculate the Preference Score of an item, as in this table.

Property Names

WW Approval, Part Status

Target Property

Preference Score

Associated Class

Associated Class

Calculate the Preference Score of the item by writing this Expression script.

if wwApproval == 0:
retValue = 10
elif wwApproval == 1:
retValue = 40
if PartStatus == 'PRE-PRODUCTION':
retValue = retValue + 10
elif PartStatus == 'PRODUCTION':
retValue = retValue + 20

Creating a simple expression involves:

  • Creating the variables.

  • Writing the expression script.

  • Linking the variables to the expression.

This task explains the procedure to create the variables:
  1. Using the Class Browser, find and select the Variable class. Click New Item. The properties appear in the Edit page.

  2. Specify the values for the Variable class properties, as described in this table. Click Insert.
    Property Name

    Specify These Values...

    Variable Name

    WWApproval

    PartStatus

    Class Property Label

    WW Approval

    Part Status

    Owner Class

    Item

    item

    Replace Null With

    0

    NULL

Note: The values specified in columns 2 and 3 of the table above are two independent items in the Variable class. The same convention is followed throughout This section.

This task explains the procedure to write the expression:
  1. Using the Class Browser, find and select the Expression class. Click New Item. The properties appear in the Edit page.

  2. Specify the values for the Expression class properties, as described in this table and click Insert.
    Property Name

    Specify These Values...

    Expression Name

    Preference score of the Item(s)

    Description

    Calculates the preference score of the item.

    Expression

    retValue = 0
    if wwApproval == 0:
    retValue = 10
    elif wwApproval == 1:
    retValue = 40
    if PartStatus == 'PRE-PRODUCTION':
    retValue = retValue + 10
    elif PartStatus == 'PRODUCTION':
    retValue = retValue + 20
    elif PartStatus == 'PROTOTYPE':
    retValue = retValue + 30
    elif PartStatus == 'SERVICE':
    retValue = retValue + 40
    elif PartStatus == 'CONCEPT':
    retValue = retValue + 50

    Expression Language

    Python. Select the value from the Valid Values dialog box.

    Expression Type Regular. Select the value from the Valid Values dialog box.
    Class Label Item
    Class Property Label Preference Score
    Owner Class Item
    Evaluation Mode Online. Select the value from the Valid Values dialog box.
    Return Variable Name retValue. Select the value from the Valid Values dialog box.
    Is Active Yes

This task explains the procedure to link the variables to the expressions:
  1. Using the Class Browser, find and select the Expression Variable Path class. Click New Item. The properties appear in the Edit window.

  2. Specify the values for the Expression Variable Path class properties, as described in this table and click Insert.
    Property Name

    Specify These Values...

    Expression Name

    Preference score of the Item(s)

    Preference score of the Item(s)

    Variable Name

    WWApprova

    PartStatus

    Is Head

    Yes

    Yes

 

Creating Expressions With Outgoing Pointer Properties

You can create an expression with outgoing pointer properties by this example.

Requirement:

To generate the description of the parts based on the part name and number, scenario number, and the preferred status, as described in this table.

Property Names

Name, Item Number, Preferred Status, and ScenarioNumber. Name and ScenarioNumber are outgoing pointer properties.

Target Property

Part Description

Associated Class

Internal Item

Generate the description of the parts by writing the this Expression script.

retValue=str(ItemNumber)+','+str(PreferredStatus)+','+str(PartStatus)+','+str(Name)+','+str(ScenarioNumber)

Creating an expression with an outgoing pointer property involves these steps.

  • Create the variables.

  • Write the expression script.

  • Link the variables with or without outgoing pointer properties to the expression.

This task explains the procedure to create the variables:
  1. Using the Class Browser, find and select the Variable class.

  2. Click New Item. The properties appear in the Edit page.

  3. Specify the values for the Variable class properties, as described in this table, and click Insert.
    Property Name

    Specify These Values...

    Variable Name

    Name

    ItemNumber PreferredStatus ScenarioNumber

    Class Property Label

    Name

    ItemNumber PreferredStatus ScenarioNumber

    Owner Class

    Yes

    Item Item ScenarioNumber
    Replace Null With NoPartName NULL None 0

 

This task explains the procedure to write expression script:
  1. Using the Class Browser, find and select the Expression class.

  2. Click New Item. The properties appear in the Edit page.

  3. Specify the values for the Expression class properties, as described in this table, and click Insert.
    Property Name

    Specify These Values...

    Expression Name

    Part Description Generator

    Description

    Generates a description for a particular part.

    Expression

    retValue=ItemNumber+','+Preferred-Status+','+PartStatus+','+str(Name)+','+str(ScenarioNumber)

    Expression Language

    Select Python from the Valid Values dialog box.

    Expression Type Select Regular from the Valid Values dialog box.
    Class Label Internal Item
    Class Property Label Part Description
    Owner Class Item
    Evaluation Mode Online. Select the value from the Valid Values dialog box.
    Return Variable Name retValue. Select the value from the Valid Values dialog box.
    Is Active Yes

This task explains the procedure to link the variables to the expression:
  1. Using the Class Browser, find and select the Expression Variable Path class. Click New Item. The properties appear in the Edit page.

  2. Specify the values for the Expression Variable Path class properties, as described in this table, and click Insert.
    Property Name

    Specify These Values...

    Expression Name

    Part Description Generator

    Part Description Generator

    Variable Name

    ItemNumber

    PreferredStatus

    Is Head

    Yes

    Yes

This task explains the procedure to link the variables (outgoing pointer properties) with the expression:
  1. Using the Class Browser, find and select the Expression Variable Path class. Click New Item. The properties appear in the Edit page.

  2. Specify the values for the Expression Variable Path class properties, as described in this table, and click Insert.
    Property Name

    Specify These Values...

    Expression Name

    Part Description
    Generator

    Part Description
    Generator
    Part Description
    Generator
    Part Description
    Generator

    Variable Name

    Name

    Name ScenarioNumber ScenarioNumber

    Pointer Class
    Property Label

     

    Product   Scenario
    Owner Class   Item   Item
    Pointer Type   Outgoing   Outgoing
    Expression   Part Description
    Generator
      Part Description
    Generator
    Variable   Name   ScenarioNumber
    Is Head N Yes No Yes

 

Creating Expressions With Incoming Pointer Properties

You can create an expression with incoming pointer properties by this example.

Requirement:

To calculate the preference score for the Internal Item of a project, as described in this table.

Property Name

Item

Target Property

Project Functional Reuse Score

Associated Class

Project

Calculate the preference score for the Internal Item by writing this Expression script.

retValue=ProjectFunctionalReuseScore

Write the Multi Value Parser Script as:

prefCount = 0
retValue = 0.0
for Score in argValue:
prefCount = prefCount + 1
retValue = retValue + Score
if prefCount > 0:
retValue = retValue / prefCount

Creating an expression with the Multi Value Parser Script involves these steps.

  • Creating the variable.

  • Writing the expression script.

  • Linking the variable to the expression.

  • Writing the multi value parser script.

This task explains the procedure to create the variable:
  1. Using the Class Browser, find and select the Variable class. Click New Item. The properties appear in the Edit page.

  2. Specify the values for the Variable class properties, as described in this table, and click Insert.
    Property Name

    Specify These Values...

    Variable Name

    ProjectFunctionalReuseScore

    Class Property Label

    Item

    Owner Class

    Parts for Projects

    Replace Null With

    0.0

This task explains the procedure to write the expression script:

  1. Using the Class Browser, find and select the Expression class. Click New Item. The properties appear in the Edit page.

  2. Specify the values for the Expression class properties, as described in this table, and click Insert.
     
    Property Name

    Specify These Values...

    Expression Name

    Project Functional Reuse Score - Project

    Description

    This expression computes the average of the preference scores of Internal Items, for a particular project.

    Expression

    retValue=ProjectFunctionalReuseScore

    Expression Language

    Python. Select the value from the Valid Values dialog box.

    Expression Type Regular. Select the value from the Valid Values dialog box.
    Class Label Project
    Class Property Label Project Functional Reuse Score
    Owner Class Project
    Evaluation Mode Online. Select the value from the Valid Values dialog box.
    Return Variable Name retValue. Select the value from the Valid Values dialog box.
    Is Active Yes

This task explains the procedure to link the variable to the expression:
  1. Using the Class Browser, find and select the Expression Variable Path class. Click New Item. The properties appear in the Edit page.

  2. Specify the values for the Expression Variable Path class properties, as described in this table, and click Insert.
    Property Name

    Specify These Values...

    Expression Name

    Project Functional Reuse Score - Project

    Variable Name

    ProjectFunctionalReuseScore

    Is Head

    Yes

This task explains the procedure to write the multi value parser script:
  1. Using the Class Browser, find and select the Multi Value Parser class. Click New Item. The properties appear in the Edit page.

  2. Specify the values for the Multi Value Parser class properties, as described in this table, and click Insert.
    Property Name

    Specify These Values...

    Expression Name

    Project Functional Reuse Score - Project

    Variable Name

    ProjectFunctionalReuseScore

    Parser Script

    prefCount = 0
    retValue = 0.0
    for Score in argValue:
    prefCount = prefCount + 1
    retValue = retValue + Score
    if prefCount > 0:
    retValue = retValue / prefCount

    Argument Variable Name argValue. Select the value from the Valid Values dialog box.
    Return Variable Name retValue. Select the value from the Valid Values dialog box.

 

Creating Expressions With Sub-Expressions

Create an expression with a sub-expression by following this example.

Requirement:

To calculate the part cost for an assembly based on the assembly item, standard cost, and the quantity, as described in this table.

Property Name

Item Number, Standard Part Cost, Assembly Cost, and Quality
Note: Assembly Cost is an incoming pointer property.

Target Property

Standard Part Cost

Associated Class

Item

Calculate the part cost for an assembly based on the assembly item, standard cost, and the quantity, by writing this regular expression script.

retValue=0.0
if NoOfChildren > 0:
retValue=AssemblyCost
else
retValue=OrgValue

Write the Sub-expression script as:

retValue=ComponentQuantity*StandardPartCost

Write the Multi Value Parser Script as:

retValue = 0.0
for Cost in argValue:
retValue = retValue + Cost

Creating an expression with a sub-expression involves these steps.

  • Creating the variables.

  • Writing the regular expression script.

  • Linking the variables with the expression.Linking the variables (outgoing pointer properties) with the expression.

  • Writing the sub-expression script.

  • Linking the variables (incoming pointer properties) with the expression.

  • Writing the multi value parser script.

This task explains the procedure to create the variables:
  1. Using the Class Browser, find and select the Variable class. Click New Item. The properties appear in the Edit page.

  2. Specify the values for the Variable class properties, as described in this table, and click Insert.
    Property Name

    Specify These Values...

    Variable Name

    NoOfChildren OrgValue ComponentQuantity Standard
    Part Cost
    AssemblyCost
    Class Property
    Label
    Item Number Standard
    Part Cost
    Quality Standard
    Part Cost
     
    Owner Class Item Item Assembly
    Item
    Item  
    Source>Expressio
    n Name
            Component
    Cost -
    Assembly Item
    Replace Null With 0 0 0 0 0

This task explains the procedure to write the regular expression script:
  1. Using the Class Browser, find and select the Expression class. Click New Item. The properties appear in the Edit page.

  2. Specify the values for the Expression class properties, as described in this table, and click Insert.
    Property Name

    Specify These Values...

    Expression Name

    Standard Part Cost - Item

    Description

    This expression computes the cost of the assembly.

    Expression

    retValue=0.0
    if NoOfChildren > 0:
    retValue=AssemblyCost
    else
    retValue=OrgValue

    Expression Language

    Python. Select the value from the Valid Values dialog box.

    Expression Type Regular. Select the value from the Valid Values dialog box.
    Class Label Item
    Class Property Label Standard Part Cost
    Owner Class Item
    Evaluation Mode Online. Select the value from the Valid Values dialog box.
    Return Variable Name retValue. Select the value from the Valid Values dialog box.
    Is Active Yes

This task explains the procedure to link the variables with the expression:
  1. Using the Class Browser, find and select the Expression Variable Path class. Click New Item. The properties appear in the Edit page.

  2. Specify the values for the Expression Variable Path class properties, as described in this table, and click Insert.
    Property Name

    Specify These Values...

    Expression Name

    Standard Part Cost - Item

    Variable Name

    OrgValue

    Is Head

    Yes

This task explains the procedure to link the variables (outgoing pointer properties) with the expression:
  1. Using the Class Browser, find and select the Expression Variable Path class. Click New Item. The properties appear in the Edit page.

  2. Specify the values for the Expression Variable Path class properties, as described in this table, and click Insert.
    Property Name

    Specify These Values...

    Expression Name

    Standard Part Cost - Item Standard Part Cost - Item
    Variable Name NoOfChildren NoOfChildren
    Pointer Class Property
    Label
      Child Item
    Owner Class   Assembly Item
    Expression   Standard Part Cost - Item
    Variable   NoOfChildren
    Is Head No Yes

This task explains the procedure to write the sub-expression script:
  1. Find and select the Expression class. Click New Item in the Class Browser. The properties appear in the Edit page.

  2. Specify the values for the Expression class properties, as described in this table, and click Insert.
    Property Name

    Specify These Values...

    Expression Name

    Component Cost - Assembly Cost

    Description

    This expression computes the component level cost of the parts in the assembly.

    Expression

    retValue=ComponentQuantity*StandardPartCost

    Expression Language

    Python. Select the value from the Valid Values dialog box.

    Expression Type Sub. Select the value from the Valid Values dialog box.
    Associated Class > Class
    Label
    Assembly Item
    Evaluation Mode Online. Select the value from the Valid Values dialog box.
    Return Variable Name retValue. Select the value from the Valid Values dialog box.
    Is Active Yes

This task explains the procedure to link the variable (incoming pointer property) with the expression:
  1. Using the Class Browser, find and select the Expression Variable Path class. Click New Item. The properties appear in the Edit page.

  2. Specify the values for the Expression Variable Path class properties, as described in this table, and click Insert.
    Property Name

    Specify These Values...

    Expression Name

    Standard Part Cost - Item Standard Part Cost - Item
    Variable Name AssemblyCost AssemblyCost
    Pointer Class Property
    Label
      Parent Item
    Owner Class   Assembly Item

    Pointer Type

     

    Incoming

    Expression   Standard Part Cost - Item
    Variable   AssemblyCost
    Is Head No Yes

This task explains the procedure to write the multi value parser script:
  1. Using the Class Browser, find and select the Multi Value Parser class. Click New Item. The properties appear in the Edit page.

  2. Specify the values for the Multi Value Parser class properties, as described in this table, and click Insert.
    Property Name

    Specify These Values...

    Expression Name

    Standard Part Cost - Item

    Variable Name

    AssemblyCost

    Parser Script

    retValue = 0.0
    for Cost in argValue:
    retValue = retValue + Cost

    Argument Variable Name argValue. Select the value from the Valid Values dialog box.
    Return Variable Name retValue. Select the value from the Valid Values dialog box.

 

Creating Copy Expressions

You can create a copy expression by following this example.

Requirement:

To set a particular price for the supplier parts, as described in this table.

Source Class

Supplier Items

Target Class

Item Stage

Source Property

Price

Target Property Current Price
Associated Class Supplier Part

Executing a copy expression involves these steps:

  • Write the expression.

  • Specify the source and target class.

  • Link the source and target property.

This task explains the procedure to write the expression:

  1. Using the Class Browser, find and select the Expression class. Click New Item. The properties appear in the Edit page.

  2. Specify the values for the Expression class properties, as described in this table, and click Insert.
    Property Name

    Specify These Values...

    Expression Name

    CMT Set Price

    Description

    Set the price for the supplier items.

    Expression

    retValue = 1

    Expression Language

    Python. Select the value from the Valid Values dialog box.

    Expression Type Copy. Select the value from the Valid Values dialog box.
    Class Label  Supplier Part
    Evaluation Mode Online. Select the value from the Valid Values dialog box.
    Return Variable Name retValue. Select the value from the Valid Values dialog box.
    Is Active Yes. Select the value from the Valid Values dialog box.

This task explains the procedure to specify the source class and target class:
  1. Using the Class Browser, find and select the Copy Expression class. Click New Item. The properties appear in the Edit page.

  2. Specify the values for the Copy Expression class properties, as described in this table, and click Insert.
    Property Name

    Specify These Values...

    Source Class > Class Label

    Supplier Items

    Target Class > Class Label

    Item Stage

    Expression Name

    CMT Set Price

    Operation

    Insert/Update. Select the value from the Valid Values dialog box.

    Expression Return Value 1

This task explains the procedure to link the source property with the target property:
  1. Using the Class Browser, find and select the Property Mapping class. Click New Item. The properties appear in the Edit page.

  2. Specify the values for the Property Mapping class properties, as described in this table, and click Insert.
    Property Name

    Specify These Values...

    Copy Expression

     

    Source Class

    Supplier Items

    Target Class

    Item Stage

    Operation

    Insert/Update. Select the value from the Valid Values dialog box.

    Source Property  
    Class Property Label Price
    Owner Class Supplier Items
    Target Property  
    Class Property Label Current Price
    Owner Class Item Stage
    Use For Search Yes