Disable all custom display conduits

I am using the Script Editor to quick-test scripts that use custom Display Conduits. As this is a fast trial-and-error process, sometimes I realize after the fact that I forgot to put error traps and some conduit display “leftovers“ remain until I restart Rhino.

Is there a way to remove them with a “cleanup” script? I’ve searched both the forum and the RhinoCommon API, but I haven’t found anything helpful to do that. Is this even possible? Or is restarting Rhino the only way?

1 Like

Perhaps you should wrap your code in a Try/Finally block, and then in the finally disable the conduit(s).

That way even if there is an exception it can remove the conduit.

1 Like

Thank you, that’s actually a good idea, but I still have to track each individual conduit I created and remember to disable it in the Finally block.

I just hoped to find a failsafe method that could be used after the fact, something like a DisableAllCustomConduits() that does not need to set the Enable field to false individually. Oh, well, I guess I’ll have to make do with what I can have….

1 Like

We use a base class with this logic, so that each concrete class gets this logic for free; so you don’t have to keep track of each commands display conduit, they do it themselves…

1 Like

This is a very neat idea! I am struggling to implement it though… can I bother you for a simple code example?

1 Like

Sure, I’ll put something together this morning and post it. In the meantime, you should download the latest community edition of Visual Studio 2026 Insiders build, and then install the Rhino Project Templates from here:

Visual Studio: https://aka.ms/vs/18/insiders/vs_Community.exe

Templates:

Then you can start developing your plugin with full debugging and not spend time with the Script Editor in Rhino.

I’ll put together a sample plugin solution and post it later this morning.

@ale2x72 here is a sample solution that implements the base command class that has error handling and a conduit that can be cleaned up when the command ends.

We use exclusively net48 plugins, but I noticed in my debugging of Rhino 8 that if you run the plugin as a .NET 7 plugin, instead of net48 that your breakpoints won’t work properly.

So I suggest that when you run the solution you choose the net48 framework:

This solution has two commands that can be executed; SampleCommandNoCleanup and SampleCommandWithCleanup. There is a BaseCommand that does the magic for the SampleCommandWithCleanup that takes care of handling exceptions and disabling the conduit.

image

When you run either command you can complete it (pressing option C), and see that the conduit has a chance to cleanup, but if you instead cause the exception (pressing option E) only the With Cleanup command properly removes the conduit drawn curves.

The BaseCommand is quite simple, it has a _conduit that is used to hold onto the DisplayConduit for any command classes that inherit from BaseCommand. This conduit is then used to cleanup and turn off the display after the command completes.

Each command that implements base, will need to implement the EnglishName property and the Execute method. The RunCommandMethod is already implemented in the BaseCommand class for every command.

So now writing commands is quite simple, and they all get the benefit of the error handling and the conduit cleanup without having to write any of that logic.

In the below command, we create an assign our CurveConduit to the _conduit property of the base class, so it can later clean it up. We then assign attributes to the conduit as needed.

The CurveConduit class is very simplistic for example purposes only.

Let me know if you have any other questions, and good luck!

SamplePluginWithCleanupLogic.zip (218.9 KB)

3 Likes

Thank you very much for the detailed example and walkthrough!

Just a note: I had to add /netfx to the Debug Command Line arguments (maybe because of how my Visual Studio is set up - btw, yes, I do use it, although when I want to quickly test some simple logics it feels too clunky, so, despite my gripes with the Script Editor, I start testing stuff there).

I think I got the logic, I’ll study the example in the next days and hopefully won’t have to bother you anymore for this matter!

Thank you again!

1 Like