ENZYME-APD / tapir-archicad-automation

The easiest way to use the JSON/Python API from Archicad without knowing how to code.
MIT License
57 stars 17 forks source link

Number of Requests sent / undo steps generated per component #203

Open SzamosiMate opened 3 weeks ago

SzamosiMate commented 3 weeks ago

I would like to discuss the number of requests a component sends when receiving tree input. As most of you are probably aware, currently, Tapir components send one request per data tree branch.

This is not only problematic from a performance standpoint, as components that change the state of ArchiCAD generate a separate undo step for each request. As the number of undo steps ArchiCAD keeps is capped at 100, this can easily result in lost data.

Simultaneously flattening inputs into lists, and then rebuilding them from the nodes output to data trees can be done, but is far from trivial, especially if the inputs have different number of elements on the corresponding branches.

I think, that in the long run, Tapir components should only send out one request per component.

One way to achieve this is by setting each input/output to dataTree access and modifying the code in the components. However, this will result in really complicated components. Most of the code can probably be extracted, but the components will be more complex. IronPython had a helper library for this, I used that to create a SetProperties node that only sends one request. A similar library should be available in C#.

Is there any other way? If we can somehow know when the last time our component runs we can build up the request and send it out at the end. But I could not find an event that corresponds to this, and to count the passes we need access to the trees - and that is what I want to avoid.

What do you think?

tlorantfy commented 3 weeks ago

Good initiative!

Today I used AllProperties + GetPropertyValues + SetPropertyValues components to set all properties of 1 element (to the same value as it was, only for testing). It executed ~1000 Tapir commands, created hundreds of undo steps, because SetPropertyValues ran as many times as many properties were available for the element. In an ideal world it should generate only 1 undo step and execute only 3 Tapir commands. I will try to optimize SetPropertyValues component.

We must keep this in focus when we are implementing new components.