I need to create >80 NamedSelections and do other NamedSelections operations like list and delete for my parametrized models. Usually, I try to do everything in RhinoCommon, but unfortunately, NamedSelections is not implemented in RhinoCommon, yet. I wrote a small IronPython layer around the RhinoScript interface using rs.Command()
to get it working for now. The entire IronPython script takes now > 60s. If I comment out the rs.Command(-_NamedSelections ...)
commands the code takes only <0.1s, therefore I started to investigate the performance a bit.
At first I tried to create 80 NamedSelections using pure RhinoScript with a constant preselection within the MacroEditor:
-_SetRedrawOff
-_NoEcho
-_NamedSelections _Save Selection_1
-_NamedSelections _Save Selection_2
-_NamedSelections _Save Selection_3
...
-_NamedSelections _Save Selection_80
-_Echo
-_SetRedrawOn
This takes approx. 17 seconds, if I have only 6 edges in my selection. Adding more entities to the selection prior to the macro execution will increase the time substantially. Rhino crashed after a while when I tried to run this Macro with preselected >190 objects and subobjects.
Afterwards I tried the same within IronPython:
import scriptcontext
import rhinoscriptsyntax as rs
import time
def main():
t1 = time.time()
rs.EnableRedraw(False)
for i in range(1,81):
rs.Command('-_NamedSelections _Save Selection_{}'.format(i), echo=False)
rs.EnableRedraw(True)
print "total time: t={}s".format(round(time.time()-t1, 2))
if __name__=='__main__':
main()
The performance was nearly identical to the pure RhinoScript version.
During both implementations the GUI NamedSelections tree updates after each command. I tried and compared rs.AddLayer("Layer_*")
versus rs.Command("-_Layer _New Layer_* _Enter")
. The first one does not update the GUI tree in between commands. I can create 80 layers within <0.05s. Running the command version of layer creation takes approx. 17 seconds and permanently updates the GUI tree as well.
Is it possible to turn off the update loop of the GUI layer, while running RhinoScript commands? In other commercial programs I have the option to do so in order to increase performance.
1 post - 1 participant