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

#322156
Hey,

This topic is actually a bit specific and maybe not totally new but I will give it another try as I am currently always coming back to it again. So afaik Grasshopper is using IronPython which is limited to version 2.7 and the Archicad module cannot be used. Due to the fact that the GH Livebridge is lacking some basic functionalities in terms of usability I have decided to use the Python Wrapper for the JSON Interface to implement some automation features. (e.g. Automatically setting classifications for elements based on Property Information).

However, it would be better to have all the functionalities condensed in one place or in other words it would be very nice if we could use Grasshopper to further customize those snippets as this is way more user friendly to handle for the everyone than to fiddle with the Python scrippts. Sure I could write a GUI for it but it would be much faster and nicer if we could already use the existing setup in the GH template like drop down selection components which contain our property groups and names or the classification names.

The only thing different for the colleagues would be that they are not using standard GH components, but Python Components containing the relevant methods as components ready for use.

Anyhow at the moment I think this is not possible without workarounds that contain big efforts. Sure I could either use the JSON Interface directly but this would take lots of time to set it up and as I think i am not alone who wants such features this is not my task either. So, well probably there are also further developements planned to improve the GH Livebridge itself to make it more GH-like but the past months and years don't make me get to exciting here in my hopes.

Coming back to the actual question, is there any workaround how to achieve what I want and that may slipped trough my attention or is it just not possible at the moment (and in the future) and my best option is to built GUIs for my Python Scripts to make them more human friendly for my colleagues?
#322201
Hi leceta,

You are right, this is indeed a possibility but it would require a complete re-writing of the scripts or as I wrote
Sure I could either use the JSON Interface directly but this would take lots of time to set it up and as I think I am not alone who wants such features this is not my task either.
Probably this is going way faster than I am thinking right now e.g. with a good input dictionary logic and rebuilding the methods with well thought-out loops does the job sooner or later ...
Code: Select all
{
    "command": "API.GetElementsByType",
    "parameters": {
        "elementType": "Wall"
    }
}
... but it is still a bit complex and the whole handling is not very good .... probably it would be even easier to access an existing python script which is customized with the help of GH, then saved locally via the filewriter component just to be executed afterwards to make the changes .... yeah I know, does not sound like the shortest way, but that's how it feels ...

So what I am saying is, I have written my scripts in python and it does the job. Reinventing the whole thing now just that other people can use them as well is a bit a showstopper.

Edit: It also seems to be a bit unstable, my canvas just literally went bloody red after the panel looked like it got beaten up badly .... this has never happend before, but it is a kind of funny discovery too :D
ThisNeverHappendBefore.PNG
ThisNeverHappendBefore.PNG (198.35 KiB) Viewed 451 times
bloody gh.PNG
bloody gh.PNG (69.52 KiB) Viewed 449 times

Anyway, seems to be just too much information for the panel - the output works .. but it seems to be still very slow. Iterating Classifications Details for 10 Elements took more than 10 second ... I have about more than 700 ... why is this taking so long here, it is just a simple loop over all my ClassificationitemGuids ...
slow.PNG
slow.PNG (82.31 KiB) Viewed 441 times
#322216
First check, avoid GH to type cast your inputs (select "No Type Hint") type checking slow things considerably, but definitely 10 seconds seems too muchs (unless you have thousands of parameters embedded in your ArchiCAD elements, who knows...)

Second check. Be sure looping over list is commanded by your python logic (foor loops) instead of leting GH component do the job

If you share your python logic I can check it for more suggestions. DM if you prefer. but sharing is a good thing, anyway.

Edit: Oh, and last but not least, in my experience json call from ghpython are veeery slow. This should be made noticed to Graphisoft developers...
Attachments
2021-02-09_01-48-42.png
2021-02-09_01-48-42.png (68.8 KiB) Viewed 433 times
#322240
leceta wrote: Tue Feb 09, 2021 1:51 am First check, avoid GH to type cast your inputs (select "No Type Hint") type checking slow things considerably, but definitely 10 seconds seems too muchs (unless you have thousands of parameters embedded in your ArchiCAD elements, who knows...)

Second check. Be sure looping over list is commanded by your python logic (foor loops) instead of leting GH component do the job
The Input type is set to >No Type Hint<, actually here it seems like it would not really matter if it is checked for a string either - processing time is pretty much the same.

The logic is simple ...
Code: Select all
result = []

request = urllib2.Request ('http://localhost:19723')

for i in x:   
    response = urllib2.urlopen (request, json.dumps(
    {
        "command": "API.GetDetailsOfClassificationItems",
        "parameters": {
            "classificationItemIds": [
                {
                    "classificationItemId": {
                        "guid": i
                    }}]}}).encode("UTF-8"))
    
    result.append (json.loads (response.read ()))
I am looping for all the guid items in x which is a simple list of the Classification Guids as you could see in the screenshot above. To avoid a crash I have limited it to just the first 11 items.

Sure it is sending a request for each guid, but is there a possibility to send it in one shot, I guess not? Plz tell me if there is a more efficient way to do this.

Well, there are lots of properties in the file, but as I am not checking elements but the classifications itself it should not be a problem. Moreover the same loop just takes a second or so in VS Code and afaik it uses the same interface,so ....
leceta wrote: Tue Feb 09, 2021 1:51 am Edit: Oh, and last but not least, in my experience json call from ghpython are veeery slow. This should be made noticed to Graphisoft developers...
Is this the issue here, or have i just missed something totally out?
Btw, thx for your time!
#322378
Well I tried it with
Code: Select all
for i in x:
    guidlist.append(i)

response = urllib2.urlopen (request, json.dumps(

{
    "command": "API.GetDetailsOfClassificationItems",
    "parameters": {
        "classificationItemIds": [
            {
                "classificationItemId": {
                    "guid": guidlist
                }
                }
        ]
    }
}

).encode("UTF-8"))

but this throws me back an error. Any ideas how to this should work?
[{'succeeded': False, 'error': {'code': 4002, 'message': "Invalid command parameters (The JSON is invalid according to the JSON schema. Validation failed on schema rule 'type' while trying to validate field on path '#/classificationItemIds/0/classificationItemId/guid'.)"}}]
#322384
Have you tried it out? For me that's not working and it seems like you forgot about the "guid" part.
I think there must be another nested loop as the example command looks like the following ....
Code: Select all
{
    "command": "API.GetDetailsOfClassificationItems",
    "parameters": {
        "classificationItemIds": [
            {
                "classificationItemId": {
                    "guid": "0EE23E04-F4FC-4DAA-AE52-01A3B0503050"
                }
            },
            {
                "classificationItemId": {
                    "guid": "8B729AC6-15B1-4F74-8B4F-359D80DA6871"
                }
            },
            {
                "classificationItemId": {
                    "guid": "11111111-2222-3333-4444-555555555555"
                }
            }
        ]
    }
}


Had not time yet to look into it, but I will try to get something closer to this. Anyhow, I think it is just too cumbersome to get everything as desired in GH .... even though it seems to be possible somehow.
Code: Select all
            {
                "classificationItemId": {
                    "guid": "0EE23E04-F4FC-4DAA-AE52-01A3B0503050"
                }
            },