We value your input!
Please participate in Archicad 28 Home Screen and Tooltips/Quick Tutorials survey

GDL
About building parametric objects with GDL.
SOLVED!

For To Next array

Alex C
Contributor

Hi, I am getting trying to get into GDL and wanted to try and create a simple object of a rectangle with an adjustable amount of divisions and border. I attempted to reverse engineer the "DET_Layout_Template" object that comes with archicad but I am having trouble getting my For To Next command to actually repeat and move.

 

 

	FOR i = 1 to divx STEP 1
	GOSUB 3050 !Column of boxes
		ADD2 lw,0
	NEXT i
END

!=======================================

3050:
	FOR i = 1 TO divy STEP 1
		POLY2_B 5, 3, flpen, flbkpen,
		0,0,1,
		lw,0,1,
		lw,lh,1,
		0,lh,1,
		0,0,1
		ADD2 0, lh+munt
	NEXT i
RETURN

 

 

This is what I have for my script.

 

 

 

add2 -ModW,0
for i=1 to MN2 step 1
	gosub 3050 ! display column of boxes
	add2 -ModW - psGapX ,0 ! advance to next column position
next i
end

! ========= Subroutine to display column of module-sized boxs
3050:
mnh=mn1+1
repeat
	pen 99
	hotspot2 0, 0
	hotspot2 ModW, 0
	hotspot2 0, ModH
	hotspot2 ModW ,ModH
	pen 95
	rect2 0, 0, ModW, ModH
! Hotlines on rectangle for easier snapping
	hotline2 0, 0, ModW, 0
	hotline2 ModW, 0, ModW, ModH
	hotline2 ModW, ModH, 0, ModH
	hotline2 0, ModH, 0, 0
	pen 92
	line2 0, 0, ModW, ModH
	line2 0, ModH, ModW,0
	add2 0, ModH + psGapY
	mnh = mnh-1
until mnh = 1

del mn1
RETURN

 

 

This is what is in the DET_Layout_Template object, I can't for the life of me figure out how this one gets the subroutine to "advance to the next column position"

MAC OS Monterey AC27
1 ACCEPTED SOLUTION

Accepted Solutions
Solution
Jochen Suehlo
Moderator

You cannot use the same loop counter like "i" in nested loops more than 1 time.
If you start your first loop with the counter "i" and then jump to the subroutine with a second loop, you should use there another counter, e.g. "j", otherwise you will get an error message or an infinty loop.
That's why I always use in a loop within a Subroutine double characters as counter, like ii and jj (or i_1 and j_1), and in one subroutine deeper iii and jjj and so on.

Jochen Suehlo . AC12-27 . MAC OSX 14.4 . WIN11
GDL object creation: b-prisma.de

View solution in original post

3 REPLIES 3
Peter Baksa
Graphisoft
Graphisoft

Hi,

 

you need to DEL the transformations done in Y direction to start at the same Y coordinate in the next X column.

 

 

Péter Baksa
Software Engineer, Library as a Platform
Graphisoft SE, Budapest

Is there also the problem that "i" is being used for both of the loop counters and one is overwriting the other?  If you change the other to "j" or whatever does it then work?

Archicad 26 / Windows 11
Solution
Jochen Suehlo
Moderator

You cannot use the same loop counter like "i" in nested loops more than 1 time.
If you start your first loop with the counter "i" and then jump to the subroutine with a second loop, you should use there another counter, e.g. "j", otherwise you will get an error message or an infinty loop.
That's why I always use in a loop within a Subroutine double characters as counter, like ii and jj (or i_1 and j_1), and in one subroutine deeper iii and jjj and so on.

Jochen Suehlo . AC12-27 . MAC OSX 14.4 . WIN11
GDL object creation: b-prisma.de