Run one Script out of two, on the given condition

Hey, I’ve a list of concrete elements and steel elements, but i want to run different scripts on them. If my parameter “Element material name” is “Concrete”, i want it to run script A onwards. AND DO NOT RUN SCRIPT B AT ALL! . Similarly, If my parameter “Element material name” is “Steel”, i want it to run script B onwards. AND DO NOT RUN SCRIPT A AT ALL!

I know there are many solutions with if statements saying if input is true, run script, if false, do not run. But its not about true or false, or running script or not. Its about “Concrete” or “Steel” and running Script A or B!

Is there a solution to this?

@fil

I’d take a look at using a simple FilterByBoolMask or you can try the ScopeIf node.

Is there a reason you don’t want to run two graphs?

1 Like

There is no reliable way to prevent part of your graph from running. Dynamo executes everything “all at once”. You do have a few options to work around it though.

  1. Let the unused branch run and fail. You’ll have a warning, but everything will still work.
  2. Wrap the two branches inside a custom node. You’ll still let one branch fail and throw a warning, but the warning will stay inside the custom node and not show anything in the main graph.
  3. Rewrite the two branches in python. Python will let you execute part of the code based on your condition.
1 Like

Here is how I would solve it. It might not be the most computationally efficient, but I’ve used this solution to create a script with 2 branches:

You may need to replace the String.Contains operation with something that suits your situation better, but either way, you can use a conditional statement to create 2 lists. The null values will pass through the script and cause warnings, but it will prevent your inputs from going down the wrong branch. You can do a List.Clean operation before each branch if you want to cut down on the warnings (and that might run the script faster).

2 Likes

yeah @SeanP i want to gather info for only one type of element at a time, Like i want to crawl web for “Concrete” only, so I will input concrete in the string, and it will do a separate script to fetch amount of sand, aggregate and cement.
But if i put “Steel”, i do other things for specs, like finding out their weight and rebar number and length etc.
So can’t run the same script for both type of elements. :confused:

@Nick_Boyts

1- Running and making fail might not work, because im using export to excel in the end of both scripts, with different export options.
2- Please describe the second method, seems reasonable!
3- Yes python is a great option, but I don’t master in python :sleepy:

thanks

  1. Writing to Excel is fine. You would just check both outputs before passing that data onto Excel or use a similar condition to get the output of the corresponding material.

  2. Using a custom node is the exact same process as Option 1, you just do it inside the custom node. You just don’t get the warning from running an empty branch.

1 Like

@Frank_Loftus
Wow, this seems like a solution.
But what if I dont have any element from “Steel”? the B part will go all null and what will happen to the export to excel node in the end of B script? how to stop that to execute?

This is exactly what we’re all explaining. You can’t stop it from running. You just have to deal with the warning.

2 Likes

Got it, let me try these options.

1 Like

Although a combined solution may get you where you want to go, but I would suggest looking at different graphs especially since each “branch” is doing completely different things with the elements found. I’d encourage simplicity when possible.

2 Likes

@SeanP What does a ScopeIf node do?

May be good to browse this post.

1 Like

From what i understand, its same as writing a python script for “If else” statement, its great. Let me try it!

ScopeIf is specifically for custom nodes. If you use it in your main graph you’ll likely error or crash.

1 Like

I think you could also use the function apply node on the nodes that output an error, works for me in most cases. Not at a computer now so I can’t try it out for this specific case

1 Like

Hi @uaftab.cem19 Did you get this solution ?

As I am also trying to do the same thing but a different condition as explained in this topic

Can you please tell me how to run the script if it is true ?
I am able to use scopeif but not able to run the whole script.