Developer forum
cancel
Showing results for 
Search instead for 
Did you mean: 

how to make infinite hostpots with array?

A_ Smith
Enthusiast
I want to make hotspots for changing elements position (user have to enter amount of elements).

Is there any possibility to create array with one row and column ( arr[1]=0 ) and then, based upon users choice to expand it to another amount (for instance, 100). I understand i must initialize this array at first (to extend it to 100 and set arr = 0 ). But I don't know where I'm wrong. I assume, my arr=0 reseting all values again to zero. Any help?
AC 22, 24 | Win 10
1 ACCEPTED SOLUTION

Solution
Peter Baksa
Graphisoft
Graphisoft

Hi,

The hotspot command takes care of storing the moved hotspots in the parameter list.
You need to write code that adds new entries to the array when amount changes. You probably won't want to overwrite already existing hotspots to 0.
It is possible that amount decreases, but GDL can't decrease the size of arrays, a temporary array has to be created that will be copied back to the parameter.
This has to be done in the parameter script:

if GLOB_MODPAR_NAME = "amount" then
	! allow decrease, vardim1 tells stored array size
	sizetokeep = min(vardim1(spots), amount)

	! copy existing hotspots
	dim newspots[]
	for i = 1 to sizetokeep
		newspots[i] = spots[i]
	next i

	! initialize new hotspots, will be skipped when decreasing size
	for i = sizetokeep + 1 to amount
		newspots[i] = 0
	next i

	! store array with new size
	spots = newspots
	parameters spots = spots
endif
Péter Baksa
Software Engineer, Library as a Platform
Graphisoft SE, Budapest

View solution in original post

7 REPLIES 7

Solution
Peter Baksa
Graphisoft
Graphisoft

Hi,

The hotspot command takes care of storing the moved hotspots in the parameter list.
You need to write code that adds new entries to the array when amount changes. You probably won't want to overwrite already existing hotspots to 0.
It is possible that amount decreases, but GDL can't decrease the size of arrays, a temporary array has to be created that will be copied back to the parameter.
This has to be done in the parameter script:

if GLOB_MODPAR_NAME = "amount" then
	! allow decrease, vardim1 tells stored array size
	sizetokeep = min(vardim1(spots), amount)

	! copy existing hotspots
	dim newspots[]
	for i = 1 to sizetokeep
		newspots[i] = spots[i]
	next i

	! initialize new hotspots, will be skipped when decreasing size
	for i = sizetokeep + 1 to amount
		newspots[i] = 0
	next i

	! store array with new size
	spots = newspots
	parameters spots = spots
endif
Péter Baksa
Software Engineer, Library as a Platform
Graphisoft SE, Budapest

I want to know what is the difference, if any, of this:

spots = newspots
parameters spots = spots

 and this:

parameters spots = newspots

 

~ReignBough~
ARCHICAD 24 INT 4018 FULL (from AC18)
Windows 10 Pro, Intel Core i7-4790 CPU @ 3.60GHz, 32.0GB RAM, 64-bit OS

There is actually a critical difference.

In the second option the parameter "spots" has to update in the parameter list before the other scripts (2D, 3D) will use the new value.

In the first example the other scripts will respond directly to the "local variable" value set in the master script (spots = newspots) before the parameter value even updates. This makes the object respond dynamically especially in the case of adding new nodes (spots) on the fly in 2D and 3D.

In all my objects I use the first method so that effectively the 2D and 3D are reading values directly from the master script rather than the parameter values. In many cases I don't even have a parameter that relates to the master script local variable.

Creator of Cadswift's parametric GDL libraries
Creator of Infinite Openings and Component Catalogues
Push the envelope & watch it bend
website: https://cadswift.com.au/
YouTube: https://www.youtube.com/user/CADSwift/playlists

I'm a little confused. (Just started studying GDL.) Does it mean that when I use spots after parameters spots = newspots, the value will be the "old" value and not the values set by parameters statement?

~ReignBough~
ARCHICAD 24 INT 4018 FULL (from AC18)
Windows 10 Pro, Intel Core i7-4790 CPU @ 3.60GHz, 32.0GB RAM, 64-bit OS

Let me try to explain in my non - GDL way (I am not much of a programmer although I get by).

 

Just saying ... spots = newspots ...

will change the value of the spots variable, but does not actually change the parameter that the user sees.

The new variable value will be used in the scripts - but the users doesn't see it in the interface.

 

That is why you use ... PARAMETERS spots = spots

 

This sets the parameter the user sees.

 

If you just use ... PARAMETERS spots = newspots ...

this will set the parameter the user sees but you have not actually set the value of the variable used in the scripts - yet.

Because of the order the scripts run (they are run multiple times), the new value will not be used in the scripts until the parameter/master script is runs after the new value has been changed.

So although you set the new parameter value, the 2D/3D script might not pick up on it straight away.

 

So you set the variable value with ... spots = newspots.

And then set the Parameter value with PARAMETERS spots = spots

 

Barry.

 

 


One of the forum moderators.
Versions 6.5 to 25
Dell XPS- i7-6700 @ 3.4Ghz, 16GB ram, GeForce GTX 960 (2GB), Windows 10
Dell Precision 3510 - i7 6820HQ @ 2.70GHz, 16GB RAM, AMD FirePro W5130M, Windows 10

The parameters and values commands have a dirty secret: they take effect only after the parameter script ends. So if you just write

parameters spots = newspots

the rest of the parameter script sees the old content of spots, and could update other parameters based on that.

It is not a problem if you never use it again in the parameter script, but its better to keep a habit of writing it correctly.

Another habit could be to only use newspots in the parameter script after that, then the spots parameter needs to be copied at the start of the script when it isn't modified too.

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

A_ Smith
Enthusiast
Thank you for your time and for the sophisticated solution.
AC 22, 24 | Win 10

Still looking?

Browse more topics

Back to forum

See latest solutions

Accepted solutions

Start a new discussion!