2021-02-07
05:56 AM
- last edited on
2021-09-14
12:59 AM
by
Noemi Balogh
2021-02-08 02:04 AM
2021-02-08 08:29 AM
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 ...
{ "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 ...
2021-02-08 04:51 PM
2021-02-09 02:24 AM
leceta wrote: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.
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
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.
leceta wrote:Is this the issue here, or have i just missed something totally out?
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...
2021-02-11 02:34 AM
2021-02-12 05:36 AM
for i in x: guidlist.append(i) response = urllib2.urlopen (request, json.dumps( { "command": "API.GetDetailsOfClassificationItems", "parameters": { "classificationItemIds": [ { "classificationItemId": { "guid": guidlist } } ] } } ).encode("UTF-8"))
[{'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'.)"}}]
2021-02-12 08:52 AM
2021-02-12 08:53 AM
guidList=[] fo guid in x: guidList.append({"classificationItemId":guid}) response = urllib2.urlopen (request, json.dumps( { "command": "API.GetDetailsOfClassificationItems", "parameters": {"classificationItemIds": guidList} }
2021-02-12 11:13 AM
{ "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" } } ] } }
{ "classificationItemId": { "guid": "0EE23E04-F4FC-4DAA-AE52-01A3B0503050" } },
2021-02-13 12:58 AM
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.
2021-02-13 05:30 AM
2021-02-14 10:45 AM
#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)
2021-02-15 02:06 AM
Also don't see a need for the double conversion of JSON commandscool, much better!
2021-02-17 08:01 AM
2021-02-17 09:54 PM
2021-02-18 08:29 AM
poco2013 wrote:I am afraid that your assumption is reflecting pretty well what many users already having in their minds ...
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.
2021-02-22 02:45 AM
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.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.
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?