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

How to set element classifications by the layer with Python add-on

JT1986
Booster

Hi,

 

I'm trying to create a script that would set same classification value to all elements in specified layer regardless of the element type. At this point I have got the script working but not quite as I hoped. Instead of giving classifications only to the elements in specified layers, script gives same classification value for every element in the project. I might have a guess why it does that, but I have not found a fix for it. 

 

Any solutions for how to get the script working right?
 
Here's the code:

 

 

from Archicad import ACConnection
import Archicad
import sys
import re

from Archicad.releases.ac25.b3000types import ElementId, ElementPropertyValue
conn = ACConnection.connect()

assert conn

conn = ACConnection.connect()
acc = conn.commands
act = conn.types
acu = conn.utilities

elementIdBuiltInPropertyUserIds = acc.GetAllElements()
Layer = acu.GetBuiltInPropertyId('ModelView_LayerName')
elemenType=acu.GetBuiltInPropertyId('General_Type')
value =acc.GetPropertyValuesOfElements(elementIdBuiltInPropertyUserIds,[Layer])
value2=acc.GetPropertyValuesOfElements(elementIdBuiltInPropertyUserIds,[elemenType])

class1 = acu.FindClassificationSystem('AC_Classification')
class2 = acu.FindClassificationItemInSystem('AC_Classification','Building Element Proxy')
class_id = act.ClassificationId(class1,class2.classificationItemId)

NumberArray = []
for index,element in enumerate(elementIdBuiltInPropertyUserIds):
    element = element.elementId
    Info1 = value[index].propertyValues[0].propertyValue.value
    Info2 = value2[index].propertyValues[0].propertyValue.value
    print("Layer name: ",Info1,"----Element type in layer:", Info2)


if "Structural - Bearing" in str(value):
    elem_classes = []
    for element2 in elementIdBuiltInPropertyUserIds:
        elem_class = act.ElementClassification(element2.elementId,class_id)
        elem_classes.append(elem_class) 
        acc.SetClassificationsOfElements(elem_classes)
        print(elem_class)

 

 

And after running the script, here's the outcome:

 

 

Layer name:  Structural - Bearing ----Element type in layer: Wall
Layer name:  Structural - Bearing ----Element type in layer: Column
Layer name:  Structural - Bearing ----Element type in layer: Column
Layer name:  Structural - Bearing ----Element type in layer: Column
Layer name:  Model Unit - Zone ----Element type in layer: Zone
Layer name:  Model Unit - Zone ----Element type in layer: Zone
ElementClassification {'elementId': {'guid': 'DE8A1990-E082-4276-BE02-834D0EBF010D'}, 'classificationId': {'classificationSystemId': {'guid': '632C30E5-2B82-4A75-BFAD-D52FEBCE9A4A'}, 'classificationItemId': {'guid': '7272DAE2-F291-4062-A660-574C7E56DC66'}}}
ElementClassification {'elementId': {'guid': 'ED65B0A9-DD68-4086-9E93-09D426134059'}, 'classificationId': {'classificationSystemId': {'guid': '632C30E5-2B82-4A75-BFAD-D52FEBCE9A4A'}, 'classificationItemId': {'guid': '7272DAE2-F291-4062-A660-574C7E56DC66'}}}
ElementClassification {'elementId': {'guid': 'C9A4FC19-4000-4490-B0B7-A29D39AD7EA8'}, 'classificationId': {'classificationSystemId': {'guid': '632C30E5-2B82-4A75-BFAD-D52FEBCE9A4A'}, 'classificationItemId': {'guid': '7272DAE2-F291-4062-A660-574C7E56DC66'}}}
ElementClassification {'elementId': {'guid': 'FA45CD41-0799-4269-91E2-F3BE5839909B'}, 'classificationId': {'classificationSystemId': {'guid': '632C30E5-2B82-4A75-BFAD-D52FEBCE9A4A'}, 'classificationItemId': {'guid': '7272DAE2-F291-4062-A660-574C7E56DC66'}}}
ElementClassification {'elementId': {'guid': '82619F49-B5C5-454F-9DEC-D613F8EEEDE3'}, 'classificationId': {'classificationSystemId': {'guid': '632C30E5-2B82-4A75-BFAD-D52FEBCE9A4A'}, 'classificationItemId': {'guid': '7272DAE2-F291-4062-A660-574C7E56DC66'}}}
ElementClassification {'elementId': {'guid': 'D11CC0E9-21C7-43C9-B3E5-03EFE696DD66'}, 'classificationId': {'classificationSystemId': {'guid': '632C30E5-2B82-4A75-BFAD-D52FEBCE9A4A'}, 'classificationItemId': {'guid': '7272DAE2-F291-4062-A660-574C7E56DC66'}}}

 

As you can see that the script gives classification "building element proxy" for every element instead giving it only for  the elements in the "Structural - Bearing" layer.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Solution
poco2013
Mentor

Try replacing the last "if" with

 

elem_classes = []
    for index,element2 in enumerate(elementIdBuiltInPropertyUserIds):
        if "Structural - Bearing" == value[index].propertyValues[0].propertyValue.value:
            elem_class = act.ElementClassification(element2.elementId,class_id)
            elem_classes.append(elem_class) 
acc.SetClassificationsOfElements(elem_classes)
print(elem_classes)
Gerry

Windows 11 - Visual Studio 2022; ArchiCAD 27

View solution in original post

2 REPLIES 2
Solution
poco2013
Mentor

Try replacing the last "if" with

 

elem_classes = []
    for index,element2 in enumerate(elementIdBuiltInPropertyUserIds):
        if "Structural - Bearing" == value[index].propertyValues[0].propertyValue.value:
            elem_class = act.ElementClassification(element2.elementId,class_id)
            elem_classes.append(elem_class) 
acc.SetClassificationsOfElements(elem_classes)
print(elem_classes)
Gerry

Windows 11 - Visual Studio 2022; ArchiCAD 27

Thank you very much Gerry! Your solution made the script do exactly what it was meant to do!