Conditional Bypass Components

I’m trying to figure out how to do a conditional bypass of a component.

Here is an example of why I want to do this.
I am extruding a circle along a curve. If the curve is 3D, meaning it has a Z axis component to it, then I need to cap the ends. But if the curve is 2D, then the cap fails, because the result of the extrusion is all on the same plane, so there are no open holes in the result.

I made it kind-of work by merging the output of the extrusion and the output of the cap.
Here is an example where the first object is extruded along a 2D path, and the second one is extruded along a 3D path.

But this is not what I want. I don’t want the untrimmed surface if the cap was successful, and I don’t want the null if it failed.
I want to bypass the Cap component, ONLY if it fails.
In other words, I want the output of Cap to be the capped extrusion if Cap is successful, otherwise I want it to pass through the extrusion, un-modified. so, the result of my example would be

{0:0} Untrimmed Surface
{0:1} Closed Brep

If I had a way to check the success of the Cap component, then I can get what I want with Stream Gates like this:

I thought I could pre-determine if the Cap would be needed, but Cap already does that, so why should I bother doing it myself, I just need to find out if Cap was successful or not.

This is just one example, I also would like to bypass a Boolean Subtract if it fails for whatever reason so that the geometry I was attempting to subtract from can continue down the line, even if the Boolean failed. I will still see that things fail because they will turn red and I can check them out, but there are times when the failure is fine, and I just want to go around the failure.


In this case you could use Replace Nulls after the Cap Holes to put pack the original item in the list, or another one of your choice.
There is also Null Item that checks for nulls or invalid outputs, and can be used with a Pick'n'Choose after.

Another idea that I use sometimes : Merge the potentially problematic component (Cap Holes) here, and the replacement item. Then use Clean Tree and List Item to retrieve only the first valid item.

Hi @magicteddy

Thanks for the suggestions! Replace Nulls does what I want for the Cap Holes. Is there a way to just remove only nulls?

Edit: I see Clean Tree has an option for that.

1 Like

Yes, Clean Tree with input Remove nulls = True would do that.

Remove Nulls doesn’t work if there is nothing there. I am trying to do A Boolean Subtract only if there is something there, otherwise, I want the original to move on to the next step. Remove Nulls works great if there was a null due to a failed operation, but it doesn’t work if there was never anything coming in.


Yes, because there is no null item to search for.

As an alternative, you can calculate the length of the input list using List Length and test if it’s equal to 0. Then use Pick'n'Choose to choose the output of the Solid Difference if 0, or the original Brep is 1.

Null Item also works - which sounds like a bug that null is detected with it, but not with Replace Nulls (17.7 KB)

@magicteddy Thank you for your help! I used a Stream Filter with the Null Item and that works great!

Is there a way to check for Invalid Brep? It’s Not null, so Null Item lets it through.

Or is there a way to check for “Closed Brep” specifically and I will reject everything that does not produce a Closed Brep

It is possible with C#, or by testing the text conversion of the Brep - not that intuitive I’ll admit.

The Invalid items can be tested with Null Item, using the X output. So you could also use Or to test if an object is null or invalid. (13.6 KB)

Hi @magicteddy

That C# Script works great!

I am wondering if there is some way to maybe make the script turn red when it outputs a false so I can quickly see it triggered? The problem is that when this Invalid Brep issue happens, there is no indication of where it went wrong. Nothing generates an error, not even the Solid Difference that created the Invalid Brep.

There is a IsValid property for brep.
This together with Component Errormessage should work.
Something like this:

 private void RunScript(Brep brep, ref object A)
    Component.Message = "isBrepValid";
    if(brep == null)return;
    A = brep.IsValid;
    if(!brep.IsValid) Component.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "This brep is not valid");

Thanks @Baris , I merged that code with the original component, which now checks for null breps, invalid breps and open breps.

One could also use the Pie Chart as a warning, although I can’t seem to be able to define custom colors… (23.1 KB)

Thank you @Baris and @magicteddy That works quite well!

Where did you get that cool pie chart? I tried to CRTL + ALT + Click on it but I don’t find it.

It’s in the Display tab.

The shortcut seems to work only if clicked on the black border of the pie chart !


@magicteddy clicking on the black border worked, thanks!

just taking a wild guess, I noticed I could make it an error with:
this.Component.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, “Brep is invalid.”);

Yes, you also have .Remark that leaves the component blank.
I chose to leave it as .Warning so that it could visually be distinguished from a real error of the component, but if you prefer it that way, that is perfectly fine.

I would probably want to do that as well, except that as you can see in my screenshot, Solid Difference does not produce an error even while it’s outputting an Invalid Brep

I’ve put that on the list today as RH-72320 solid difference component doesn’t turn red on invalid result

1 Like