Developer forum
cancel
Showing results for 
Search instead for 
Did you mean: 

Python Script to extract Property value and place in parameters

tonyfitz
Booster
I am wondering if it is possible to use Python to take a property value for a zone and place it in the Zone name parameter ?

We are trying to implement a system that reduces the potential for errors in data entry, so to acheive this we have created a property with an option list for all room names in a project along with a corresponding short-code in the format Shortcode:Room Name Then we use expressions to pull out the Room name and Short codes to use in labels, etc.

Now I would like to create room schedules showing the furniture contained within a zone grouped by zone, but the only way I can get that to work is to use the Zone Name parameter, so I want to set up a python script that will enable us to look at the Zone Name property and then copy this to the Zone Name parameter.

Thanks for your assistance in advance.
Tony Fitzpatrick
Head of BIM
www.aw2.fi

Co-Founder / CEO
www.the bimcrowd.com
1 ACCEPTED SOLUTION

Solution

I believe I finally figured out your request. Some tines the obvious things are more difficult. At any rate. i made up a short Python script to change zone names as you requested. I only used the option list property, as the expression property would just be redundant. Attached is a demo video which demonstrates the process. The script is posted on a GitHub repository as listed in the video. BTW, because you have 1000+ rooms, you may want to further identify your room names with more identifiers as in: Story level, Suite style, special restrictions, etc. -- this is also possible in the python script with a option list.

Zone Name Change Video 

i assume you can make the necessary language name translations in the script. Please advise if you have any questions -- hope this helps assuming i got it right?

 

Gerry

Windows 10 - Visual Studio 2019; ArchiCAD 25

View solution in original post

13 REPLIES 13

poco2013
Advisor
Amazingly: Python scripts do not have access to the zone name which is a "built-in" property.
There are several "workarounds" which I can think of:

one would be to create a expression which returns 'Zone name' only and directly then use that in Python which would have access to all user properties.

Another would be to create a auxiliary Add-on to supply this info via the ExecuteAddOnCommand. I believe this is what your trying to avoid.

Last would be to do everything in the C++ AddOn. Messy??

I am not clear as to what your trying to accomplish. An example or screenshots would help. However, i am guessing you could do all in one or two expressions without Python. A expression can reference a expression. Need more explanation.
Gerry

Windows 10 - Visual Studio 2019; ArchiCAD 25

Hi Gerry,

thanks for that, here are some screenshots to explain what I am trying to achieve so hopefully makes it clearer.

tonyfitz_0-1630654397458.png

Firstly instead of entering room name in the Zone room name box (1000's of rooms being entered by different team always results in variations of the same room names in different parts of the building...) I have created a property which is a drop down list of all room names used in a project along with a shortcode (eg WC:Toilet), then I have used an expression to extract the shortcode and room name into new properties.   This works well for most things I want to do like labelling rooms, extracting schedules, etc, but when I want to create a schedule that tells me what elements are in a particular zone I need to use the "related Zone name"  parameter to return the name of the room along with the Zone number.

tonyfitz_1-1630654762588.png

So was wanting to find a way that I could automate the process of transferring the selected room name from the property to the Zone name parameter box.  I have set up a schedule where I can copy / paste from the property to the name parameter, but as this is just repetitive and I can't see anyone really wanting to sit down and repeat this process 1000's of times across a project, was wanting to make it more painless...  

tonyfitz_3-1630655045771.png

The red bits are currently done automatically after selecting the part in the circle, so now I want to automate the green bit.

 

Thanks for any help.

 

Tony

 

Tony Fitzpatrick
Head of BIM
www.aw2.fi

Co-Founder / CEO
www.the bimcrowd.com

Sorry, I don't speak your native language or even know which it is? So, I have no idea what is being transferred to where in your schedules.

But, on the face of it, this seems like a simple automation application and , for 1000+ rooms, would justify a script. If you could provide more info in 'English' I might be able to help. you may want to PM me directly? I believe this could now involve a simple script

 

BTW: I was wrong about Python access to room name?

 

Gerry

Windows 10 - Visual Studio 2019; ArchiCAD 25

Solution

I believe I finally figured out your request. Some tines the obvious things are more difficult. At any rate. i made up a short Python script to change zone names as you requested. I only used the option list property, as the expression property would just be redundant. Attached is a demo video which demonstrates the process. The script is posted on a GitHub repository as listed in the video. BTW, because you have 1000+ rooms, you may want to further identify your room names with more identifiers as in: Story level, Suite style, special restrictions, etc. -- this is also possible in the python script with a option list.

Zone Name Change Video 

i assume you can make the necessary language name translations in the script. Please advise if you have any questions -- hope this helps assuming i got it right?

 

Gerry

Windows 10 - Visual Studio 2019; ArchiCAD 25

View solution in original post

Gerry, you are a bloody magician, that is exactly what I was looking for. Will download the file and plug into our template.

 

I cannot thank you enough.

 

Tony

Tony Fitzpatrick
Head of BIM
www.aw2.fi

Co-Founder / CEO
www.the bimcrowd.com

Hi Gerry,

I have managed to put this into my file and adjust the property names and run the script (woo hoo my first attempt at Python...lol) and it works on some zones but not others.

 

Would the language version of Archicad have any affect ? (we are running Finnish version)  I assume it doesn't as the expressions still use the standard English.

 

The only other thought I had so far is could it be related to the zone type ?

 

cheers


Tony

Tony Fitzpatrick
Head of BIM
www.aw2.fi

Co-Founder / CEO
www.the bimcrowd.com

poco2013
Advisor

There is probably a lot of reasons why it does not work on all zones. But if it works on some, I doubt that language is the problem.  Perhaps some are not configured properly, or some zones are a derivative of a zone (really a object) , perhaps a hotlink? --- i don't know.

 

If you can send me a small sample file (English Please) I'll take a look. It is possible that Archicad is not recognizing some zones as a "Zone" category. If that is the case, i may have a work around. Otherwise, i'll send it on to Graphisoft for future inclusion.

Gerry

Windows 10 - Visual Studio 2019; ArchiCAD 25

tonyfitz
Booster

Hi I have tried again to run the script and copy the error code, which is as follows;

 

Traceback (most recent call last):
File "C:\Users\aw2\Desktop\Temporary Archicad Files\zone renamer.py", line 20, in <module>
buffer = str(value[index].propertyValues[0].propertyValue.value.displayValue)
AttributeError: 'UserUndefinedPropertyValue' object has no attribute 'value'

 

I was wondering if the splitting operation could be causing an issue ?  I do have a property where the split has already been carried out, so could refer directly to this (but am not sure of which lines I would then remove if I tried this.)

 

I will have to save an English file from my home computer as don't have an English version of 24 loaded on my work computer at present.

Will try and get that through in the next day or 2.

 

regards


Tony

Tony Fitzpatrick
Head of BIM
www.aw2.fi

Co-Founder / CEO
www.the bimcrowd.com

poco2013
Advisor

My apologizes for not explaining certain lines. In order to demo this application,I had to make certain assumptions.

The error your getting indicates Python is not finding your name property or the property is not a Option.

In line 15,you must insert the group and property name.

   acc.GetUserDefinfedPropertyId('Phases','Application') -- change to your group name and property name.Group first , than name

 

Line 21:

buffer = buffer.split(':')[0] -- expects a colon (:) as a separator. Insert you own separator.

Gerry

Windows 10 - Visual Studio 2019; ArchiCAD 25

Hi Gerry

I am pretty sure I have changed those to the correct properties.

 

How can I send you a file ?  would a pln, pla or mod file be best ?

 

Tony

 

Tony Fitzpatrick
Head of BIM
www.aw2.fi

Co-Founder / CEO
www.the bimcrowd.com

Would need both the pln & mod files -- Dropbox link via PM would be great

Gerry

Windows 10 - Visual Studio 2019; ArchiCAD 25

tonyfitz
Booster

Hi Gerry,

I have created a folder here for you to take a look at, containing pln and mod files of project plus the python script you sent through, modified to our needs and another I was experimenting with to redirect to the already shortened property rather than do the splitting in the python script.

 

Dropbox folder 

 

Waiting to see what you make of it.

 

best regards

 

Tony

Tony Fitzpatrick
Head of BIM
www.aw2.fi

Co-Founder / CEO
www.the bimcrowd.com

I do see how you revision #2 would work Of course, i could be wrong, but as I understand it:

GetPropertyValues require a type (class) not a string  and Elelement PropertValue value is packed with a type (class) for the value

Also SetPropertyValues should be outside and below the for loop. I believe that was my original mistake

 

Gerry

Windows 10 - Visual Studio 2019; ArchiCAD 25

Still looking?

Browse more topics

Back to forum

See latest solutions

Accepted solutions

Start a new discussion!