Keep dynamo from executing nodes it doesn't need

So I have this script that helps me apply filters to a selected set of views.

Within the script; I handle:

  1. Getting the desired filter from the model IF it does exist
  2. Creating a new filter if the desired filter does not exist
  3. Apply said filter

My problem is mainly… that the IF node still seems to run all my nodes instead of the branch chosen by the condition:

I’m using an IF node at the end where I gather my filters ( both created and found )
THe IF node takes the following input:

  1. A boolmask: True = The filter for this view exists // False = The filter for this view has to be created
  2. True: A list of filters retreived from the revit doc
  3. False: A list of filters created

In the screenshot; you can see the “ParameterFilterElement.ByRules” throw a warning because it tries to create a filter that already exists. But the way I’ve set it up. I’d expect it to not even be run for filters that already exist.

Considering how Dynamo works you can’t stop those from running with an If node.
I’m not sure it’s exactly in the nature of Dynamo to NOT run things, but I think you get a work around with a code block or Python.

1 Like

Paul is correct. Because you’re never tying the second group of functions into the first if statement, so it’s processing all nodes acordingly.

Try converting the first if node to a code block and calling the functions required to create the filters inside that code block. Node to code will help with this. Also read up on If statements in design script as that function won’t usually node to code. They follow this format:

Test ? ResultIfTrue : ResultIfFalse;

That’s a bit of a bummer.
I guess a DS or PY block could indeed help out here I’ll give that a spin when I can.
Now the node doesn’t really do anything wrong in this script so it can stay there. But can I disable/ignore that particular warning in a way?

The warning doesn’t hurt anything actually.
There are ways to make this more efficient. It’s worth knowing to go into the details of that whether both values are calculated with the same starting data.

1 Like

@gertjan.vdb scope if is for this case specifically.

2 Likes

http://dictionary.dynamobim.com/#/Core/Logic/Action/ScopeIf

Thanks for the idea, but it appears my script crashes if I replace my if with a scopeif.
Though I’ve been able to create a small test case in which it indeed provides the behaviour I’d expect. So thanks :slight_smile:

But I’m going to stick with try and putting it all in a code block. It’s going to reduce clutter significantly.

@gertjan.vdb - scope if requires that the two true/false branches are totally independent, that might be the cause of the crash.

1 Like