Compare two parameter values to set a third

Hello everyone! First off, thanks so much for all of the knowledge being shared here. It has helped me tremendously as I navigate my way through the Dynamo forest!

I’ve managed to do things like copy parameter values from one to another successfully, but this time I’m stumped as I think I may be dealing with If sorts of statements here. I have no experience or knowledge with coding so I’m hoping to learn enough to figure this out.

My goal is to take two parameters, compare them to each other some way, and then use the result to set a third parameter value. I’ve managed to pull the parameters I want to compare and identify the parameters I want to modify, but when I get to the If part, (using a codeblock) I hit a wall:

My first test is to compare the “Estimated Design Start” parameter to the “Report End” parameter. If the first is greater than the second, then “Future Project” should be ‘Yes’ or ‘1’. If the first is less than the second, then “Future Project” should be ‘No’ or ‘0’. Any direction is very much appreciated!

You’re almost there. You need to use the parameter values instead of the parameter names and then define your outputs for True and False, 1 and 0.

Thanks for the quick response! So rather than saying “Estimated Design Start” in the string, I should pull the value from the “Element.GetParameterValueByName” node? I then set my “True” result as “1” and my “False” result as “0”?

Would I then use something like the “Parameter.SetValue” node to turn my “Future Projects” parameter on or off, (set to 1 or 0)?

Exactly. The IF node will give you the output based on your condition, then you can use that value as the input when you set the parameter values.

1 Like

Okay, I think I get the idea, however it looks like I may have missed a step. For my “If” statement node, I set the test to be x, (‘Estimated Design Start’ pulled with the Element.GetParameterValueByName node) is greater than y, (‘Report End Date’ also pulled with the Element.GetParameterValueByName node). I then set the True value to be “1” with a string node and False value to be “0” with a string node. Initially I connected the result of that to a Parameter.SetValue node for my ‘Future Project’ parameter. I got a warning that it couldn’t use a string for the value. When I then attached a Watch node to see what I was getting, I didn’t get a list of 0’s and 1’s as I had expected.

Here’s the updated script:

Any additional feedback would be very appreciated!

Your Future Project parameter isn’t a string parameter. Make sure your input matches the parameter type.

After a bit of back and forth, and A LOT of time, I have been able to revisit this script with some additions and modifications. To facilitate the comparison of values, I’ve changed out the Text parameters I was using with Integer parameters so I no longer have to deal with converting strings to numbers. Small victory there!

I am now able to get the ‘Future Project’ parameter to switch to Yes or No with the Greater Than comparison I described in the original post. The script checks each area object against the parameter I am comparing to and turns on or off the third parameter based on its findings:

When I move to the next step, using the same logic, I run into an issue with the script. This time around, I am using a ‘Less Than’ comparison to set another parameter to Yes or No. The problem now is that when I run the comparison, I only get one element listed in the results. Initially, I was also only getting one element listed after the “Element.SetParameterByName” node. After a bit of research, I tried using the “ScopeIf” rather than just a regular “If” node. I am still only seeing one result from the comparison, but at least now, I am seeing all of the same elements listed after the “Element.SetParameterByName” node as I am with the ‘Future Projects’ comparison:

I’ve checked the values manually and know that there should be at least 5 instances where the “Less Than” comparison for “In Design Projects” will yield a Yes result. Maybe I’m missing something with lists and lacing?

Any light the community can shed on this is very much appreciated!

Does any one have a script to (copy parameter values from one to another)
This would be for System Parameter to Project Parameter…specifically “Area”