The Global Archicad Community

Stay informed. Get help. Share your knowledge.

Discussions about using GRAPHISOFT's tools (Archicad API, BIMx API, BIMcloud API) for independent software developers

Moderators: Karl Ottenstein, LaszloNagy, ejrolon, Barry Kelly, Gordana Radonic, nbalogh, mnguyen, gkmethy, rmasaki, Viktor Kovacs, MOREH Tamas, Akos Somorjai, Ed Brown, Mihály Palenik, Tibor Lorántfy

#322390
my bad, I obviate the conversion from python dict to json objects. Here it goes a working version (checked)

code from "Step 3" (see image below)
Code: Select all
import json
import urllib2

guid = json.dumps(classSysGuid)

if run:
    req = urllib2.Request('http://localhost:19723')
    response = urllib2.urlopen(req,json.dumps({"command": "API.GetAllClassificationsInSystem","parameters":json.loads(guid)}).encode("UTF-8"))
    response = json.loads(response.read())

    classIds = []
    if response['succeeded']:
        for item in response['result']['classificationItems']:
            for key,dict in item['classificationItem'].items():
                if key == 'classificationItemId':
                    classIds.append({'classificationItemId':dict})

    guids = json.dumps(classIds)
    req = urllib2.Request('http://localhost:19723')
    response = urllib2.urlopen(req,json.dumps({
    "command":"API.GetDetailsOfClassificationItems",
    "parameters":{
        "classificationItemIds":json.loads(guids)
        }
        }).encode('UTF-8'))
    response = json.loads(response.read())
    id = []
    name = []
    description = []
    for item in  response['result']['classificationItems']:
        id.append(item['classificationItem']['id'])
        name.append(item['classificationItem']['name'])
        description.append(item['classificationItem']['description'])
Also sharing the GH file. Note that there is a dependency to a 3rd. party plugin (Human), but Its not necessary for the json logic to work, just used as a convenient UI gadget to select between different classification systems received from Archicad document. There is alternative implemented in the shared gh if you don't want to install Human in your system.
Attachments
2021-02-13_01-17-05.png
2021-02-13_01-17-05.png (231.33 KiB) Viewed 307 times
(10.84 KiB) Downloaded 1 time
Last edited by leceta on Sun Feb 14, 2021 12:18 pm, edited 1 time in total.
#322395
Ah yes thx the hint how to convert the dicts to json objects again helps a lot to understand the parsing.
I used it to reformat my guidList (which had no hierachy) to retrieve the ClassificationDetails for all ClassificationItems. So yeah, I will look a bit more into that next week if time allows it. I will come back to you if I encounter the next hurdle ;-)

GuidList.PNG
GuidList.PNG (110.18 KiB) Viewed 297 times
#322409
Hey JSN:

I have been following your posts and am curious as to your intended use of Grasshopper? I see that there was some initial complaint about the slowness of the script. I didn't see any significant difference other than the initial requests time delays. Also, to that point, since the initial request of GetCllasifcationItems returns all the info you are asking -- why then call GetDetails? Also don't see a need for the double conversion of JSON commands?
Finally, Since the script will work just as well within Archicad, any IDE, or Grasshopper, allowing for the change in urllib2 from 2.7 to 3.0+, what is the advantage of Grasshopper? What are you ultimately trying to accomplish that can't be directly done in Archicad or the Archhicad/Grasshopper interface? -- Just asking?

To illustrate my point I have attached a Python Grasshopper script that returns the classifications info with minimal delay.Runs equally well within Archicad -- just change urlib2 to urllib - change from 2.7 to 3.0+
Code: Select all
 #import rhinoscriptsyntax as rs
import json
import  urllib2 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'][1]['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)

 
Image
Attachments
communication Panel.PNG
communication Panel.PNG (42.26 KiB) Viewed 268 times
#322448
Even if I have not been asked, let me share my point of view
I personally find interesting the idea of having packed all this tech in the same environment. I found the current state of things... "disgregated". Param-O should be the natural place for all this to happen, but no tinkering possible currently without C++ (afaik). Limited connection with GDL code, no python interface, no GH interface... Sadly, Graphisoft doesn't seem interested in "agglutination", but hopefully time will demonstrate I'm wrong.

With all its performance/stability issues, I think GH connection is currently the most accessible "all-this-tech agglutination" tool, it offers a more powerful interface to couple with GDL code and all the JSON API is there using IronPython, plus the plethora of goodies that offer GH...
Also don't see a need for the double conversion of JSON commands
cool, much better!
#322534
Hey Gerry,

As leceta already summed it in well wrapped sentences, it's an attempt to unite the fragmented situation we are facing at the moment. There have been discussions in other topics that it is a very welcomed way to open up different interfaces and ways to connect but currently it feels like you need always a different tool for a different workflow task. This makes it very hard to setup a streamlined developement pipeline. Grasshopper is not only very easy to learn and intuitive to use, but it allows you to achieve very fast results. With all it's universal goodies it's simply the weapon of choice.

Anyhow after some time I can say that the JSON API approach with IronPython has kinda served as a proof of concept, it could indeed be used to compensate what the official GH plugin is lacking since the beginning - the possibility to alter existing elements e.g. here more specifically to change classifications based on element property values (but dynamically). Needless to say that it is of course lots of tinkering around. I mean you could write it very use case specific all within one component - as you did very efficiently - or with the more universal building block approach as I did, to have more flexibility. So, well as I said it works and I think there is still some space left for improvements but at the moment I am fine with the speed. Especially because the functionalities are kinda limited at the moment.

So let's hope that the JSON Api will be extended further in the future to be able to automate more and more. Needless to say that it would be of course highly appreciated to see Param-o grow but I think it is a long way to go to reach anywhere near because with the grasshopper experience the bar is set very high ...
#322553
Thanx for the feedback Leceta and JSN:

I mostly agree but getting there is the real problem in my opinion. With the introduction of Python, Param-o ,Grasshopper, MEP, Structural connections, etc., etc. I expect that Graphisoft has taken on more than they can deliver. Small yearly incremental changes in each of these areas will be of no use to anyone. For example, the Present C++ API has approx. 900 functions, The present Python API has 25. At this rate, it would be 50 years before Python would approximate the utility of the C API. and the same is true for the other features.

With respect to Python, Graphisoft's management has already reneged on several promised developments. I do wonder if the small increments and diverse approach is just marketing hype to to tout features that really have little real world utilization because of the limited development effort. In effect, false advertising?

The approach of "lets do a little of everything" will not work and never has. It only promotes features that can not be practically used.This is ultimately going to frustrate users and give Archicad a very bad reputation if some change in philosophy is not demonstrated soon.
#322576
poco2013 wrote: Thu Feb 18, 2021 6:54 am Graphisoft's management has already reneged on several promised developments. I do wonder if the small increments and diverse approach is just marketing hype to to tout features that really have little real world utilization because of the limited development effort. In effect, false advertising?

The approach of "lets do a little of everything" will not work and never has. It only promotes features that can not be practically used.This is ultimately going to frustrate users and give Archicad a very bad reputation if some change in philosophy is not demonstrated soon.
I am afraid that your assumption is reflecting pretty well what many users already having in their minds ...
#322716
I mostly agree but getting there is the real problem in my opinion. With the introduction of Python, Param-o ,Grasshopper, MEP, Structural connections, etc., etc. I expect that Graphisoft has taken on more than they can deliver. Small yearly incremental changes in each of these areas will be of no use to anyone. For example, the Present C++ API has approx. 900 functions, The present Python API has 25. At this rate, it would be 50 years before Python would approximate the utility of the C API. and the same is true for the other features.

With respect to Python, Graphisoft's management has already reneged on several promised developments. I do wonder if the small increments and diverse approach is just marketing hype to to tout features that really have little real-world utilization because of the limited development effort. In effect, false advertising?
Yes, as JSN said this is a shared "fear". Graphisoft seems to follow the same pattern, again and again, letting perish lots of great initiatives, but feel bored complaining about all this. The general user complacency, the minimal near to zero contact with ArchiCAD developers... makes the conversation not only boring (because its futility), but also discouraging because one finishes feeling like an annoying troll.

So, fingers crossed, let's see how good they do it this time.