Clearing a "stuck" display conduit

I am just tinkering with a script here that uses a custom display conduit to show some on-screen info temporarily until it is escaped, at which time the conduit is disabled again. While messing around with this, of course, occasionally I inadvertently forgot to disable the conduit at the end of the script, or it errored out before it got to the disable line. The result is unsettling, as the display then remains on-screen - even if one starts a new document! The only way I found so far to get rid of the display is to close that instance of Rhino and re-open it.

So, I am simply throwing this out here for info - is there a list/table or some other access somewhere of running conduits where I can find the ‘stuck’ conduit and disable it after the fact? Admittedly I am playing at sorcerer’s apprentice here as I have really no idea what all this stuff does in the background, I am just basically copying and adapting code from various samples I have found.

Here is a script which will create a “stuck” conduit. If you want to try it, please note that you will need to close that instance of Rhino to get rid of it after, so use at your own risk. Normally, if you uncomment the last line, the conduit will be disabled if you hit Enter. As is posted, with the last line commented out, a dot will get “stuck” and not be able to be removed.

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino, System

#colors defined globally
dot_col=System.Drawing.Color.FromArgb(255,230,230,230)
txt_col=System.Drawing.Color.FromArgb(255,0,0,0)

def GetOptionEnterEsc(prompt):
    go = Rhino.Input.Custom.GetOption()
    go.SetCommandPrompt(prompt)
    go.AcceptNothing(True)
    get_rc = go.Get()
    if get_rc==Rhino.Input.GetResult.Nothing: return True
    
class DrawTextDotsConduit(Rhino.Display.DisplayConduit):
    def __init__(self,pts,txts):
        
        self.pts = pts
        self.txts = txts
    
    def DrawOverlay(self, e):
        for i in range(len(self.pts)):
            e.Display.DrawDot(self.pts[i], self.txts[i], dot_col, txt_col)

dot_txts=[]
dot_pts=[]
dot_txts.append("This is a stuck display conduit dot")
dot_pts.append(Rhino.Geometry.Point3d(30,10,0))
conduit=DrawTextDotsConduit(dot_pts,dot_txts)
conduit.Enabled = True
sc.doc.Views.Redraw()
GetOptionEnterEsc("Press Enter to finish")
#conduit.Enabled = False

Rather than look for an obscure (as in “not obviously documented”) cleanup route, maybe better prevent the problem occurring with a Try…[Except…Else…]Finally structure?

dot_pts=[]
dot_txts.append("This is a stuck display conduit dot")
dot_pts.append(Rhino.Geometry.Point3d(30,10,0))
conduit=DrawTextDotsConduit(dot_pts,dot_txts)
try:
  conduit.Enabled = True
  sc.doc.Views.Redraw()
  GetOptionEnterEsc("Press Enter to finish")
finally:
  conduit.Enabled = False

Write the Finally clause before playing about with the golden path and exceptions - that way, the conduit will always be disabled at the end.

HTH
Jeremy

1 Like

Yes, there are ways to prevent this from happening, that was not actually the question. My question was simply if it did happen - for whatever reason - what can then be done about it to clear the problem without having to resort to closing Rhino and re-opening it.

Sadly I can’t answer the real question, so like a good politician I answered a different one. Hopefully it may help some readers.

2 Likes

:stuck_out_tongue_winking_eye::stuck_out_tongue_winking_eye::+1:t2::+1:t2: