cancel
Showing results for
Did you mean:
cancel
Showing results for
Did you mean:
2024 Technology Preview Program

2024 Technology Preview Program:
Master powerful new features and shape the latest BIM-enabled innovations

GDL
About building parametric objects with GDL.
SOLVED!

# Alternate objects dimension in loop

Expert

Hello,

I might be drowning in a glass of water here.

I have a working script where two objects of the same width are duplicated by a FOR-TO-NEXT, where the user chooses if it want all the objects at the same height or alternate height.

With my limited knoledge, I have set two loops, one for the "smaller" and another one for the "bigger" one. My problem comes when changing the width of the whole repetition element where the last object in the loop is "out" from the cage and sometimes it doesn't.

In this case if I set the width of the whole element to 1550mm it looks as it should:

But if I set the width of the whole element to 1475mm it goes crazy:

Not sure if instead of two loops I can do the same but with one loop only.

Here is my loop for each element:

``````N1= INT(A /(width+gap))
FOR H=1 TO N1
GOSUB 20
NEXT H

N2= INT(A /(width-gap))
FOR H=1 TO N2 STEP 2
GOSUB 40
NEXT H

DEL TOP
END

20:
block widthA, heightB, ZZYZX
RETURN

40:
ADDx gap + widthA + gap*0.5
block widthA, heightC, ZZYZX
RETURN

``````

Juan

1 ACCEPTED SOLUTION

Accepted Solutions
Solution
Guru

Did not know about the Modulo operation. Was thinking that you could take the integer of half your input, multiply it then compare... the same outcome in 2 characters vs 20.

Given the blocks are just variations on the same shape, it would probably be better to use a generic subroutine and define parameters instead;

``````for i=1 to last
if i%2 then
height = c
else
height = d
endif
gosub "block 1"
next i``````

Ling.

 AC22-23 AUS 7000 Help Those Help You - Add a Signature Self-taught, bend it till it breaks Creating a Thread Win11 | i9 10850K | 64GB | RX6600 Win10 | R5 2600 | 16GB | GTX1660
4 REPLIES 4
Legend

Use the modulo for the current loop number. E.g.:

``````for i=1 to last
if i%2 then
gosub "block 1"
else
gosub "block 2"
endif
next i``````

(where "last" is the total number fo blocks you need)

Lucas Becker | AC 27 on Mac | Author of Runxel's Archicad Wiki | Editor at SelfGDL | Developer of the GDL plugin for Sublime Text | My List of AC shortcomings & bugs | I Will Piledrive You If You Mention AI Again |

«Furthermore, I consider that Carth... yearly releases must be destroyed»
Solution
Guru

Did not know about the Modulo operation. Was thinking that you could take the integer of half your input, multiply it then compare... the same outcome in 2 characters vs 20.

Given the blocks are just variations on the same shape, it would probably be better to use a generic subroutine and define parameters instead;

``````for i=1 to last
if i%2 then
height = c
else
height = d
endif
gosub "block 1"
next i``````

Ling.

 AC22-23 AUS 7000 Help Those Help You - Add a Signature Self-taught, bend it till it breaks Creating a Thread Win11 | i9 10850K | 64GB | RX6600 Win10 | R5 2600 | 16GB | GTX1660
Expert

Thank you both for chime in, I wasn't aware we can use a Modulo operation.

Both solutions are great, but the one from Ling I noticed it would be easier to maintain since there is one subroutine ony so I can ditch the second one. Nevertheless, it is great to see different  approach to the same problem. 👍

Juan

Could also work like that if you need more than 2 Variations.

``````current_sub = 1

for i=1 to last
gosub current_sub
next i

END:

1:
!Dimension variation
current_sub = 2
RETURN

2:
!Dimension variation
current_sub = 3
RETURN

3:
!Dimension variation
current_sub = 1
RETURN

``````