cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 
2024 Technology Preview Program

2024 Technology Preview Program:
Master powerful new features and shape the latest BIM-enabled innovations

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 

6 REPLIES 6
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.7, 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!