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.

Insert wall property on door beloning to wall

Gortz
Booster

Hi, 

 

Is it possible to retrieve a property from a wall and insert the value of the property on, for example, doors and windows located in that specific wall with a Python Script or is it a limitation of the Python API or even Archicad?

 

In this case, we want to get the sound reduction property from a wall and push it onto the door belonging to that wall. 

 

Thanks in advance! 

1 REPLY 1
Gortz
Booster

This is what I have managed so far.
I have managed to extract the GUID from the element and propery with the value. I would just need to move the value from one GUID to another. The challenge is to know which door is in which wall. Maybe impossible... 🤔

import archicad
from archicad import ACConnection
from typing import List

# Etablera en anslutning till Archicad
conn = ACConnection.connect()
if not conn:
    print("Unable to connect to Archicad")
else:
    print("Connection established")

# Få kommandoreferenser
acc = conn.commands
act = conn.types

# Steg 1: Hämta alla property-ID:n och filtrera ut den du vill ha
property_name = "6.3 Ljudreduktion"
property_set = "SS 81 73 40:2021"

# Normalisera strängar för att undvika jämförelseproblem
def normalize_string(s):
    return s.strip().lower()

normalized_property_name = normalize_string(property_name)
normalized_property_set = normalize_string(property_set)

# Hämta alla properties
all_property_ids = acc.GetAllPropertyIds()

# Filtrera efter property set och property name
target_property_id = None
for prop in all_property_ids:
    prop_details = acc.GetDetailsOfProperties([prop])
    prop_definition = prop_details[0].propertyDefinition  # Hämta property definition

    # Jämför nu med 'group.name' för property set
    if normalize_string(prop_definition.group.name) == normalized_property_set and normalize_string(prop_definition.name) == normalized_property_name:
        target_property_id = prop
        break

if not target_property_id:
    print(f"Property '{property_name}' under set '{property_set}' not found.")
else:
    # Steg 2: Hämta alla element och deras properties
    elements = acc.GetAllElements()

    for element in elements:
        # Extrahera GUID för elementet
        element_guid = element.elementId.guid
        print(f"Element GUID: {element_guid}")
        
        # Extrahera elementets property-värde för den specifika property
        try:
            property_values = acc.GetPropertyValuesOfElements([element.elementId], [target_property_id])
            if property_values and property_values[0].propertyValues:
                for prop in property_values[0].propertyValues:
                    property_value = prop.propertyValue
                    print(f"  Property Name: {property_name}")
                    
                    # Skriv ut värdet om det inte är tomt
                    if isinstance(property_value, act.NormalStringPropertyValue):
                        if property_value.value:
                            print(f"  Value: {property_value.value}")
                        else:
                            print(f"  Value is empty for element {element_guid}")
                    else:
                        print(f"Unhandled property value type for element {element_guid}")
            else:
                print("No properties found for this element")
        except Exception as e:
            print(f"Error fetching properties: {e}")

Didn't find the answer?

Check other topics in this Forum

Back to Forum

Read the latest accepted solutions!

Accepted Solutions

Start a new conversation!