Calling Nodebox functions from a library Module

Kevin Karney's Avatar

Kevin Karney

08 Mar, 2015 10:43 AM

I am sure this is an easy question.

I have built many Nodebox 1 utilities that I want to put in a library module. The routines that just use raw Python mathematics work just fine, but any with Nodebox functions (lineto, oval, push, etc etc) fail since the function does not seem to be recognised.

I have tried
from node import *
and many other variations - but nothing seems to resolve this for me.

I am a heavy user of Nodebox 1 but am a very lightweight Python user.....

Any help would be appreciated

  1. Support Staff 1 Posted by Frederik De Ble... on 09 Mar, 2015 09:27 AM

    Frederik De Bleser's Avatar

    You're right: the NodeBox 3 graphics API is different from the NodeBox 1 API. That's because the new API uses Path objects instead of directly drawing which is what NodeBox 1 did. We do this because we can take these generated Path objects and modify them using different nodes, for example the "wiggle" node.

    So whereas in NodeBox 1 you would write:

    rect(10, 20, 30, 40)

    In NodeBox 3, you would construct a Path and add a rectangle to it:

    from import Path
    def my_rect(x, y, w, h):
        p = Path()
        p.rect(x, y, w, h)
        return p

    We call these nodes generators: they only take in primitive values (numbers) and generate shapes. Nodes that take in shapes and modify them are called filters. They might look like this:

    def my_colorize(shape, fill):
        if shape is None: return None
        new_shape = shape.clone()
        new_shape.fill = fill
        return new_shape

    Note that these nodes are required to clone the input shape, instead of modifying the input shape directly.

    The documentation for the graphics API is unfortunately still missing. You can look at the source code for the Path class to see how it works internally.

    I hope this helps. Feel free to ask any additional questions.

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:


Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts


? 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

Recent Discussions

16 May, 2024 02:11 AM
16 May, 2024 01:58 AM
14 May, 2024 01:29 AM
13 May, 2024 12:36 AM
12 May, 2024 07:46 PM


05 May, 2024 04:38 PM
03 May, 2024 06:50 AM
03 May, 2024 12:30 AM
03 May, 2024 12:09 AM
19 Apr, 2024 04:41 AM
16 Apr, 2024 06:18 PM