Skip to content
Advertisement

Result of function is returned without changing list items in if-statement

Thanks in advance for your input.

I started learning Python today, because I want to define custom Python nodes in DynamoBIM (Revit) to be more flexible if there aren´t predefined / suitable nodes for my tasks in BIM.

The PythonScript gets input from input nodes, which are IN[i].
In my case I use 2 bool values (IN[0], IN[3]), 1x str IN[1], 1x float IN[2] and 1x list IN[4].

After processing the input via PythonScript it returns a result (OUT), which can be used for further tasks.

I tried to attach a prefix in front of every list item, if IN[0] = True and add a value IN[2] to each list item, before it´s changed. The result is displayed in the watch-node.


In case of IN[3] = False (list isn´t replaced) I get the desired result:

enter image description here

In case of IN[3] = True, the custom list, doesn´t get adapted (no prefix added, no adding of values):

enter image description here


Code of the (integrated) PythonScript:

JavaScript

Python-code (compilable in online compiler)

JavaScript

I tried to reproduce the problem from the integrated script in a online compiler with python code, but in this case the expected result got calculated:

JavaScript

Compiled with https://www.programiz.com/python-programming/online-compiler/


Expected result should be:

enter image description here

I don’t currently have the slightest idea why there are different results between the online compiler code and the integrated PythonScript.

Advertisement

Answer

I Previously had some issues with dynamo and python, in most times I found that the best practice is to use OUT only once at the end of the code. I took your sample and modified it, Try it. I added an empty list that will be used as a container for the processed list, and assigned it to the output

JavaScript

And don’t forget to review your indentations within the Python node inside Dynamo.

Advertisement