Copy parameter values with if condition "> 0"

Hello,
I just try to copy values from one parameter to another BUT only those which are larger than 0. So the script also need an if-condition.

In detail: in our project is a room parameter which is called “RA_RB_Soll-Flaeche”. My colleagues filled it sometimes with specific values. When they don’t, the value is 0,00.
Now I try to copy all values bigger than 0,00 to another room parameter which is called “Soll-Fläche”. If there is a value like 0,00 it must be ignored, so the parameter keeps empty.

In the end of my current dynamo script, I uses the block “Element.SetParameterByName”. I could set the right parameterName (“Soll-Fläche”) and I could filter all values which are bigger than 0,00.
But I don’t know how to filter the elements… Can anybody help me please? Thank you very much :slight_smile:

Hello,
you can instead use a filterbyboolmask on your parameter and then apply this same mask on your elements
edit:

cordially
christian.stan

1 Like

Okay, I tried to integrate filterbyboolmask in more varities but I don’t get it. What do I wrong?

You’re feeding the node the same inputs. The list input needs to be the list you want to filter (the parameter value).

1 Like


cordially
christian.stan

Hey thank you for your response. Unfortunately dynamo doesn’t find any rooms when I connect AllElementsOfCategory with FilterByBookMask. In my opinion, it doesn’t make sense.

This is why I make a list by using the blocks Object.IsNull and FilterByBoolMask to show the room elements. I don’t know what it means: there you can read “Dictionary in: Empty List” and “out List: all room ids”…

my go-to method on this kind of work flow is to use enumerate in python. get the index of the items that I only want to modify/copy and use it to feed List.GetItemAtIndex which will then be fed on the element input on Parameter.SetValueByName

elements = IN[0]

indices_of_elements = [index for index, value in enumerate(elements) if value > 0]

OUT = indices_of_element

the idea is that the number of items to be changed should match the number of items that was extracted on if statement (if that makes sense) instead of just feeding all the elements on the category. also makes my script shorter.

1 Like

It sounds good but I cannot imagine exactely what you mean. Can you make a picture of that please?

this is what i meant

CopyParameter.dyn (15.0 KB)

elements = IN[0]

indices_of_elements = []

for index, value in enumerate(elements):
	if value != "" and value > 0:
		indices_of_elements.append(index)
		

OUT = indices_of_elements

added to filter out a null value for safety measure

3 Likes

Oh thank you very much. Now it works, well done! :slight_smile:

I need to learn more about Python Script. There is still one little problem: when a colleague changed a value up to 0 and in the next step you start this script again, there is any number instead of 0. So this must get fixed. Let’s try …

You need to provide more information. In your images you only show a few outputs. We need to see everything that’s going on in your graph to know what’s happening. Otherwise all we can do is guess.

Yeah ok, on the top you can see the current script.
Under this you can see what happens in the model. The values get copied from “RA_RB_Soll-Fläche” to “Soll-Fläche” if the value is bigger than 0.

After this I changed two values down to 0. After restarting the dynamo script, the values didn’t get changed. This is because the script is filtering out this values.
That means, we need to amend something (e.g. another filter, if the value = 0 the script needs to delete it in “Soll-Fläche”)…

There’s a couple ways you could go about this but they’re all basically the same. Essentially you need to check both parameter values through a nested conditional statement.

if RA_RB_Soll-Fläche > 0:
    Soll-Fläche = RA_RB_Soll-Fläche
elif RA_RB_Soll-Fläche == 0 and Soll-Fläche > 0:
        Soll-Fläche = 0

You can clear first the parameter that you want to add values before pasting the new value by adding a few nodes. This way we don’t have to change any nodes from the previous script.

Updated script is uploaded. If this is what you’re looking for you can mark this a solution instead.
ClearParamThenSet.dyn (21.2 KB)

Mh, no it doesn’t work. I guess it’s because dynamo don’t accept the empty value in code block. If the parameter would be a text parameter instead it would work. In this case “Soll-Fläche” is a number/integer parameter…

Hi @RobBoos probably springs node “set parameter to none” could help

1 Like

Just nest the conditions.

hi you can use springs’ “set parameter to none”. or just simply add this to the beginning of code as a value input.