We value your input!
Please participate in Archicad 28 Home Screen and Tooltips/Quick Tutorials survey

Libraries & objects
About Archicad and BIMcloud libraries, their management and migration, objects and other library parts, etc.

Alphabetize List

Anybody know a trick for alphabetizing a list in GDL?
James Murray

Archicad 27 • Rill Architects • macOS • OnLand.info
3 REPLIES 3
Frank Beister
Moderator
One of the basic programming issues. Are you looking for an algorithm or a ready to use script? Best should be bubble sort, I guess.
Comparing two strings can be done by < or >

From brain to keyboard:
dim t[], s[]

! ### set source
t[1]="one "
t[2]="two "
t[3]="three "
t[4]="four "

! ### preset destination
FOR i=1 TO VARDIM1(t)
 s=""
 NEXT i

! ### sort
FOR i=1 TO VARDIM1(t)
 p=i
 FOR j=1 TO i-1
  IF s>t THEN
   ! insert element
   FOR k=i TO j+1 STEP -1
    s=s[k-1]
    NEXT k
   p=j : j=VARDIM1(s)
   ENDIF
  NEXT j
 s

=t NEXT i ! ### output PRINT s, "/", VARDIM1(s)

bim author since 1994 | bim manager since 2018 | author of selfGDL.de | openGDL | skewed archicad user hall of fame | author of bim-all-doors.gsm
Viel Dank, Frank. I'll give it a go.
James Murray

Archicad 27 • Rill Architects • macOS • OnLand.info
Anonymous
Not applicable
Danke sehr mein Freund. I have been meaning to figure something like this out for some time. I hadn't expected the code to be so short. I look forward to trying it out.