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

GDL For... Next Loop Issues

Anonymous
Not applicable
Hello,

I am relatively new to GDL scripting. I am really enjoying it, however I have ran into a hiccup on my first 3D object.

I'll start by giving you some context. I am currently scripting a kitchen cabinet GDL object. I have created a For... Next loop in order to create parametric shelves for the unit.

The issue is that when I edit the height, either by entering a value or manually in 3D, a number of the shelves disappear. I believe this is because the value being returned is an integer and not a real number and therefore it cannot divide the shelves equally. Is it possible to change the value being returned into a real number?

I have included 2 example images for your reference.

The first image shows the cabinet at 900 high with equal shelving divisions:


The second image shows the cabinet at 895 high with unequal shelving divisions and missing shelves.


I have no idea how to go about solving this one, a simple point in the right direction would be helpful!

Thanks in advance.

Cheers,

Jarrod Phillips
6 REPLIES 6
Jochen Suehlo
Moderator
If you devide 2 Numbers, you always get as result a real number.
And you can turn the real number back again into integer by using INT command.
It would be helpful if you post your script with the issue.
Jochen Suehlo . AC12-27 . MAC OSX 14.4 . WIN11
GDL object creation: b-prisma.de
Anonymous
Not applicable
Joachim wrote:
If you devide 2 Numbers, you always get as result a real number.
And you can turn the real number back again into integer by using INT command.
It would be helpful if you post your script with the issue.
Thanks for the reply Joachim!

I thought that this was the case, so I was confused when shelves were disappearing on unequal divisions.

Please feel free to give any other pointers on best practices for formatting etc. if anything is unclear.

Script is as shown below:
! PARAMETRIC KITCHEN CABINET
! copyright 2019 by Jarrod Phillips

! VARIABLES
width = A
depth = B
height = ZZYZX

! FRONT KICKBOARD
		add 0, doorPanelThickness+0.002+toedepth, 0
		building_material buildingMat1, bForePen1, bBackPen1
		cwall_ mat1, mat2, mat3,
		toeHeight, 0, width, width, 0, toeThickness,
		15, 15, 15, 15,
		0,
		0
		del 1

! REAR KICKBOARD
		add 0, depth-toeThickness, 0
		building_material buildingMat1, bForePen1, bBackPen1
		cwall_ mat1, mat2, mat3,
		toeHeight, 0, width, width, 0, toeThickness,
		15, 15, 15, 15,
		0,
		0
		del 1

! LEFT KICKBOARD
		add toeThickness, doorPanelThickness+0.002+toeThickness+toeDepth, 0
		rotz 90
		building_material buildingMat1, bForePen1, bBackPen1
		cwall_ mat1, mat2, mat3,
		toeHeight, 0, depth-(2*toeThickness+doorPanelThickness+0.002+toeDepth), depth-(2*toeThickness+doorPanelThickness+0.002+toeDepth), 0, toeThickness,
		15, 15, 15, 15,
		0,
		0
		del 2

! RIGHT KICKBOARD
		add width, doorPanelThickness+0.002+toeThickness+toeDepth, 0
		rotz 90
		building_material buildingMat1, bForePen1, bBackPen1
		cwall_ mat1, mat2, mat3,
		toeHeight, 0, depth-(2*toeThickness+doorPanelThickness+0.002+toeDepth), depth-(2*toeThickness+doorPanelThickness+0.002+toeDepth), 0, toeThickness,
		15, 15, 15, 15,
		0,
		0
		del 2

! BOTTOM PANEL
		add 0, doorPanelThickness+0.002, toeHeight
		building_material buildingMat2, bForePen2, bBackPen2
		cprism_ mat4, mat5, mat6,
       	5, bottomPanelThickness,
       	0, 0, 15,
       	width, 0, 15,
       	width, depth-(doorPanelThickness+0.002), 15,
       	0, depth-(doorPanelThickness+0.002), 15,
       	0, 0, 15
		del 1

! DOOR PANEL
	if doorOn then
		add 0.002, 0, toeHeight+0.002
		rotz 360-doorAngle
		building_material buildingMat3, bForePen3, bBackPen3
		cwall_ mat7, mat8, mat9,
       	height-(toeHeight+0.002), 0, width-0.004, width-0.004, 0, doorPanelThickness,       	
		15, 15, 15, 15,
		0,
		0			
		del 2
	endif

! REAR PANEL
		add 0, depth-rearPanelThickness, toeHeight+bottomPanelThickness
		building_material buildingMat2, bForePen2, bBackPen2
		cwall_ mat4, mat5, mat6,
       	height-(toeHeight+bottomPanelThickness), 0, width, width, 0, rearPanelThickness,       	
		15, 15, 15, 15,
		0,
		0
		del 1

! LEFT PANEL
		add 0, doorPanelThickness+0.002, toeHeight+bottomPanelThickness
		rotz 90
		building_material buildingMat2, bForePen2, bBackPen2
		cwall_ mat4, mat5, mat6,
       	height-(toeHeight+bottomPanelThickness), 0, depth-(rearPanelThickness+doorPanelThickness+0.002), depth-(rearPanelThickness+doorPanelThickness+0.002), 0, -leftPanelThickness,       	
		15, 15, 15, 15,
		0,
		0
		del 2

! RIGHT PANEL
		add width-rightPanelThickness, doorPanelThickness+0.002, toeHeight+bottomPanelThickness
		rotz 90
		building_material buildingMat2, bForePen2, bBackPen2
		cwall_ mat4, mat5, mat6,
       	height-(toeHeight+bottomPanelThickness), 0, depth-(rearPanelThickness+doorPanelThickness+0.002), depth-(rearPanelThickness+doorPanelThickness+0.002), 0, -rightPanelThickness,       	
		15, 15, 15, 15,
		0,
		0		
		del 2
	
	If braceHorizontal then

! FRONT HORIZONTAL BRACING MEMBER
		add leftPanelThickness, doorPanelThickness+0.002, height-frontBraceThickness
		building_material buildingMat4, bForePen4, bBackPen4
		cprism_ mat10, mat11, mat12,
		5, frontBraceThickness,
		0, 0, 15,
		width-(leftPanelThickness+rightPanelThickness), 0, 15,
		width-(leftPanelThickness+rightPanelThickness), braceHeight, 15,
		0, braceHeight, 15,
		0, 0, 15
		del 1

! REAR HORIZONTAL BRACING MEMBER
		add leftPanelThickness, depth-(braceHeight+rearPanelThickness), height-rearBraceThickness
		building_material buildingMat4, bForePen4, bBackPen4
		cprism_ mat10, mat11, mat12,
		5, rearBraceThickness,
		0, 0, 15,
		width-(leftPanelThickness+rightPanelThickness), 0, 15,
		width-(leftPanelThickness+rightPanelThickness), braceHeight, 15,
		0, braceHeight, 15,
		0, 0, 15
		del 1
	else

! FRONT VERTICAL BRACING MEMBER
		add leftPanelThickness, doorPanelThickness+0.002, height-braceHeight
		building_material buildingMat4, bForePen4, bBackPen4
		cwall_ mat10, mat11, mat12,
		braceHeight, 0, width-(leftPanelThickness+rightPanelThickness), width-(leftPanelThickness+rightPanelThickness), 0, frontBraceThickness,
		15, 15, 15, 15,
		0,
		0
		del 1

! REAR VERTICIAL BRACING MEMBER
		add leftPanelThickness, depth-(rearPanelThickness+rearBraceThickness), height-braceHeight	
		building_material buildingMat4, bForePen4, bBackPen4
		cwall_ mat10, mat11, mat12,
		braceHeight, 0, width-(leftPanelThickness+rightPanelThickness), width-(leftPanelThickness+rightPanelThickness), 0, rearBraceThickness,
		15, 15, 15, 15,
		0,
		0
		del 1
	endif

! SHELF

	if numShelf > 1 then

			add leftPanelThickness+0.002, doorPanelThickness+0.004, toeHeight
	
		for k= (height-toeHeight)/numShelf to (height-toeHeight)-(height-toeHeight)/numShelf step (height-toeHeight)/numShelf
			addz k
			building_material buildingMat5, bForePen5, bBackPen5
			cprism_ mat13, mat14, mat15,
       		5, adjustShelfThickness,
       		0, 0, 15,
       		width-(leftPanelThickness+0.002+0.002+rightPanelThickness), 0, 15,
       		width-(leftPanelThickness+0.002+0.002+rightPanelThickness), depth-(doorPanelThickness+0.002+0.002+0.002+rearPanelThickness), 15,
       		0, depth-(doorPanelThickness+0.002+0.002+0.002+rearPanelThickness), 15,
       		0, 0, 15
			del 1
		next k
	endif
Barry Kelly
Moderator
Just having a quick look at your code you might want to try this for the shelf.


k= (height-toeHeight)/numShelf to (height-toeHeight)-(height-toeHeight)/numShelf step (height-toeHeight)/numShelf

for count = 1 to numShelf 
addz k
.... shelf stuff
next count
DEL numShelf 

Barry.
One of the forum moderators.
Versions 6.5 to 27
i7-10700 @ 2.9Ghz, 32GB ram, GeForce RTX 2060 (6GB), Windows 10
Lenovo Thinkpad - i7-1270P 2.20 GHz, 32GB RAM, Nvidia T550, Windows 11
Anonymous
Not applicable
Barry wrote:
Just having a quick look at your code you might want to try this for the shelf.


k= (height-toeHeight)/numShelf to (height-toeHeight)-(height-toeHeight)/numShelf step (height-toeHeight)/numShelf

for count = 1 to numShelf 
addz k
.... shelf stuff
next count
DEL numShelf 

Barry.
Hello Barry,

This is great, I will give this a go!

Thanks for the pointers

Jarrod
Anonymous
Not applicable
Barry wrote:
Just having a quick look at your code you might want to try this for the shelf.


k= (height-toeHeight)/numShelf to (height-toeHeight)-(height-toeHeight)/numShelf step (height-toeHeight)/numShelf

for count = 1 to numShelf 
addz k
.... shelf stuff
next count
DEL numShelf 

Barry.
Hello Barry,

I had a play around with your suggested code and with a little tinkering got it to work for me.

My solution was as follows:

! SHELF

	if numShelf > 1 then

			add leftPanelThickness+0.002, doorPanelThickness+0.004, toeHeight

			k= (height-toeHeight)/numShelf
			for count = 1 to numShelf-1 
			addz k
			building_material buildingMat5, bForePen5, bBackPen5
			cprism_ mat13, mat14, mat15,
       		5, adjustShelfThickness,
       		0, 0, 15,
       		width-(leftPanelThickness+0.002+0.002+rightPanelThickness), 0, 15,
       		width-(leftPanelThickness+0.002+0.002+rightPanelThickness), depth-(doorPanelThickness+0.002+0.002+0.002+rearPanelThickness), 15,
       		0, depth-(doorPanelThickness+0.002+0.002+0.002+rearPanelThickness), 15,
       		0, 0, 15
			next count
			DEL numShelf

	endif
Thanks for you help!

Jarrod.
Barry Kelly
Moderator
I am glad that you have this working.
But a couple of things you may want to watch out for.

You are counting from 1 to numShelf-1 and inside the loop you have one ADD command.
However after the loop you are DEL-ing numShelf.
So you are DEL-eting more than you have ADD-ed.
This may cause problems if you have following script.

Also if you are counting the base of the cabinet as shelf number 1, then the loop from 1 to numShelf-1 is fine, as you already have the base shelf and you don't want to add any more - you don't want to execute the loop.
But if you are counting 1 shelf in the middle of the cabinet a 'one' shelf, then you will want to loop from 1 to numShelf.

Barry.
One of the forum moderators.
Versions 6.5 to 27
i7-10700 @ 2.9Ghz, 32GB ram, GeForce RTX 2060 (6GB), Windows 10
Lenovo Thinkpad - i7-1270P 2.20 GHz, 32GB RAM, Nvidia T550, Windows 11