Forum Allplan

[Domanda] Cycle For Next


Hi, I does anyone know how to do a smart part with double For Next loop including one with a variable element (in my case the variable value should be "n_rig")?

For exemple:
3D Script

! n_rig = number rows
! n_col = number columns
! d = distance between columns and rows

FOR r = 1 TO n_rig
FOR c = 1 TO n_col
BOX REF_X , REF_Y , REF_Z
TRANS 0 , REF_Y + d , 0
NEXT
RESTORE n_col

TRANS REF_X + d , 0 , 0
NEXT
RESTORE n_rig

Hello,

It seems to be correct.

If you only move in X direction, you can use TRANSX (TRANSX REF_X + d).
And also in Y direction, use TRANSY (TRANSY REF_Y + d).


Quotato da: Bertrand_C


Thank you Bertrand but the problem is not the move X or Y...the problem is "n_col".
I wrote wrong in the first message...My variable parameter is "n_col" and not "n_rig".
I would like "n_col" to be variable and decide a variable value for each row.
For exemple: n_col =2 for n_rig=1 and n_col = 3 for n_rig=2 and n_col = 5 for n_rig =3 and so on.....

Indeed, this was not clear to me.
There are several solutions.
1- Create, before the loop, an array with the number of columns according to each row and use this array for the loop like this:
FOR c = 1 TO a_col [ n_rig ]
2- Define conditions in the loop of n_rig to redefine the value of n_col before the beginning of the loop n_rig.
3- Maybe other methods...


Quotato da: Bertrand_C
Indeed, this was not clear to me.

There are several solutions.

1- Create, before the loop, an array with the number of columns according to each row and use this array for the loop like this:

FOR c = 1 TO a_col [ n_rig ]

2- Define conditions in the loop of n_rig to redefine the value of n_col before the beginning of the loop n_rig.

3- Maybe other methods...

Thank you but with these few informations I understand.

Quotato da: Bertrand_C
Indeed, this was not clear to me.

There are several solutions.

1- Create, before the loop, an array with the number of columns according to each row and use this array for the loop like this:

FOR c = 1 TO a_col [ n_rig ]

2- Define conditions in the loop of n_rig to redefine the value of n_col before the beginning of the loop n_rig.

3- Maybe other methods...


Can you give a complete example with array? Thank you.

DIM a_col [ n_rig ] 
a_col [ 1 ] = 2
a_col [ 2 ] = 3
a_col [ 3 ] = 4 
a_col [ 4 ] = 2
...
FOR r = 1 TO n_rig
FOR c = 1 TO a_col [ r ] 
...
NEXT
...
NEXT


Quotato da: Bertrand_C

DIM a_col [ n_rig ] a_col [ 1 ]= 2
a_col [ 2 ]= 3
a_col [ 3 ]= 4 a_col [ 4 ]= 2
...
FOR r = 1 TO n_rig
FOR c = 1 TO a_col [ r ]...
NEXT
...
NEXT

Thank you Bertrand for the example!
In this case, however, every time you want to change the number of columns you have to do it manually in the 3D script.
I think there is a system to change from the palette (after setting script master or parameter)