Python API?
Hello!
I just discovered this wonderful program (N3). Thanks and congratulations!
I'm familiar with Python programming, so I'm wondering what can be done with Python today. I see there's a python console available, but I'm not sure how I could point to an arbitrary script -- "import sys" and "import os" both fail. I also don't know what facilities are available from Python right now. I gather from other discussions that networks cannot be built programmatically, but that Python code can be used to create custom nodes. I don't know what the abilities of such a custom node could be, i.e., what the Python API is. Could it invoke other nodes? Could it invoke drawing primitives? How does the API relate to what could be done in N1 (which, alas, I cannot run because I'm on Windows)? Are there any examples?
I'd be interested in hearing what your plans are for the Python API. Also, if there's a way to "vote up" the priority for working on the Python API or other related functionality, consider this message such a vote :-)
Thanks again for your hard work!
Mike
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
Support Staff 1 Posted by lievenmenschaer... on 08 Jan, 2013 10:18 AM
hi mike,
There is still some information missing on the website when it comes to working with your own code. For the moment NB3 can import python and clojure scripts. An integrated code editing tool (as in NB2) is at this time not implemented.
The procedure as it is now:
Create a folder to store your python file.
In NodeBox, create a new document and store it inside this folder. This step is important because NodeBox won't allow you to import
outside code when the document has not yet been stored. Also, because
code dependencies are stored inside the .ndbx file in a relative way
it's wise to have the ndbx file and python code files close to each
other (e.g. in the same folder).
Write some code and put it inside a python file (mycode.py). NodeBox relates every node to a specific function and it calls its parameters
one on one. The names of the parameters are not important but their
order is. For example adding 3 numbers:
def add(a, b, c): return a + b + c
Import the code inside NodeBox:
You can now create a node based on this code:
Hope this helps. We'll put this information en some examples on the website in the near
future as well.
lievenmenschaert closed this discussion on 08 Jan, 2013 10:20 AM.
Stefan Gabriels re-opened this discussion on 31 Jan, 2013 08:24 PM
Support Staff 2 Posted by Stefan Gabriels on 31 Jan, 2013 08:24 PM
Our documention now includes a page on how to create nodes that link to custom python code. It lives here:
http://nodebox.net/node/documentation/advanced/programming-nodes.html
Stefan Gabriels closed this discussion on 31 Jan, 2013 08:24 PM.