GDL Cookbook 3.01

Page 229

The GDL Cookbook 3 – Voyager

Clearing the database So what is the use of this if simple ArchiCAD calculations give the same result without the need for GDL scripting? Well, in this case it is possible to create a little library part that will inform us ‘live’ of how many rectangles we have inserted on the floor plan. Inside a new library part, paste the following lines of text, a variant of what was established above of a reading GDL script: !******2D SCRIPT !****** INPUT NUMBER OF ROWS INSIDE TXT FILE ch=OPEN("TEXT",”rectpar.TXT”,"MODE=RO, DIALOG") linecont=1 nr=INPUT(ch,linecont,1,val1) WHILE nr>-1 DO linecont=Linecont+1 nr=INPUT(ch,linecont,1,val1) ENDWHILE CLOSE ch linecont=linecont-1 !****DISPLAY NUMBER OF ROWS INSIDE TEXT FILE string=STR(linecont,1,0)+” SPECIALRECT Objects Detected” TEXT2 0,0,string

Save this object as RectControl.GSM (upon saving ArchiCAD will ask you to locate the rectpar.TXT file, as we have instructed the TEXT add-on using the DIALOG keyword), and insert it on the floor plan, next to the previously inserted rectangles. Does it display the right number of rectangles?

So after deleting objects that use the DATA GDL addon, we need to clear the text file of its contents, then remaining instances of our parts can store their data again and the number of records can become accurate again. This can be done in two ways: Hide or minimize ArchiCAD, trash the rectpar.TXT file, go back into ArchiCAD and choose rebuild & regenerate. The number displayed by rectControl is accurate again. Another way, more orthodox GDL speaking, is to add a parameter to RectControl.GSM, called CLEARFILE, of type checkbox: Then paste inside the Parameter Script of RectControl the following lines, which upon activation of the CLEARFILE checkbox will open the file in Write Only mode, thus initializing it. After that the master script will turn the CLEARFILE checkbox Off again so the objects can safely store their parameters again. !*********MASTER SCRIPT !*********DATABASE CLEANING IF CLEARFILE THEN chCLEAR=OPEN("DATA",”rectpar.TXT”,"MODE=WO") CLOSE chCLEAR PARAMETERS CLEARFILE=0 ENDIF

The clearfile checkbox will then behave like a button. Save the RectControl part, and back on your floor plan delete a couple of more instances of SpecialRect. Then select RectControl, and activate the Erase File Contents checkbox. It will turn itself OFF automatically and immediately. Back on the floor plan, choose Rebuild & Regenerate. The number displayed by RectControl is now accurate.

Conclusion You now have the basic skills to build your own GDL and text interactions. Before developing a new application of these features do a little planning on how you need the parts to behave and interact between themselves. And keep in mind the golden rules:

Now drag a copy of one of the rectangles. Does RectControl display the right number of rectangles now? No, you need to rebuild & regenerate the floor plan for RectControl to update its data reading inside the text file again. When the SpecialRect was copied, the new instance did store its parameters inside the text file. However RectControl had no idea of what was going on and did not feel necessary to reload data from the text file. Remember to rebuild & regenerate your projects often when you use these GDL add-ons. In for another surprise? Select a couple of special rects and delete them from your floor plan. Does the RectControl library part display the right number now, even after rebuild and regenerate? It does not: In the current version of GDL (ArchiCAD 6.5 v3) there is no way to tell an object to delete its record when the object itself is cleared from the floor plan. Now that’s sad. 2.126

1) Use the DATA or TEXT add-on according to what each of them can do 2) When needed you must be able to clear the contents of a text file quickly, from within ArchiCAD. Instead of being a checkbox parameter inside an object the file cleaning feature can activate itself upon a certain circumstance inside ArchiCAD (for example, IF GLOB_SCALE=333 THEN....). Very useful and fast! 3) Over a network use the FULLPATH keyword and to define a complete path to the desired files on a server. This will ensure everybody on the team has access to the files. Avoid the DIALOG keyword in large groups. 4) When importing records, remember to transfer all data inside a parameter array, leaving the processing for after the input task. 5) As data interchange between GDL and TXT files can become slow when files are extensive or a lot of objects try to do it simulateously, it is good to provide the object with a “Store Parameters” checkbox, so actual export can be turned on/off any time.

©Laurent Godel, 2000 ©Copyright Marmalade 1998, 1999, 2000, 2001


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.
GDL Cookbook 3.01 by David Nicholson-Cole - Issuu