Choose your top Archicad wishes!

Read more
GDL
About building parametric objects with GDL.

User-created array

Mathias Jonathan
Advocate

Hello everyone,
I've been studying arrays, and I'd like to know if an idea I had in mind was possible:

I'd like to give the user the possibility of manually entering numbers in an ui_infield by separating them with a space (or a /) and have these numbers automatically transferred into an array, one entry per number.

For example:

0 1 12 15 16 30
or
0/1/12/15/16/30

I've looked at STRSUB, but you need to know the length of the elements. The problem with numbers is that they can be 1, 2 or 3+ long.

Any ideas on how to extract the data from the text?
(And how to enter them in an array?)

Thanks a lot!

2 REPLIES 2
scottjm
Advisor

STRSTR will return the location of a character in a string. So can be used in conjunction with STRSUB to split strings at certain characters. 

I’m thinking you’d want a while loop to process the input string, split it at the slash and grab the first part and drop it into the first index of an array. 
Then grab the remainder of the string and do the same thing again. And keep doing that until you can’t find any more slashes in your string. 

I’m not at a computer at the moment so this probably has syntax errors galore but maybe something like this:

 

Input_str = “0/1/12/15/16/30”
slash_present = true
dim inputs_array[]
i = 1

WHILE slash_present DO
     slash_pos = STRSTR(input_str, “/“)
     IF slash_pos <> 0 THEN
           inputs_ary[i] = SUBSTR(input_str,1,slash_pos)
           Input_str = SUBSTR(input_str,slash_pos+1,STRLEN(input_str))
          i = i + 1
     ELSE
         slash_present = false
     ENDIF
ENDWHILE
Scott J. Moore | Fulton Trotter Architects | BIM Manager, Associate, Architect
Since AC13 | Current versions AC23.7000 & AC26.5002 | BIMCloud Basic | Python, GDL, VBA, PHP, SQL, CSS
Certified Graphisoft BIM Manger (2022)
Win 10, i9-9900K, 32GB, Quadro P2200, 500GB NVMe
Peter Baksa
Graphisoft
Graphisoft

Hi,

 

SPLIT is the command that converts strings to numbers. You can make an assumption about the maximum number of numbers present in the infield, or pre-split the whole string with scottjm's code.

 

dim numbers[]
n = split("1/2", "%n/%n/%n", numbers)
print n, numbers[1], numbers[3]
Péter Baksa
Software Engineer, Library as a Platform
Graphisoft SE, Budapest

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!