cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead 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

jc4d
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.

jc4d_0-1678271689274.pngjc4d_1-1678271697446.png

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:

jc4d_2-1678271906618.png

 

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

jc4d_3-1678271970452.png

 

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
ADDx gap + width
NEXT H

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

DEL TOP
END

20:
ADDx gap*0.5
block widthA, heightB, ZZYZX
RETURN

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

 

Juan




1 ACCEPTED SOLUTION

Accepted Solutions
Solution
Lingwisyer
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 7000Help Those Help You - Add a Signature
Self-taught, bend it till it breaksCreating a Thread
Win11 | i9 10850K | 64GB | RX6600 Win10 | R5 2600 | 16GB | GTX1660

View solution in original post

4 REPLIES 4
runxel
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
Lingwisyer
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 7000Help Those Help You - Add a Signature
Self-taught, bend it till it breaksCreating a Thread
Win11 | i9 10850K | 64GB | RX6600 Win10 | R5 2600 | 16GB | GTX1660
jc4d
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

vdentello
Advocate

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

 

 

 

Archicad User Since 2013
GDL Developer
Experimenting with API
from Brazil