Call variable from ironpython node to external python script

Hi guys,
as a simplification of my problem, I created an external file with the following code:

n = aaa
if n <= 5:
    n += 1
    n += 2

meanwhile, inside the Ironpython script in dynamo I have:

import sys
import clr
from Autodesk.DesignScript.Geometry import *

sys.path.append("C:\\Users\\.....") # location

aaa = IN[0]

from test import *

OUT = n

and the error is

global name “aaa” is not defined, beacuse inside it’s not.
And now the question: is there a way to make the variable aaa readable in
Thanks in advance!

I don’t think this is possible, although I may be wrong. Is there any specific reason you’re trying to do this? If I were you, I would treat your python node in Dynamo as your and import functions from as if it were a module.

Thanks @cgartland for the quick answer.
I thought about it as well. But the main reason for it is that I’m going to use my more than one time in different python node and the code is not so simple… so if I have to modify it, I only do it once…

For that reason I would recommend defining all of your common functions in and importing them as needed. For example, if this is

def test_func(var):
    var += 1
    return var

And this is your Dynamo node:

from test import test_func
a = 1
b = test_func(a)
OUT = b

You can use test_func in as many other Dynamo graphs as you need, but you don’t have to worry about global variables.

What is in and could what is in be put directly into a python node?

Reason i ask this is because you could just do the following, though you will have to change your input “aaa” to “IN[0]”

1 Like