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:
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.
Is there a file associated with what you’re trying that I can use to debug? My guess is the lag is from building the UI tree elements but I’d need to see a file and script to know more. Feel free to pm me the file.
I am using Rhino 7 and IronPython at the moment. You can use any kind of rhino file with a couple of curves and breps inside. Just select some items in that file and execute the script. Depending on how much you select, it will take longer on the named selection save loop.
In addition to this, I just gave it a try in Rhino 8 with CPython and IronPython. The new panel implementation in Rhino 8 shows a different behaviour. If the NamedSelection Panel is open, it takes nearly the same amount of time as in Rhino 7. If for instance the layer panel is open, the script executes in less than a second.
There’s definitely some room for improvement here. I get about 1s completion time with your script on some box faces and curves vs ~10 seconds with the UI panel open. I’ve made a ticket to get this improved. RH-84774
I was able to greatly speed up the performance. Some of it was the UI elements trying to keep up and some of it was the storage process in the file with each addition. Both of those actions will now pause when view redraws are suspended and then refresh when view redraws are re-enabled. This fix should show up in 8.15
@Trav I just installed Rhino 8 Service Release 15 Release Candidate and tested the above python script. Now it takes only approx. 1s. Thank you for the great improvement.