Get a function into Python Script as an input?

Is there any way to get a function into Python Script as an input?

fPython

 

 

 

 

 

 

1 Like

hi mehmet, yes of course you can use functions in python nodes!

  1. internal functions are like:

def flunwrap(a):
#load input flattened and Unwrapped
for x in a:
for y in x:
elements.append(UnwrapElement(y))
return elements


to use it, just call it like:

flunwrap(IN[0])

it is even possible to use external functions! that is what makes live a lot easier! :wink:

how will it work?

  1. create a path to your personal library:

libpath = 'd:/Daten/ARCHITEKTUR/DYNAMO/Python-Codes/'
library = ‘2015DynamoLibrary.py

  1. create the execfile reference:

execfile(libpath+library)

in your library file the syntax is like:

def flunwrap(a):
"load input flattened and Unwrapped"
for x in a:
for y in x:
elements.append(UnwrapElement(y))
return elements

you see, almost the same as in a python node (as far as i found out using a comment in the first line of a definition in an external file will be handled as message and has to be embraced by “”)

greatest advantage in day to day use: less typing as most of your functionsf can easily be generalized.

better enviroment for python coding in external editors :slight_smile: :slight_smile:

 

Passing nodes as functions to Python used to work in Dynamo 0.6.3 (and it was awesome!!!), but is currently not supported:

1 Like

Is it now possible to use Functions as inputs in python scripts?

maybe this wasn’t the answer you were looking for…
but it is is quite fun
node base python.dyn (37.1 KB)

2 Likes