Sort of "on/off" switch needed

Hi all,

I’m creating a script that’s getting a lot of rebar info from excel.
But not all rebar is necessary but the calculation rules are present in the Dynamo script.
I’d like to make some sort of “switch” that looks to the input (an excel cell) and when it have a value it passes that value but when it has no value it’s “suspends” a part of the script.
Basicly I want to keep the calculation without the output to Revit but I don’t want the yellow error signs!
A bit error catching and handling.

How do you do this?

@Mike_Wellink Seems possible.
However, you might get suggestions specific to your issue if you post files and images of your attempts.

Hi @Vikram_Subbaiah,

I’m sorry…sure I can. First I just wanted to know if the thing I need actualy can be done in Dynamo.

I already tryed the "passthrough’node from the Clockwork package and placed it fore the Rebar.ByCurve node.
But that only result in an error. And yet when I don’t connect a node to the hostElementId input…no error and also no rebar in Revit.

So I started to make an design script “switch” with an if-statement but that also fails.

The thing is that the calculation for the rebar must be present in the script but the input could be not present.
So the rebar isn’t needed. And when a calculation has no input it gives an error.
And though the script will complete as intended…it gives back errors to the user who does not understand those errors because he/she is using Dynamo player and doesn’t know how Dynamo works.
He/she just reads “Run completed with warnings” and stops working to ask for help.

But I also attechet my side calculation file hoping someone can help me.
Ortho coordinates on a circle.dyn (39.5 KB)

@Mike_Wellink What does the warning says?

@Mike_Wellink
hi, just trying to help.

Have you already tried the if statement? I normally use this together with “passthrough” . I got the image online to explain better.

hope this helps…in a way.

1 Like

Hi @Kulkul,

It’s a long warning:

But the strange thing is…this is my side script! And this is a 1-on-1 copy from my large mainscript.
And in my mainscript it works just great. atleast…the standard way that is.
When I get the “Curve” input from the Line.ByStartPointEndPoint node it works in my mainscript but give a error in my side script. And it’s just copy and past into a new script.

Hi @4bimferdie.espiritu,

This for thinking with me! Much appreciated!
I had no idea of these nodes. But aren’t you doing the same thing as I do inside my code block?
You do it with nodes and I’m doing it with a designscript.
Here’s the content of my code block:

input;
element;
//create switch
switch = [Imperative]
{
if (input == "yes")
{return = element;
}
else
{return = null;
}
};

Were “input” gets the Yes or no input and “element” is the list of lines.

I’m just looking for a way to “switch off” a part of the script when it isn’t needed/has no input to calculate with so it wouldn’t produce an warning.

You can write this in a shorter way…

input == “yes” ? element : null;

4 Likes

Hi @Erik_Falck_Jorgensen,

Thanks, though I have no clue to what it does.
hmmm…wait a sec…
input equal to yes? Then pass element, else null??
Is that correct?

Don’t get me wrong but although I learn a lot from this I’m not closer to my goal.

Could this perhaps work:
Put the “switch” after the Rebar.ByCurve node??
Or will it still put the rebar through to Revit and than go to the “switch”?

Hi @Erik_Falck_Jorgensen,

I thought so to…that the “null” part is the problem.
To solve that I’d like to pass…nothing! But I have no idea if that is possible.
Because when I disconnect the ElementId from the Rebar.ByCurve the script runs and I don’t get a warning massage.

But like I mentioned I don’t know if it is possible.
If input equals this then let element pass… if it doesn’t do nothing/break/don’t pass anything/cut the line/disconnet to the Rebar.ByCurve input!

Hey Mike… i have tried this also in one of my scripts and till now i seem to get nothing to do the trick… exactly like you said ( cute the line ) part!

but i’m trying to do something now which is if i can say ’ passing fake value ’ when it doesn’t equal to yes. you might want to try that.
i’ll keep you updated

Hi @Mohammadz,

PLEASE DO!!! :grinning:

just clean the list for nulls, thats really easy… see my post where the code is included…

…Or download a package from Archilab, Lunchbox or DanEDU. There is nodes for this.

:worried: But my list doesn’t contain nulls … only Lines.

why do you then use the if branch if all elements is lines?
you need to make a test which makes sense, meaning that the passed elemets gives you something to continue working.
You need to have a proper input…

I know…I know…sorry for the confusion.
But in my case the “switch” is intended for the ElementID input of the Rebar node.
I noticed that when I leave that input unconnected the node doesn’t have enough input to work and turns light grey instead of dark grey. And I don’t get a warning.

as far as I can see from screen dump, you need to pass curves, not lines. Try Rythm package, it includes a Curve.FromLine.

But a curve is also a line and a line is also a curve.
(Don’t get me wrong Erik…I’m not attacking you … I’m just debating and looking for a solution)
When I run my main script (with the same script setup as my side script I posted above) I don’t get that warning.

Revit model view after script has run:

1 Like

@erfajo Just what I was looking for and very elegant, thanks!