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

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 

13 REPLIES 13
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 28 USA and earlier   •   macOS Sonoma 14.7.1, 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!

magdak
Contributor

Hi, I don't know programming but I would like to learn how I could combine this script with another python script or use them both,

- 1st one is to sum up areas by zone number like shown in this post

- 2nd to measure % of areas with exact zone number according to a zone sum that will be taken as 100%

 

Here is better explanation what I mean:

magdak_1-1717673778530.png

And get something in table like this:

magdak_2-1717675109579.png

I am doing it in archicad but here I cannot set zone number property to get 100% into table, so I thought one can achieve it with Python.

 

magdak_3-1717675331201.png

 

Better explanation of the problem I run into - various 100% plots in a project:

magdak_2-1717679799918.png

 

I would need to define each plot area in Python as 100% for its zone number and then execute calculation of %, I thought it would be easy operation but I am having problem applying this in python script.

 

Would be grateful for any help! Thank you

Mathias Jonathan
Advocate

@magdak It seems possible, and the sum area script seems to be a good start. You'll have to study the code that is heavily commented

 

@Everybody: I updated the script in order to give feedback to the user: why the script didn't work, how to help correct it. All the feedback will appear ine the python console , like this :

Capture d’écran 2024-06-07 à 14.01.04.png

 

 

 

If you used or like this script, please vote for any Python wish on the forum!

We need more development on it!

pr3
Enthusiast

Hello Mathias!

 

Very big thank you for providing this script for free. I was struggling with a solution and with the archicad zone stamp tool for years. This solves nearly everything I could hope for.

 

If I may add one small wish if you still work on updating the script:

Could you add the option to select a custom property for the type of area to be used for calculation?

We sometimes need to use a reducing factor for certain room areas and we can only do this by using a custom property for calculating.

 

Would be very much appreciated! 

Archicad 28 | Mac Studio | OS 14.6

Hi pr3,

 

If the factor you're talking about is a percent value then you can do that directly in the Zone Tool.

Just use the "Reduce by:" field in Zone settings. (Keep in mind that you have to Update Zone for the reduction to take effect!).

Then just select Calculated Area in that marvelous tool that Mathias has created.

 

Below you can find the location of that setting:

 

LucaP_0-1724840169378.png

 

Łukasz Pietraszko
ArchiCAD 26 PL, since AC20 | WIN 10 Home
Intel Core i7-7700HQ 2.8 GHz | 16 GB RAM | NVIDIA GeForce GTX 1060 6 GB | 500 GB SSD
pr3
Enthusiast

I know you could do it this way but for some reason we abandoned this a few years ago and did id with a calculated property.

I just tired it now and it works just fine...

 

Thank you 😉

 

 

Archicad 28 | Mac Studio | OS 14.6