Cancel
Showing results for 
Search instead for 
Did you mean: 

sum attribute values of MU's

Creator
Creator

Hi all

Im currently trying to sum the values of a specific attribute from all MU's located on an object.
It is a user-defined attribute formatted as integer. The MU's to be summed are in the first 10 rows of the contentslist of the object.

I'm trying to use the the sumAttr function but PlantSim doesnt pick it up so im afraid im using the function incorrectly.

Situation is as follows:
object is derived from a list, lets call it "objectlist"
the contentslist of the object shows the MU's
From those MU's id like to have the user defined attribute "length" summed for the first 10 MU's. Id like to test if the value is below a certain global variable named "L"

Currently I tried it like this:

is
do 

      If objectlist[1,2].contentslist.sumAttr({1}..{10}, "length") < L then
      --perform some action
     end;
end;

Plantsim is telling me that sumAttr is an unknown identifier.
I'd like to know if im using the function correctly, or some input on how I can achieve my goal to sum the attributes .

2 REPLIES

Re: sum attribute values of MU's

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

contentslist returns an array, but you can also pass a table and plant simulation writes the contentslist into this table (so you can use sumAttr). So you have to change your programming:

 


is
content:table;
do 
content.create;
objectlist[1,2].contentslist(content);

if content.sumAttr({1,1}..{1,10}, "length") < L then
      --perform some action
 end;
end;

 

 

 

Steffen Bangsow
freelance simulation specialist  
web: www.bangsow.eu
mail: steffen@bangsow.net

Re: sum attribute values of MU's

Creator
Creator

Thanx again Steffen Smiley Happy

Such an easy solution
It worked like charm

regards