I want to define a global variable in a code block and use/call it outside the scope of that node. For example:
If I pass x as parameter in func(), then code block will ask x for the parameter which I don’t want it to an input.
I want to define a global variable in a code block and use/call it outside the scope of that node. For example:
If I pass x as parameter in func(), then code block will ask x for the parameter which I don’t want it to an input.
You need to set X inside the scope of the definition.
def func()
{
x = “sdf”;
return = x;
};
Then when you want to call it just type func();
, and the result ought to be “sdf”.
If you want to Dynamically set the value you’ll need something quite a bit more complex, and I actually don’t even recommend using the previously explored methods anymore.
@jacob.small
Is there a way to define that path as global var?
My aim is to reuse that code block and call the function every time I need file path, for example.
There’s not really a “Dynamo way” to do this. You can however hide wires between nodes, so you can connect everything and then clean up your graph to look like it, but you can’t write to a function in that way.
You could type the string in the code block, or better yet just use the path and hide the wire (right click on the wire or output port, in product since 2.13, about 2 years now).
If you want to ‘push’ without seeing it hard coded, and to be able to update it, you can write to a scratch file, and read that in. Note that though need to watch the order of execution in such cases; hiding wires is my preference (supported in ~50% of current builds).