Example 6

Example 6 demonstrates how operations are conducted for certain fragments by use of the for condition and of a count-variable.

volumedata = structure:getvolumedata (0);
volumedata.reset ();
fragment=volumedata:addmeshtoraster();

cell01=fragment:randomize(1,1,1,50);
cell02=fragment:randomize(1,1,1,50);
cell03=fragment:randomize(1,1,1,50);
cell04=cell01:randomize(1,1,1,50);
cell05=cell01:randomize(1,1,1,50);
cell06=cell02:randomize(1,1,1,50);
cell07=cell04:randomize(1,1,1,50);

cell09=cell01:randomize(1,1,1,50);
cell10=cell02:randomize(1,1,1,50);
cell11=cell03:randomize(1,1,1,50);
cell12=cell04:randomize(1,1,1,50);
cell13=cell05:randomize(1,1,1,50);
cell14=cell06:randomize(1,1,1,50);
cell15=cell07:randomize(1,1,1,50);
cell16=fragment:randomize(1,1,1,50);

cell_a=structure:getcell(0);
cell_b=structure:getcell(1);

for a=0, volumedata.fragmentcount-1, 2 do
fragment_a = volumedata:getfragment(a);
fragment_a.cell = cell_a
end;

for b=1, volumedata.fragmentcount-1, 2 do
fragment_b = volumedata:getfragment (b);
fragment_b.cell = cell_b;
end;

As in Example 4, the basic fragment of the part is split into 16 random fragments. After that, the first two cells of the structure are loaded into the script, referred to as cell_a and cell_b.

Then, the first conditional block of orders applies to every second fragment (Jump distance: 2) of the volume data, starting with the first (a=0) and running through to the end (fragmentcount-1).

You have to add -1 to the fragment count and to other count variables, because the LUA language always starts counting with zero. Therefore, the number of the last fragment is the overall count of fragments minus one.

For each of these fragments, a new fragment (fragment_a) is loaded into the script. This new fragment is filled with cell_a.

In the second conditional block, the same process is repeated, only for those fragments starting with the second fragment (b=1) of the part. This time, cell_b is assigned to the fragments. That way, every second fragment of the randomized part will have cell_a and all others will have cell_b.