GDL
About building parametric objects with GDL.
SOLVED!

Setting the Value of One Parameter Based on the Value of Another Parameter

Aaron Bourgoin
Virtuoso

I've created an object for half a dozen types of bicycle racks. I'm scheduling these by kind to get a quantity of racks, but a couple of them are for stacking units that contain two bikes. These are technically one object that should count as two.

 

I created a parameter called Stall Count and created values for these based on the type of stall - also a set of values. I've tried placing this at the top of the Master Script as well as the Parameter script.

 

When I place or edit a stall to be a stacked bike rack, I can't get the stall count number to change automatically based on the stall type.

 

I've looked at GLOB_MODPAR_NAME as a possibility, but don't fully understand how it works.

 

I can set this manually by instance, but I've got 50 people using the part and want to make this transparent to the user.

 

Help!

Think Like a Spec Writer
AC4.55 through 27 / USA AC27-6000 USA
Rhino 8 Mac
MacOS 14.6.1
1 ACCEPTED SOLUTION

Accepted Solutions
Solution

Haha, thanks Aaron!

To the issue at hand: I should have put in even more info. Both parameters (the number of bikes, and the rack type) must be integers!

Then once set the value of the rack type parameter to one manually. The error will go away then. (The reason is that any new number parameter, be it float or integer, will be initialized to zero. A GDL array can't have indizes that are negative or zero (!) – that's why youre getting screamed at)

 

ezgif-1-0493c0dc5c.gif

Lucas Becker | AC 27 on Mac | Graphisoft Insider Panelist | 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 |

POSIWID – The Purpose Of a System Is What It Does /// «Furthermore, I consider that Carth... yearly releases must be destroyed»

View solution in original post

5 REPLIES 5
runxel
Legend

Hey Aaron!

Do not forget to "push back" the values to the parameters with the same named command.

If there are a lot of different types, I'd personally do it like this:

 

!!! Master script
TYPE_ONE = 1
TYPE_TWO = 2
TYPE_OTHER_DESCRIPTION = 3

dim racktype[] ! used as String representation of the internal number for the racktypes
racktype[TYPE_ONE] = "First Type"
racktype[TYPE_TWO] = "Second Type, yeah"
racktype[TYPE_OTHER_DESCRIPTION] = "Also an important Type"

dim nrs[] ! helper for param script
for i=1 to vardim1(racktype)
   nrs[i] = i
next i

dim n_of_bikes[]
n_of_bikes[TYPE_ONE] = 3
n_of_bikes[TYPE_TWO] = 42
n_of_bikes[TYPE_OTHER_DESCRIPTION] = 900

! set the value with the number of stored bikes
! by using the stored integer number of the other parameter
paramNumBikes = n_of_bikes[paramforracktype]

! push back the value to the parameter
parameters paramNumBikes = paramNumBikes


!!! Param script
! Here we set the whole array at once
! we can then use the number internally in the GDL scripts instead of strings
! this has a lot of benefits
values{2} "paramforracktype",
          nrs, racktype

 

Lucas Becker | AC 27 on Mac | Graphisoft Insider Panelist | 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 |

POSIWID – The Purpose Of a System Is What It Does /// «Furthermore, I consider that Carth... yearly releases must be destroyed»

They don't call you 'Ace' for nothing. Thanks for your response.

 

I've placed your snippets in an empty file and it's throwing me errors.

 

I have two parameters in the Parameter List:

 

paramNumBikes (Integer)

 

paramforracktype (String)

 

Neither Parameter shows a value, the line "paramNumBikes = n_of_bikes[paramforracktype]" throws an error and then the Check Script button references an unknown error on compilation or execution. Pressing Save doesn't make the error messages go away.

Think Like a Spec Writer
AC4.55 through 27 / USA AC27-6000 USA
Rhino 8 Mac
MacOS 14.6.1
Solution

Haha, thanks Aaron!

To the issue at hand: I should have put in even more info. Both parameters (the number of bikes, and the rack type) must be integers!

Then once set the value of the rack type parameter to one manually. The error will go away then. (The reason is that any new number parameter, be it float or integer, will be initialized to zero. A GDL array can't have indizes that are negative or zero (!) – that's why youre getting screamed at)

 

ezgif-1-0493c0dc5c.gif

Lucas Becker | AC 27 on Mac | Graphisoft Insider Panelist | 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 |

POSIWID – The Purpose Of a System Is What It Does /// «Furthermore, I consider that Carth... yearly releases must be destroyed»

That did the trick, although I'd have never debugged that in a thousand years. Now I begin to understand why my MVO attempts (and your assists) were fraught with trouble. I'm not used to working with your array ideas, but will keep trying. Thanks Ace!

Think Like a Spec Writer
AC4.55 through 27 / USA AC27-6000 USA
Rhino 8 Mac
MacOS 14.6.1

You're welcome, Aaron! Glad I was able to help.

The whole array thing might be offputting, and with a list as short as two or three items it might not be worth the hassle, and spaghetti code it is!

However the more code you write, the more elegant and more easily maintainable this solution becomes (I always try to imagine what would happen if I ever need to amend an object – I want to make my future work easier). E.g. you do not need a single IF statement here! Batteries included!

 

 

Lucas Becker | AC 27 on Mac | Graphisoft Insider Panelist | 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 |

POSIWID – The Purpose Of a System Is What It Does /// «Furthermore, I consider that Carth... yearly releases must be destroyed»