AI & GDL

AI archicad GDL
 
Oh, wonderful artificial intelligence, show yourself in all your power!
 
After watching an impressive video, in which a Chinese artificial intelligence was shown that with a few prompts created an astonishing app, I decided to test the ones that we all have in our browsers, to write a simple GDL object.
 
So I opened Chrome and asked Gemini this question:
Sono un programmatore e uso il linguaggio GDL di ArchiCAD. Voglio realizzare un oggetto parametrico, puoi aiutarmi a scrivere il codice?

Reply:

Certamente! Sarò lieto di aiutarti a scrivere il codice GDL per un oggetto parametrico in ArchiCAD.

Per iniziare, avrei bisogno di maggiori informazioni sull'oggetto che desideri creare. Potresti fornirmi una descrizione dettagliata dell'oggetto, delle sue dimensioni, delle sue caratteristiche e di eventuali parametri che desideri controllare?

Ad esempio, se volessi creare un semplice parallelepipedo, potremmo iniziare con questo codice di base:

Snippet di codice

DEFINE PARAMETERS

    Lunghezza = 1.0

    Larghezza = 1.0

    Altezza = 1.0

END DEFINE

BODY

    BLOCK Lunghezza, Larghezza, Altezza

END BODY

Questo codice crea un parallelepipedo con dimensioni predefinite (1 metro per 1 metro per 1 metro). I parametri Lunghezza, Larghezza e Altezza possono essere modificati dall'utente per personalizzare le dimensioni dell'oggetto.

Naturalmente, questo è solo un esempio molto semplice. Per oggetti più complessi, il codice GDL può diventare più elaborato. Potremmo aggiungere ulteriori parametri per controllare altri aspetti dell'oggetto, come il materiale, il colore, la rotazione, ecc.

Inoltre, il GDL offre una vasta gamma di funzioni e comandi che consentono di creare oggetti parametrici altamente personalizzati. Ad esempio, possiamo utilizzare cicli FOR per creare array di oggetti, funzioni matematiche per definire relazioni tra parametri, e comandi grafici per disegnare forme complesse.

Se mi fornisci una descrizione più dettagliata dell'oggetto che vuoi creare, sarò in grado di fornirti un codice GDL più specifico e completo.

Inoltre, se hai già scritto del codice GDL, ma hai bisogno di aiuto per risolvere un problema o aggiungere una funzionalità, non esitare a condividerlo con me. Sarò felice di esaminarlo e offrirti il mio supporto.

Spero di esserti d'aiuto!

 The conversational form is quite pleasant, and it feels like you're chatting with someone who knows what they're talking about and is ready to help you.

 
It doesn't say, but in fact I didn't explicitly ask, how to actually "use" this code. That's fine, I'll take care of it. I open ArchiCAD and from the File>Libraries and Objects menu I choose the NEW OBJECT command.
 
Let's try to put the code in the MASTER TEXT of a new object and see what happens by pressing the CHECK SCRIPT button.
 
ERROR on line 1

1 Immagine 2025 02 09 095314

I actually never knew about the existence of a command called DEFINE PARAMETERS, although I must point out that I am using an obsolete version of ArchiCAD (22) and I am pretty rusty by now too. Ok, I put an exclamation point in front of the command (which in GDL means “Ignore the text that follows on this line”) and try again. 3 more errors (and as many exclamation points) later, the example script finally works in all its glory.

2 Immagine 2025 02 09 100721

Let's go tell Gemini what we want to do now.

Voglio creare una libreria. In pratica uno scaffale formato da due fianchi verticali e una serie di mensole. Lo scaffale è alto 2,40 metri, largo 1,50 e profondo 45 cm. Voglio che le misure siano parametriche e anche il numero di ripiani, variabile da 3 a 10.

Reply:

Ottimo! Creare una libreria parametrica per uno scaffale è un progetto interessante. Ecco un codice GDL di base per iniziare, con alcune spiegazioni e suggerimenti per personalizzarlo ulteriormente:

Snippet di codice

DEFINE PARAMETERS

    Lunghezza = 1.50 ' Lunghezza scaffale (metri)

    Profondita = 0.45 ' Profondità scaffale (metri)

    Altezza = 2.40 ' Altezza scaffale (metri)

    SpessoreFianchi = 0.03 ' Spessore fianchi (metri)

    SpessoreMensole = 0.02 ' Spessore mensole (metri)

    NumeroRipiani = 5 ' Numero ripiani (da 3 a 10)

END DEFINE

' Calcolo automatico della distanza tra i ripiani

DistanzaRipiani = (Altezza - SpessoreMensole * NumeroRipiani) / (NumeroRipiani + 1)

BODY

    ' Fianco sinistro

    BLOCK SpessoreFianchi, Profondita, Altezza

    ' Fianco destro (traslato in larghezza)

    ADD Lunghezza - SpessoreFianchi, 0, 0

    BLOCK SpessoreFianchi, Profondita, Altezza

    ' Mensole

    FOR i = 1 TO NumeroRipiani

        ' Posiziona la mensola in altezza

        AltezzaMensola = i * (DistanzaRipiani + SpessoreMensole)

        ADD 0, 0, AltezzaMensola

        BLOCK Lunghezza, Profondita, SpessoreMensole

    NEXT i

END BODY

Spiegazione del codice

DEFINE PARAMETERS: Definisce i parametri personalizzabili dall'utente, come dimensioni, spessori e numero di ripiani.

Calcolo DistanzaRipiani: Calcola automaticamente la distanza tra i ripiani in base all'altezza totale, al numero di ripiani e allo spessore delle mensole.

BODY: Contiene la descrizione geometrica dell'oggetto.

Fianchi: Crea due blocchi verticali per i fianchi, uno a sinistra e uno a destra (traslato in larghezza).

Mensole: Utilizza un ciclo FOR per creare le mensole. Per ogni mensola:

Calcola l'altezza della mensola in base alla sua posizione.

Posiziona la mensola all'altezza calcolata.

Crea un blocco per la mensola.

Suggerimenti e personalizzazioni

Materiali: Aggiungi parametri per definire i materiali di fianchi e mensole, utilizzando il comando MATERIAL.

Posizionamento: Puoi controllare il posizionamento dell'oggetto nel modello utilizzando le coordinate x, y, z.

Rotazione: Aggiungi parametri per controllare la rotazione dell'oggetto attorno agli assi x, y, z utilizzando il comando ROTATE.

Ulteriori dettagli: Aggiungi dettagli come zoccoli, cornici o altri elementi decorativi.

Condizioni: Utilizza istruzioni IF per definire comportamenti diversi in base ai parametri (ad esempio, se il numero di ripiani è pari o dispari).

Come utilizzare il codice

Apri l'editor GDL in ArchiCAD.

Copia e incolla il codice nell'editor.

Modifica i parametri secondo le tue esigenze.

Salva l'oggetto GDL.

Inserisci l'oggetto nel tuo progetto ArchiCAD.

Spero che questo codice ti sia utile per iniziare a creare la tua libreria parametrica. Se hai domande o bisogno di aiuto per personalizzare ulteriormente il codice, non esitare a chiedere!

 

I didn't point out the errors so, as I expected, he put DEFINE PARAMETERS, END DEFINE, BODY, END BODY back (to which I immediately put the exclamation point, as done previously).
 
For the rest, the explanation of what he did was good, the presence of further suggestions was excellent, and the "how to use the code" section was also good. The formatting of all the output was also very clear (which I didn't fully respect here)
 
I immediately noticed that he also inserted a series of comments (always very useful) within the script. Unfortunately, as a separator character, he used the apostrophe (which is used in other languages) instead of the exclamation point that GDL uses.
 
I proceed to use the "Find and replace" command to change all the apostrophes with exclamation points.

3 Immagine 2025 02 09 104752

Great. Now the syntax check tells me that there are no errors and the script can be interpreted.

4 Immagine 2025 02 09 105201

Unfortunately, the AI ​​forgot to use the DEL instruction to cancel the movements so the position of each single element is relative to the previous element, rather than referring to a common origin.
 
I try to point this out to him, or rather to directly suggest the correction…
Va abbastanza bene, ma gli elementi non hanno la posizione corretta. Considera la possibilità di usare il comando DEL per riportare l'origine al punto di partenza, dopo aver usato il comando ADD

Reply:

Hai ragione! L'uso del comando ADD sposta l'origine del sistema di coordinate, quindi le mensole non vengono posizionate correttamente. Per risolvere questo problema, possiamo utilizzare il comando DEL per riportare l'origine al punto di partenza dopo aver disegnato ciascun elemento.

Ecco il codice corretto:

Snippet di codice

DEFINE PARAMETERS

    Lunghezza = 1.50 ' Lunghezza scaffale (metri)

    Profondita = 0.45 ' Profondità scaffale (metri)

    Altezza = 2.40 ' Altezza scaffale (metri)

    SpessoreFianchi = 0.03 ' Spessore fianchi (metri)

    SpessoreMensole = 0.02 ' Spessore mensole (metri)

    NumeroRipiani = 5 ' Numero ripiani (da 3 a 10)

END DEFINE

' Calcolo automatico della distanza tra i ripiani

DistanzaRipiani = (Altezza - SpessoreMensole * NumeroRipiani) / (NumeroRipiani + 1)

BODY

    ' Fianco sinistro

    BLOCK SpessoreFianchi, Profondita, Altezza

    ' Fianco destro

    ADD Lunghezza - SpessoreFianchi, 0, 0

    BLOCK SpessoreFianchi, Profondita, Altezza

    DEL Lunghezza - SpessoreFianchi, 0, 0 ' Riporta l'origine al punto di partenza

    ' Mensole

    FOR i = 1 TO NumeroRipiani

        ' Posiziona la mensola in altezza

        AltezzaMensola = i * (DistanzaRipiani + SpessoreMensole)

        ADD 0, 0, AltezzaMensola

        BLOCK Lunghezza, Profondita, SpessoreMensole

        DEL 0, 0, AltezzaMensola ' Riporta l'origine al punto di partenza

    NEXT i

END BODY

Spiegazione delle modifiche

DEL: Dopo aver disegnato il fianco destro e ogni mensola, ho aggiunto il comando DEL per riportare l'origine del sistema di coordinate al punto di partenza. In questo modo, il prossimo elemento verrà disegnato nella posizione corretta.

Con questa correzione, le mensole dovrebbero essere posizionate correttamente all'interno dello scaffale.

Spero che questo codice funzioni correttamente per te. Se hai ancora problemi o domande, non esitare a chiedere!

 

Good, but not very good. That is not the correct syntax for the DEL command, which requires a number (how many move operations to undo) or the keyword TOP, to undo all moves at once. In this case (in addition to the changes I made previously) I will replace the instructions he added with a more correct DEL 1.

5 Immagine 2025 02 09 111105

Here we are! Artificial intelligence and natural intelligence, working together, have managed to make an object that works. By removing the parameters from this script, and putting them in the Parameters list, we actually get a parametric object that works, although, to be honest, the shelves stick into the sides in an inelegant way…6 Immagine 2025 02 09 112229

 

Okay. Now let’s see how it goes, if I make exactly the same request to Copilot, Microsoft’s AI that we find in Edge.

Sono un programmatore e uso il linguaggio GDL di ArchiCAD. Voglio realizzare un oggetto parametrico, puoi aiutarmi a scrivere il codice?

Reply:

Certo, posso aiutarti a scrivere il codice per un oggetto parametrico in GDL per ArchiCAD. Potresti dirmi quale tipo di oggetto vuoi creare e quali parametri desideri che siano personalizzabili? Questo mi aiuterà a capire meglio le tue esigenze e a fornirti un codice più appropriato. 

Much more concise than Gemini, but all in all it's okay, considering I haven't told him what I want yet.

Voglio creare una libreria. In pratica uno scaffale formato da due fianchi verticali e una serie di mensole. Lo scaffale è alto 2,40 metri, largo 1,50 e profondo 45 cm. Voglio che le misure siano parametriche e anche il numero di ripiani, variabile da 3 a 10.

Reply:

Perfetto, posso aiutarti a creare il codice GDL per una libreria parametrica. Ecco un esempio di come potrebbe essere il codice:

GDL

! Definizione delle variabili parametriche

DEFINE LIB_Version "ArchiCAD 24"

MASTER_SCRIPT

DIM _ripiani_count

PARAMETERS A=1.5, B=2.4, C=0.45, _ripiani_count=5

! Main script

MAIN

_shelf_height = B / (_ripiani_count + 1)

! Creazione dei fianchi verticali

BLOCK C, A, B

! Creazione delle mensole

FOR i=1 TO _ripiani_count

ADDz i * _shelf_height

BLOCK C, A, 0.02

DEL 1

NEXT i

END

In questo script:

A, B e C sono i parametri per la larghezza, l'altezza e la profondità della libreria rispettivamente.

_ripiani_count è il parametro per il numero di ripiani, variabile da 3 a 10.

Il ciclo FOR crea i ripiani alla distanza corretta l'uno dall'altro.

Puoi copiare questo codice in ArchiCAD e modificarlo secondo le tue esigenze specifiche. Fammi sapere se hai bisogno di ulteriori personalizzazioni o se ci sono altri aspetti che desideri esplorare!
Even in this case, the answer has a formatting that helps distinguish the references to the code, even if the explanations are bare bones.
 
I create a new object in ArchiCAD and copy the script into the Master Text.
 
This time, the comments are correctly preceded by an exclamation point, but the first error is already there on line 2.

7 Immagine 2025 02 09 114050

Never heard of a DEFINE LIB_version command. Sure, they might have introduced it in more recent versions than mine, but I can't find any reference even searching online. Then there is "MASTER_SCRIPT" which is perhaps an indication of where to insert the code... in any case it is not a valid instruction.
 
Also the MAIN instruction does not exist in the GDL, and the DIM instruction has something wrong. It should be used to create a matrix, that is, a series of correlated values ​​(e.g. the height of each shelf). Analyzing the entire script I notice that it is not used, or at least not as a matrix, so I decide to eliminate it along with the previous "invented" instructions.
 
Using the "Check script" function again it reports an error on line 9, saying that the _shelf_Height variable is not defined. Of course, the PARAMETERS instruction with which it assigns a value to the variables only works if those parameters are present in the object's Parameters list.
 
So, for now let's write them explicitly in this script.

8 Immagine 2025 02 09 120230

Finally the text is free of errors. Or at least syntax errors, since the object preview only shows a solid block. In fact, analyzing the code, where it says “Creation of the vertical sides” I see that there is only one “side” and moreover as big as the entire library… at this point I’m going to tell him!

Nel tuo codice non vengono generati due fianchi, ma solo uno, largo quanto l'intera libreria. puoi correggere questo errore, creando due fianchi distinti, dello spessore di 3 cm?

Reply:

Hai ragione, grazie per averlo segnalato. Ecco il codice aggiornato che crea due fianchi distinti dello spessore di 3 cm:

GDL

! Definizione delle variabili parametriche

DEFINE LIB_Version "ArchiCAD 24"

MASTER_SCRIPT

DIM _ripiani_count

PARAMETERS A=1.5, B=2.4, C=0.45, _ripiani_count=5, _spessore_fianchi=0.03

! Main script

MAIN

_shelf_height = B / (_ripiani_count + 1)

! Creazione dei fianchi verticali

ADDx _spessore_fianchi / 2

BLOCK C, _spessore_fianchi, B

DEL 1

ADDx (A - _spessore_fianchi)

BLOCK C, _spessore_fianchi, B

DEL 1

! Creazione delle mensole

FOR i=1 TO _ripiani_count

ADDz i * _shelf_height

ADDx _spessore_fianchi

BLOCK C, (A - 2 * _spessore_fianchi), 0.02

DEL 2

NEXT i

END

In questo aggiornamento:

_spessore_fianchi è il parametro per lo spessore dei fianchi, impostato a 3 cm (0.03 metri).

Sono stati aggiunti due BLOCK per creare i fianchi a sinistra e a destra della libreria.

Le mensole sono state modificate per adattarsi alla larghezza tra i fianchi.

Prova a inserire questo codice in ArchiCAD e fammi sapere se ci sono altre modifiche o miglioramenti necessari!

 

The “reaction” is very human… it seems to hear him say “wow, how silly I was!”.
 
I also judge the description of the modifications positively, with a modification not explicitly requested, but necessary, to the width of the shelves.
 
Well, I redo the usual modifications and get ready to test the object.

9 Immagine 2025 02 09 163137

Good intentions, but the result is not there. The sides align along the X axis, while the shelves go in the Y direction.

10 Immagine 2025 02 09 163538

The position of the first side is shifted in the X direction by half a thickness (why?). The shelves are correctly shifted by a whole thickness, but in the wrong direction.
 
Moved by compassion (or stressed enough) I decide to replace all the ADDx with the same number of ADDy. However, I choose not to correct the shift of the left side.
 
In the end it works, but what a pain!
 
Note, and perhaps it is a coincidence, but who knows!, that both my assistants decided, on their own, to make the shelves two centimeters thick, and to put 5 of them. I had said "between 3 and 10" and would have expected a more central number, 6 or 7.
 
Finally I tried to superimpose the two objects, to see if there were differences that at first glance escaped, and in fact there is something.

11 Immagine 2025 02 09 170450

Aside from the 1.5 cm offset of the first side, the two programs use different calculations to determine the position of the shelves. Neither has a correct method for obtaining equal spaces, not only between the individual shelves, but also between the first shelf and the floor, but Copilot (green) tries to do so by taking into account the thickness of the shelves, while Gemini (red) ignores it.
 
The difference becomes evident by exaggerating the thickness of the shelves. In the case of Gemini there is also the appropriate parameter, while with Copilot you have to operate on the number (0.02) written directly in the BLOCK instruction.

12 Immagine 2025 02 09 172443

Conclusions? Of course, it is just an example and it is a bit too little to draw conclusions worthy of consideration, but the impression is that it is still early to use these tools in writing parametric objects for ArchiCAD. I have a fair knowledge of the GDL language, and I was able to identify and correct several errors, which is not easy for a beginner.
 
Let's also consider that the object created in this way, without other additions, is completely devoid of a symbol in the plan. Therefore absolutely invisible and not selectable... no big deal. Let's say that it can be solved by adding a line with the command PROJECT2 3,270,2 at the end of the script, before the END instruction, if present (it is optional).
 
Given the relative simplicity of the task required, and the small number of instructions (excluding the definition of the parameters and the comments, there are only about fifteen commands), the number of errors found is definitely too high. It is true that there are specific artificial intelligences, dedicated to programming ("obviously" in other languages), but I wanted to try specifically to use those that we all have at hand, to verify if an "average user" of ArchiCAD could use them to create, on the fly, an object that he might need. From this perspective, the answer is NO.
 
However, the development of AI is so fast that these evaluations are only valid for the "here and now" in which they were written.

--Roberto Corona-- 

Who's Online

We have 711 guests and one member online

Utenti iscritti al sito

87953