Workflow Gate (True/False)

Hi,

I am trying to make a script that checks for duplicate parameter values, like Mark and ElementID, then overwrites them with new unique values. I have it mostly done but I would like to add an option to check the changes in a spreadsheet before you finalize the changes to the model.

What I really need is and if gate that goes something like this

image

or a more advanced gate like

image

I’m pretty new to dynamo, and this is my first post on this forum, so if you have any suggestions or if there is a package that you could point me to it would be greatly appreciated.
-Thanks

Try the ScopeIf node and see if that works for you.

You could try the ScopeIf node as Sean suggested, or List.FilterByBoolMask (similar to a dispatch node in grasshopper). However, if you want more than two outputs, it gets more complicated. You could string together a series of logic gates, but this could get really messy. You might be better off doing your tests in Python and splitting the data outside of the node:


Logic Flow.dyn (18.4 KB)

def test_1(var):
	if 0 <= var < 4:
		return True
	return False

def test_2(var):
	if 4 <= var < 7:
		return True
	return False

def test_3(var): # True if var is even number
	if var % 2 == 0:
		return True
	return False

data = IN[0]

valid_1 = []
valid_2 = []
valid_3 = []
valid_none = []

for cell in data:
	cond_1 = test_1(cell)
	cond_2 = test_2(cell)
	cond_3 = test_3(cell)
	if cond_1:
		valid_1.append(cell)
	if cond_2:
		valid_2.append(cell)
	if cond_3:
		valid_3.append(cell)
	if not any([cond_1, cond_2, cond_3]):
		valid_none.append(cell)

OUT = [valid_1, valid_2, valid_3, valid_none]

There seems to only be one output out of the ScopeIf node, and I don’t know how or if you can control what node you want it to go to on a true condition opposed to a false condition.
image

Thanks for the suggestion,

Let me clarify a bit, I would like the gate to be controlled independently from the data that it is pushing through it, and the gate to change the destination node based on that independent variable. I want to be able to select which node I push this data to, in this case either to the model from via a Element.SetParameterByName node or to Excel via the Data.ExportExcel node. I would like to see some sort of gate or flow control like this introduced to dynamo, I feel like it could apply in some autonomous modeling situations where you have some base input data, a gate, and then a choice of workflows following that gate.

I think I’m now realizing that it will just be far easier for me to just freeze the node that I don’t want to use and make a note of that for future users of the script.

-Thanks!

You can’t really prevent nodes from executing downstream, but you can force your data to go a certain way with a simple script:

condition = IN[0]
data = IN[1]

if condition:
	OUT = [data, []]
else:
	OUT = [[], data]

In your case, you’d have to send all of your data (element, parameterName, value) through the gate and break it back out using a similar method illustrated above.

1 Like

Partly true, but you can prevent a certain up stream flow from executing by using the scopeif, mind it is a little tricky to get right and one have to be careful to have completely separate true and false tracks but it is possible to only have one branch execute!

But I think that what is sought here is more in the like of your answer or a basic code block

Inp==“condition”?
ActionOne:
Imo=="condition2?
ActionTwo:
“Noconditionoutput”;

1 Like

I wish I were better at python, but could you help me troubleshoot what’s going wrong here?


-Thanks again!

As @Jonathan.Olesen noted, you’re likely nest off using a single code block here. If you’re looking to split your data lists into multiple tracks and do a bunch of processing on both sets, List.FilterByBoolMask would also work.

False alarm! It’s working now, I’m not sure what was going on but your code works as intended, and I even figured out how to do the multiple option thing that I purposed.


-Thanks

:thinking:

A dictionary might also work well there, adding values and pulling them based on the desired result.