Libraries & objects
About Archicad and BIMcloud libraries, their management and migration, objects and other library parts, etc.

GDL Help Please

Red
Advocate
What I'm trying to do is multiple as many copies as I need of an 2D object (rect2 0,0,2',2' ) by an integer parameter. Could someone show me how I can do this. Also can each copy have a movable (SMART) hotspot in the middle allowing it to only move in the x axis. Would array be used in this process?
Thanks,
Red
i7 8700k
ROG Strix Z390-E MoBo
64gb RAM
EVGA GeForce GTX 2080
_______________________
http://www.facebook.com/flatcreekdesignstn
http://www.sraarchitects.biz
9 REPLIES 9
Red wrote:
What I'm trying to do is multiple as many copies as I need of an 2D object (rect2 0,0,2',2' ) by an integer parameter.
FOR/NEXT loop. I assume the RECT2s need to be spaced out in some way.

FOR k=1 TO RedsIntegerParam
ADD2 (k-1)*x_spacing, (k-1)*y_spacing
RECT2 0,0,2',2'
DEL 1
NEXT k
For an array multiply you need to nest another loop inside.
Red wrote:
Also can each copy have a movable (SMART) hotspot in the middle allowing it to only move in the x axis. Would array be used in this process?
In principle, yes. The array might be helpful/needed, or maybe not. 8-ball says, answer hazy, post screenshot.
James Murray

Archicad 27 • Rill Architects • macOS • OnLand.info
Red
Advocate
James wrote:

FOR k=1 TO RedsIntegerParam
ADD2 (k-1)*x_spacing, (k-1)*y_spacing
RECT2 0,0,2',2'
DEL 1
NEXT k
Is it possible to add something to this code for each of them to move independently?
Thanks,
Red
i7 8700k
ROG Strix Z390-E MoBo
64gb RAM
EVGA GeForce GTX 2080
_______________________
http://www.facebook.com/flatcreekdesignstn
http://www.sraarchitects.biz
Red wrote:
each of them to move independently?
So we have a object made of some number of squares, each with its own offset from some origin, each position graphically editable.

For that you need an array. To edit the offset graphically, it needs to be a parameter, that means a parameter array. Since (I'm pretty sure) you can't have a dynamic parameter array, you'll need to pick number as a limit. It can be big. I don't know how big, it's more than 256.

To make an array parameter click the button to the right of the parameter type (length, etc.) button. This opens the array values dialog. Since you only have one offset, you need just one column and some number of rows. Click the "1" button to the left of the top row, and then click insert however many times. OK. To change this later, don't click the array button again, click 'Set' at the top next to delete.

(The number of rows will be the limit. I would also offer users a parameter for how many copies they actually want; tell them about the limit there.)

Assuming each offset is from 0. Also assuming a hard-coded 2'x2' RECT2:

!Parameter: Qty is user's # of copies
!Array parameter: x_offset is offset distances

FOR k=1 to Qty
	HOTSPOT2 0, 0, hsid, x_offset, 1 : hsid=hsid+1 !b
	HOTSPOT2 x_offset, 0, hsid, x_offset, 2 : hsid=hsid+1 !m
	HOTSPOT2 -1, 0, hsid, x_offset, 3 : hsid=hsid+1 !r

	RECT2 x_offset-1.0', -1.0', x_offset+1.0', 1.0'
	!optional corner spots on rect2
	HOTSPOT2 x_offset-1.0', -1.0'
	HOTSPOT2 x_offset+1.0', -1.0'
	HOTSPOT2 x_offset-1.0', 1.0'
	HOTSPOT2 x_offset+1.0', 1.0'
NEXT k
For each copy, it reads the value in the array in the slot numbered 'k' and builds everything from that.

If you want default values in the array of other than zero, you need to put them in using the set button.

If the squares all start at zero, the user doesn't know which one they're moving, but to me it wouldn't matter.

The array parameter can be hidden. The user only needs to interact with it graphically IMO.

Put in an error handler for the Qty: IF Qty>RedsArraySize THEN Qty= RedsArraySize. Note: RedsArraySize exists in your mind, it's not a variable.
James Murray

Archicad 27 • Rill Architects • macOS • OnLand.info
TomWaltz
Participant
x_spacing and y_spacing would both need to be array variables.

You will also need some way to define all those array values, probably stretchy hotspots.

That would be:
 unID = 1
FOR k=1 TO RedsIntegerParam 
DIM x_spacing[], y_spacing[]    ! Define two dynamic arrays
HOTSPOT2		x_spacing, 0, 		unID, y_spacing, 1+128 : unID = unID +1
HOTSPOT2		x_spacing, -1, 		unID, y_spacing, 3 : unID = unID +1
HOTSPOT2		x_spacing, y_spacing, 	unID, y_spacing, 2 : unID = unID +1

HOTSPOT2		0, y_spacing, 		unID, x_spacing, 1+128 : unID = unID +1
HOTSPOT2		-1, y_spacing, 		unID, x_spacing, 3 : unID = unID +1
HOTSPOT2		x_spacing, y_spacing,	unID, x_spacing, 2 : unID = unID +1
<the rest of your code>
Tom Waltz
Red
Advocate

!!Pipe Column
FOR k=1 to NUMOPC 
	HOTSPOT2 0, 0, hsid, X4PC, 1 : hsid=hsid+1 !b 
	HOTSPOT2 X4PC, 0, hsid, X4PC, 2 : hsid=hsid+1 !m 
	HOTSPOT2 -1, 0, hsid, X4PC, 3 : hsid=hsid+1 !r 
	
	ADD2 (PCT/2)*(-1),0
	RECT2 X4PC,O,PCT+X4PC,S2SF-SFT-HDRS	
	DEL TOP

	!!FOOTER
	SET FILL 6
	POLY2_B{2}       6,     7,      6,     91,  
			-1'-2",-ST, 1, 
			(-1'-2")+2",(ST+4")*(-1), 1, 
			(-1'-2")+2",(ST+4"+10")*(-1), 1, 
			(1'-2")-2",(ST+4"+10")*(-1), 1, 
			(1'-2")-2",(ST+4")*(-1), 1,
			1'-2",-ST,1,
			-1'-2",-ST,1
	
	PEN 91
	LINE2 -1'-2",-ST,1'-2",-ST
	PEN 2
	LINE2 (-1'-2")+2",(ST+4")*(-1),(1'-2")-2",(ST+4")*(-1)	

NEXT k 

First off thanks for the help on getting me this far. I'm starting to see the light at the end of the tunnel. Anyway the pipe column is working great as you can see above. Now I'm trying to add the footer which is the 2nd POLY2_B{2} and the two LINE2. Will I need to reference all of their "X" values as a parameter plus add the for them to follow the pipe column as I move it. Or am I going about it all wrong? See the attached picture.
Thanks,
Red
i7 8700k
ROG Strix Z390-E MoBo
64gb RAM
EVGA GeForce GTX 2080
_______________________
http://www.facebook.com/flatcreekdesignstn
http://www.sraarchitects.biz
Everything that you're repeating should relate to the offset parameter.

It can become cumbersome to put in operations for the offset in every XY coord pair of the shapes. The alternative is to use a transformation of the offset distance instead.

FOR k=1 to Qty 
	HOTSPOT2 0, 0, hsid, x_offset, 1 : hsid=hsid+1 !b 
	HOTSPOT2 x_offset, 0, hsid, x_offset, 2 : hsid=hsid+1 !m 
	HOTSPOT2 -1, 0, hsid, x_offset, 3 : hsid=hsid+1 !r

		ADDx x_offset

	RECT2 -1.0', -1.0', +1.0', 1.0' 
	!optional corner spots on rect2 
	HOTSPOT2 -1.0', -1.0' 
	HOTSPOT2 +1.0', -1.0' 
	HOTSPOT2 -1.0', 1.0' 
	HOTSPOT2 +1.0', 1.0' 

		DEL  1

NEXT k
For each iteration:

Do the hotspots for x_offset.

Move the origin to x_offset. (ADDx)

Draw the stuff.

Go back to 0. (DEL 1)

A couple more tips: Rather than typing 1'-2" over and over, create a variable. You can call it anything, I would call it X1. This is faster for AC to parse and easier for you to read/understand/change later. I would write your polygon like this:

X1=14"
X2=X1-2"
Y1=-ST
Y2=-(ST+4")
Y3=-(Y2+10")
POLY2_B{2}       6,     7,      6,     91,  
         -X1, Y1, 1, 
         -X2, Y2, 1, 
         -X2, Y3, 1, 
         X2, Y3, 1, 
         X2, Y2, 1, 
         X1, Y1, 1, 
         -X1, Y1, 1
There's probably a typo in there but you get the idea. Also, use inches rather than feet & inches; faster parsing again. If you have fractions, convert them to decimals. (1.5" not 1 1/2")

Don't use DEL TOP. The only place you can safely use it is at the very end of a script. Once you start doing more complexly structured scripts (subroutines, macros), DEL TOP will wreck your life. Always delete only the number you need to. You can get help keeping track of the transformation stack by using PRINT NTR(), which tells you the number of trans at that point in the script.
James Murray

Archicad 27 • Rill Architects • macOS • OnLand.info
TomWaltz
Participant
I've gotten in the habit of using a variable: delNum.

Whenever I start a new loop, I set delNum to 0. Then I make compound statements, such as : ADD2 xOffset, yOffset : delNum = delNum + 1

Then at the end of the loop, I DEL delNum

This allows me to bury ADD, MUL and ROT statements inside loops anywhere, and DEL the proper varying number at the end.
Tom Waltz
Anonymous
Not applicable
TomWaltz wrote:
I've gotten in the habit of using a variable: delNum.

Whenever I start a new loop, I set delNum to 0. Then I make compound statements, such as : ADD2 xOffset, yOffset : delNum = delNum + 1

Then at the end of the loop, I DEL delNum

This allows me to bury ADD, MUL and ROT statements inside loops anywhere, and DEL the proper varying number at the end.
Tom,

I seem to recognize the programmer spirit sleeping in you, but this is an interesting tip.
Thank you for sharing!
A similar trick is good for cutting. Every time you use a cutting command, increment a counter.

CUTPLANE : cutz=cutz+1
CUTPOLY yada yada
cutz=cutz+1

etc., then at the end,

FOR k=1 TO cutz
CUTEND
NEXT k

I was thinking that counting the transformations isn't any better than using NTR(), but it is better, because in a macro you can have it delete only the local transformations.
James Murray

Archicad 27 • Rill Architects • macOS • OnLand.info