License delivery maintenance is planned for Saturday, July 26, between 12:00 and 20:00 CEST. During this time, you may experience outages or limited availability across our services, including BIMcloud SaaS, License Delivery, Graphisoft ID (for customer and company management), Graphisoft Store, and BIMx Web Viewer. More details…
2024-06-26 01:42 PM
Hello everyone.
I'm pretty new to python, but I've managed to make a few scripts.
I am working on a script with a graphical interface, and I would like to be able to propose to select a classification in a Tkinter treeview style interface (keep the hierarchical system).
I've managed to retrieve the first and second levels of classifications, but my system is pretty basic in terms of code: I don't know, for example, how to find out the depth of the list retrieved by archicad.
Basically: how can I retrieve a hierarchical list with only the classification names?
My attempt (for the first and second levels):
from archicad import ACConnection
conn = ACConnection.connect()
acc = conn.commands
act = conn.types
acu = conn.utilities
chooseClassification = acc.GetAllClassificationSystems()
classifications = acc.GetAllClassificationsInSystem(
chooseClassification[0].classificationSystemId)
nbEnfants =0
nbEnfants2 =0
for classification in classifications:
print(" "+classification.classificationItem.id + " " +
str(len(classification.classificationItem.children))+" children")
nbEnfants +=len(classification.classificationItem.children)
for subelements in classification.classificationItem.children:
try:
print(" " + subelements.classificationItem.id + " " +
str(len(subelements.classificationItem.children))+" children")
nbEnfants2 +=len(subelements.classificationItem.children)
except TypeError:
print(" " + subelements.classificationItem.id)
print(nbEnfants)
print(nbEnfants2)
Solved! Go to Solution.
2024-06-27 07:36 AM
Not sure I can be of any help --But to retrieve the Classifications tree you need to use recursion. i wrote a classification interface for grasshopper which uses the Json interface and not the built in Python interface. Attached is a Demo Script - You would have to translate to the native Python interface which does not need Json.
Note that the two native classifications in Archicad use different Ids and naming convention. i assume you are interested in the Graphisoft default.
import json
import urllib.request as rb
#request = rb.Request('http://localhost:19723')
request = 'http://localhost:19723'
response = rb.urlopen(request,json.dumps({"command":"API.GetAllClassificationSystems"}).encode('UTF-8'))
results = json.loads(response.read())
result = results['result']['classificationSystems'][0]['classificationSystemId']['guid']
response.close()
response = rb.urlopen(request,json.dumps({"command":"API.GetAllClassificationsInSystem",
"parameters": {"classificationSystemId": {"guid": result }}}).encode('UTF-8'))
results = json.loads(response.read())
response.close()
seed =results['result']['classificationItems']
output = []
level = 0
def get_ids(seed,kids = 0 ):
global level
level += 1
for item in seed:
output.append( ' '*(level-1) + item['classificationItem']['id'])
if kids >0:
kids -= 1
if 'children' in item['classificationItem'].keys():
depth = len(item['classificationItem']['children'])
get_ids(item['classificationItem']['children'], kids = depth)
else:
if kids == 0:
pass # Debug only
level -= 1
get_ids(seed, kids = 0 )
for x in output:
print(x)
2024-06-27 07:36 AM
Not sure I can be of any help --But to retrieve the Classifications tree you need to use recursion. i wrote a classification interface for grasshopper which uses the Json interface and not the built in Python interface. Attached is a Demo Script - You would have to translate to the native Python interface which does not need Json.
Note that the two native classifications in Archicad use different Ids and naming convention. i assume you are interested in the Graphisoft default.
import json
import urllib.request as rb
#request = rb.Request('http://localhost:19723')
request = 'http://localhost:19723'
response = rb.urlopen(request,json.dumps({"command":"API.GetAllClassificationSystems"}).encode('UTF-8'))
results = json.loads(response.read())
result = results['result']['classificationSystems'][0]['classificationSystemId']['guid']
response.close()
response = rb.urlopen(request,json.dumps({"command":"API.GetAllClassificationsInSystem",
"parameters": {"classificationSystemId": {"guid": result }}}).encode('UTF-8'))
results = json.loads(response.read())
response.close()
seed =results['result']['classificationItems']
output = []
level = 0
def get_ids(seed,kids = 0 ):
global level
level += 1
for item in seed:
output.append( ' '*(level-1) + item['classificationItem']['id'])
if kids >0:
kids -= 1
if 'children' in item['classificationItem'].keys():
depth = len(item['classificationItem']['children'])
get_ids(item['classificationItem']['children'], kids = depth)
else:
if kids == 0:
pass # Debug only
level -= 1
get_ids(seed, kids = 0 )
for x in output:
print(x)
2024-07-01 11:09 AM
It worked well, thanks a lot!
here is my code (it's not clean, but it seems to work!)
from archicad import ACConnection
conn = ACConnection.connect()
acc = conn.commands
act = conn.types
acu = conn.utilities
chooseClassification = acc.GetAllClassificationSystems()
classifications = acc.GetAllClassificationsInSystem(
chooseClassification[0].classificationSystemId)
seed = classifications
output = []
level = 0
def get_ids(seed, kids=0):
global level
level += 1
for item in seed:
output.append(' '*(level-1) +
item.classificationItem.id + " (level " + str(level) + ")")
if kids > 0:
kids -= 1
try:
get_ids(item.classificationItem.children,
kids=len(item.classificationItem.children))
except TypeError:
pass # Debug only
level -= 1
get_ids(seed, kids=0)
for x in output:
print(x)