Back

Topic

[KB1113]Childcount use case in Application Architect

Tags: AA, Application Architect, Expression

3 years ago
By FABO
Options
Print
Applies to:

PcVue 12 onwards


Summary: 

In Application Architect expression engine, it is possible to count things like the number of templates that has been instantiated at a certain level of the instances tree. It is also possible to count the number of variables, of symbols, of mimics… This article propose to discover this feature through a simple use case. 


Details:

The sample project is collecting power of solar panels on the roof of a building. We want to know the maximum power that can be expected according to the number of solar panels installed. Not only does the Application Architect automatically position symbols (see KB1122), but it is also able to automatically count the number of instantiated solar panels. Thus it is easy to create an expression which is multiplying the number of solar panel by the maximum power of one solar panel.

In Application Architect, the parameter definition:

Chilcount pChildcount parameter

The expression used: =ChildCount(_ctInst,”*”,1)
The parameter returns the number of template instances under the 1st level. In this case the evaluation mode is “Once” because the parameter is declared in the parent template (ROOF) of SolarPanel templates.

We add and use this parameter in ROOF template:

Chilcount pChildcount in template

We can check that the value is correct in the instances tree:

Chilcount pChildcount in instances

So after synchronisation, the basic expression on variables will calculate the maximum power of all solar panels:

Chilcount expression on template

Thanks to all this, we have the right values in the mimic after the synchronization. Whether we add panels or remove them:

Chilcount result in mimic
    

How to use the ChildCount function in an expression :

The argument eCountType determines which types of child items should be counted and on which criteria, child item’s instance name or child item’s template name.

Possible values are as follow:

Value What kind of child items will be countedd Expected value for argument str
_ctInst

child instances (excluding the embedded instances)

 instance names

_ctInst_ByType

 child instances (excluding the embedded instances)

 instance type (name of the template)

_ctEmbedded

 embedded instances (excluding the child instances)

 instance names

_ctEmbedded_ByType

 embedded instances (excluding the child instances)

 instance type (name of the template)

_ctInstAndEmbedded

 child and embedded instances

 instance names

_ctInstAndEmbedded_ByType

 child and embedded instances

 instance type (name of the template)

_ctVar

 child items of type variable

 variable names

_ctVarBit

 child items of type bit variables

 variable names

_ctVarReg

 child items of type register variables

 variable names

_ctVarText

 child items of type text variables

 variable names

_ctMimic

 child items of type mimic

 mimic names

_ctSymbol

 child items of type symbol

 symbol names

The str argument is used to take into account child elements that match a pattern based on a regular expression:

  • * Matches one or more characters
  • ? Matches any single character
  • # Matches any number
  • [abc] Matches one character among {a; b; c}
  • [!abc] Matches one character other than {a; b; c}
  • [a-z] Matches one character between a and z
  • [!a-z] Matches a character not between a and z

The argument num is the depth level for matching child items:

  • If omitted (or -1): Count among child items with no depth-level limit.
  • 0: Count items in the current instance and its embedded instances only (excluding any child item).
  • Any other positive value n: Count among child items down to the nth level.

For instance:

=Childcount(_ctInst_ByType,”Solar*”,-1)
Count the number of child instances without depth limit if the instances are templates whose name starts with Solar.

Download attachments: 

 

 

 
 
 

Created on: 15 Jun 2021 Last update: 30 May 2024