<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Retrieve all classifications item with python in Archicad Python API</title>
    <link>https://community.graphisoft.com/t5/Archicad-Python-API/Retrieve-all-classifications-item-with-python/m-p/612743#M1014</link>
    <description>&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;Note that the two native classifications in Archicad use different Ids and naming convention. i assume you are interested in the Graphisoft default.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;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 &amp;gt;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)&lt;/LI-CODE&gt;</description>
    <pubDate>Thu, 27 Jun 2024 05:36:03 GMT</pubDate>
    <dc:creator>poco2013</dc:creator>
    <dc:date>2024-06-27T05:36:03Z</dc:date>
    <item>
      <title>Retrieve all classifications item with python</title>
      <link>https://community.graphisoft.com/t5/Archicad-Python-API/Retrieve-all-classifications-item-with-python/m-p/612621#M1013</link>
      <description>&lt;P&gt;Hello everyone.&lt;/P&gt;
&lt;P&gt;I'm pretty new to python, but I've managed to make a few scripts.&lt;/P&gt;
&lt;P&gt;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).&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Basically: how can I retrieve a hierarchical list with only the classification names?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My attempt (for the first and second levels):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;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)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jun 2024 11:42:34 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-Python-API/Retrieve-all-classifications-item-with-python/m-p/612621#M1013</guid>
      <dc:creator>Mathias Jonathan</dc:creator>
      <dc:date>2024-06-26T11:42:34Z</dc:date>
    </item>
    <item>
      <title>Re: Retrieve all classifications item with python</title>
      <link>https://community.graphisoft.com/t5/Archicad-Python-API/Retrieve-all-classifications-item-with-python/m-p/612743#M1014</link>
      <description>&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;Note that the two native classifications in Archicad use different Ids and naming convention. i assume you are interested in the Graphisoft default.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;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 &amp;gt;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)&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 27 Jun 2024 05:36:03 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-Python-API/Retrieve-all-classifications-item-with-python/m-p/612743#M1014</guid>
      <dc:creator>poco2013</dc:creator>
      <dc:date>2024-06-27T05:36:03Z</dc:date>
    </item>
    <item>
      <title>Re: Retrieve all classifications item with python</title>
      <link>https://community.graphisoft.com/t5/Archicad-Python-API/Retrieve-all-classifications-item-with-python/m-p/613362#M1015</link>
      <description>&lt;P&gt;It worked well, thanks a lot!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;here is my code (it's not clean, but it seems to work!)&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;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 &amp;gt; 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)
&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 01 Jul 2024 09:09:09 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-Python-API/Retrieve-all-classifications-item-with-python/m-p/613362#M1015</guid>
      <dc:creator>Mathias Jonathan</dc:creator>
      <dc:date>2024-07-01T09:09:09Z</dc:date>
    </item>
  </channel>
</rss>

