Sometimes you might want to change an attribute for all children of a class element by using a Simtalk method. e.g. to set up the z-position in a conveyor model for all line elements. This can be done very easy by using the following lines:
is i,n:integer; do n:=.MaterialFlow.Line.numChildren; --counts how many children the line object has for i := 1 to n loop .MaterialFlow.Line.childNo(i).zpos:=14; --sets the z coordinate for child number i next; end;
Deleting all children of a class:
Be careful with this one!
You might want to save your model before trying it:
if you want to delete all children of a class object with a method you have to count backwards (as the deleted objects will immideately be missing in the counting). This lines will do the job:
is i,n:integer; do n:=.MaterialFlow.Line.numChildren; for i := n downto 1 loop --count backwards .MaterialFlow.Line.childNo(i).deleteobject; --delete object next; end;