Archicad Python API
About automating tasks in Archicad using the Python API.

[PYTHON] Sum area script

Mathias Jonathan
Advocate

Hi everybody!

 

I developped a python script that sum the zone area  with the help of Poco.

 

The script sum all zone of the same zone number and put the result in a custom property. You just have to retrieve the value with a label (example file in the zip).

 

The custom property has to be to string type.

The scrip uses the measured area.

 

SCHEMA.png

 

Capture d’écran 2023-02-27 à 13.52.21.png 

4 REPLIES 4
Mathias Jonathan
Advocate

Hi everybody.

 

Here is an update of the script:

 

-Add the possibility to choose more than one layer

-Add the possibility to choose zone category codes instead of layers

-Add parameters for the use of calculated area or measured area, shown or real values.

 

 

Capture d’écran 2023-03-20 à 16.00.20.png

So many good things about your script, beyond your giving it to the Archicad community.  I'm very impressed with your clear, readable code with meaningful variable names and ample use of comments throughout to explain what is happening - in both English and French.  Even for someone who may not need this script for their work, I really think it serves as an excellent advanced Python-in-Archicad tutorial because of the clarity of your code.

 

I will say that, not having used Python in Archicad and having only looked at the 'baby' samples, the length of your script (800 lines) was at first surprising until I read the code.

 

Thank you for sharing this!

 

One of the forum moderators
AC 27 USA and earlier   •   macOS Ventura 13.6.6, MacBook Pro M2 Max 12CPU/30GPU cores, 32GB

Thanks for the nice message Karl.

I started learning and coding in python to modify this script originally written by Poco (whom I would like to thank by the way!).

I didn't know anything about Python at the time, and had only coded small objects in GDL until now.

 

There have been many iterations on this script, and it has been heavily reviewed by Poco who proposed many corrections to make the code cleaner.


The script part allowing to do the calculations is in itself quite short.
What makes it heavy are the comments as you pointed out, but especially the interface with Tkinter.

I was impressed by the possibilities of the python-archicad connection, even if it is still quite limited.

We can easily imagine functions coded by experienced users but used by users not initiated to code (thanks to the GUI), which makes the thing very interesting

 

I think that I will continue my tutorials on the archicad-python so that anybody can code this kind of script.

Dawid
Participant

Great job!