About building parametric objects with GDL.

Possible for the user to add to an array?




I am creating a 2D "person" object and I would like the clothes to be randomised using an array. I currently have it working as such:


top_random = rnd(vardim1(top_colour))
pen top_colour[top_random]


 The user is able to edit the current values of the array (to set the pens they want to randomise from) but I was wondering if there is any way that the user is able to add / remove lines of the array to reduce or increase potential pens as it is currently greyed out?


Many thanks

ArchiCAD 23

Windows 10

Yes, that is possible.

But you need an UI, tho. You are right, the user can't change the dimension of the array later on. Teh reason behind this is that the programmer needs to be in control of their data structure – everything else would invoke hazard sooner or later for sure.




If you have an UI you could script the adding and deleting. E.g. the old room stamp had something you could reuse (at least the german one had this feature):


You have to tie a function to the buttons basically.


Or, a completely different way I implemented in some of my objects, is to actually parse a string and populate the array afterwards.

The input could look like this "1,44, 6-17, 25, 3". A bit like printing pages from a PDF.


I also tried something totally ridiculous: Overlaying an ui_infield (to have the accurat color represenation) by an ui_pict_pushcheckbutton.... but that does not really work.

Lucas Becker | AC 27 on Mac | Editor at SelfGDL | Developer of the GDL plugin for Sublime Text |
«Furthermore, I consider that Carth... yearly releases must be destroyed»

Thanks for your help. I added in a way to add rows to the array using a boolean and it seems to work well. I was wondering if you knew of a way to then reduce the rows using a similar method. I had a look in the Zone Stamp as that has a way of adding and removing but I found it rather confusing to follow!

if (glob_modpar_name = "add_top") then
	if (add_top) then
		num_top = vardim1(top_colour) + 1
		top_colour[num_top] = 1
		add_top = 0
		parameters add_top=add_top
		parameters top_colour=top_colour


ArchiCAD 23

Windows 10

Deleting rows is similar, but you'll need another temp structure.

Following your style:


if GLOB_MODPAR_NAME = "del_top" then
    if del_top then
        dim temp[]
        for i=1 to vardim1(top_colour)-1
            temp[i] = top_color[i]
        next i
        ! reset the array first
        top_colour = EMPTYARRAY
        top_colour = temp
        del_top = 0
        parameters \
            del_top = del_top,
            top_colour = top_colour



Lucas Becker | AC 27 on Mac | Editor at SelfGDL | Developer of the GDL plugin for Sublime Text |
«Furthermore, I consider that Carth... yearly releases must be destroyed»

You're a genius! Thank you so much for your help, that is working perfectly now.

ArchiCAD 23

Windows 10

Didn't find the answer?

Check other topics in this Forum

Back to Forum

Read the latest accepted solutions!

Accepted Solutions

Start a new conversation!