License Delivery maintenance is expected to occur on Saturday, November 30, between 8 AM and 11 AM CET. This may cause a short 3-hours outage in which license-related tasks: license key upload, download, update, SSA validation, access to the license pool and Graphisoft ID authentication may not function properly. We apologize for any inconvenience.
GDL
About building parametric objects with GDL.
SOLVED!

Possible for the user to add to an array?

JGoode
Expert

Hello,

 

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
1 ACCEPTED SOLUTION

Accepted Solutions
Solution

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

Following your style:

 

dim EMPTYARRAY[]
!...
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
    endif
endif

 

 

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

4 REPLIES 4
runxel
Legend

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.

 

runxel_0-1646920043771.png

 

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):

runxel_1-1646920277240.png

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 | 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»
JGoode
Expert

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
	endif
endif

 

ArchiCAD 23

Windows 10
Solution

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

Following your style:

 

dim EMPTYARRAY[]
!...
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
    endif
endif

 

 

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»

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

ArchiCAD 23

Windows 10