tag:support.nodebox.net,2012-11-01:/discussions/nodebox-2-3/32-how-to-change-view-to-script-modeNodeBox: Discussion 2014-02-11T22:23:55Ztag:support.nodebox.net,2012-11-01:Comment/227805042012-12-20T15:20:52Z2012-12-20T15:20:52Zhow to change view to script mode?<div><p>We did have a code editor in the previous edition of NodeBox,
but because the internal workings have changed quite a bit since we
started developing NodeBox 3 we decided to leave it out for the
time being. We do agree that an integrated code editing tool is a
valuable thing to have though, so it will definitely return one
day.</p>
<p>That said, it's totally possible to integrate your own code
into<br>
NodeBox, even without having a dedicated editor. The procedure as
it stands right now is as follows:</p>
<ul>
<li>
<p>Create a folder to store your python file.</p>
</li>
<li>
<p>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).</p>
</li>
<li>
<p>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:</p>
<p>def add(a, b, c): return a + b + c</p>
</li>
<li>
<p>Import the code inside NodeBox:</p>
<ul>
<li>Go to File > Code Libraries (a new dialog will show
up).</li>
<li>Press the + button and choose Python.</li>
<li>In the file dialog select mycode.py.</li>
<li>Close the dialog.</li>
</ul>
</li>
<li>
<p>You can now create a node based on this code:</p>
<ul>
<li>Inside NodeBox, open the node selection dialog and add a new
"root" node (the first one to show up in the dialog).</li>
<li>When added, this node is named _root1, but feel free to rename
it.</li>
<li>With this node selected, press the Metadata button on top of
the ports panel. A new editor window will show up.</li>
<li>In the left panel, click on "settings". This will bring up the
node metadata.</li>
<li>In the field "Function" write down "mycode/add".
<ul>
<li>"mycode" is the name of the python file we created (here, we'll
also call it the function's namespace).</li>
<li>"add" is the name of the function we wrote.</li>
</ul>
</li>
<li>We have a new node but we still have to map the function's
parameters to node ports (parameters):</li>
<li>Press the + button in the bottom left part of the metadata
panel.</li>
<li>An "Add new port" dialog shows up. Give your port a name "a"
and a type "float".</li>
<li>Optionally, more parameter tweaking can be done at this
point.</li>
<li>Repeat this process for the "b" and "c" parameters.</li>
<li>Press "Ok" to apply your changes.</li>
<li>That's it, the node is ready to use!</li>
</ul>
</li>
</ul>
<p>You can make changes to the code in an external editor, then
press Command-R to reload the code instantly in NodeBox.</p>
<p>Hope this helps. We'll put this information on our website in
the near future as well. If you have more questions please do feel
free to ask!</p></div>Frederik De Bleser