GH Python Component with rs.command locking up definition

So I am trying to access FixedLengthCrvEdit from inside a GHPython Component in grasshopper. Much like Lunchbox RhCom component, but I wanted to be able to bake the curve to rhino from GH and select it and edit it with the command without the user having to keep selecting it or keep typing the command.

I have got the attached code to work and it does what it needs to, but sometimes are clicking an option (Reset or Edit) and changing the curve with FixedLengthCrvEdit. GH kind of freezes, it brings up tooltips etc when you move over a component but you can’t click on anything and you have to restart Rhino to bring it back to life.

Also if the Edit option is set as a switch instead of a button the code seems to be waiting for the command in Rhino to complete before it gives a profiler readout. This is different from the lunchbox RhCom component that is not waiting.

import Rhino as rh
import rhinoscriptsyntax as rs
import scriptcontext as sc


if Reset or Edit:
   sc.doc = rh.RhinoDoc.ActiveDoc
   
   if Reset:
       rs.AddLayer(Layer)
       
       orgCrv = rs.ObjectsByName("Control_Crv")
       rs.DeleteObjects(orgCrv)

       attr = rh.DocObjects.ObjectAttributes()
       
       #select layer to bake and add to the attributes
       layertable = sc.doc.Layers
       layerindex = layertable.Find(Layer,True)
       attr.LayerIndex = layerindex
       rh.DocObjects.ObjectAttributes.Name.SetValue(attr,"Control_Crv")
       
       #bake object
       rh.RhinoDoc.ActiveDoc.Objects.AddCurve(Crv,attr)
       
   elif Edit:
       rs.ObjectsByName("Control_Crv",True)
       rs.Command("FixedLengthCrvEdit")
   
   sc.doc = ghdoc

GH Code
FixedLenghtCrvEdit Issue.gh (31.1 KB)

Hi Steve @stevebaer & Guilio @piac

Any thoughts on what causes in the freezing/lockup of GH? when I run the code sometimes.

Edit: Ok i think i have found the issue, it seems FixedLengthCurveEdit is not telling grasshopper the command has finished after you press return in Rhino everytime so GH locks down somethings while it waits.

Edit 2: Solved this by changing the input switch from a button to a Boolean toggle so now when you finish editing you switch it back to false after pressing return in Rhino at the end of the editing and the GH comes back to life.

Cheers
Matt

I believe this would be helpful when implemented:

Here is the actual cause (in your case as well)

Thanks, @ivelin.peychev good to know.

The workaround I used to get around the boolean toggle double click issue which i found out about after the button issue was to use a value list with the setting as dropdown so I could pick one or the other option as slow or as fast as need no double clicking and it stayed on it switched back again.

solved this problem using a “true only button”. thx.