Contours without a Custom Node

john's Avatar


27 Jul, 2020 06:46 AM

Even after all these years I am still learning new tricks from other users on the forum.

One of the things not built-in to NodeBox is a node which can extract individual contours from a multi-contoured path. Multiple contours most commonly occur in text paths like the letter "a". One closed path describes the outer shape of the letter; a separate, unconnected path describes the bowl inside the letter (or the dot atop a lower case j ). If you resample such paths or manipulate them in other ways, the contours are usually lost and you end up with an unsightly line connecting the inside of a letter with its outside.

You can solve this problem with a single line of Python code wrapped in a custom node. Frederik supplied such a node years ago and I included it in my node library because it is so essential. But I prefer not to use custom nodes unless I have no other choice. They are a slight pain to deal with and will generate errors if you forget to include them when distributing a network or change your file path. It's also an interesting challenge finding ways of doing things entirely within NodeBox.

I spent months looking for another way to split a path into its constituent contours, but was never able to crack it. Then, a few weeks ago, I stumbled onto an old network by veteran NodeBoxer Rioch containing a node that performs this miracle.

The trick is to do a lookup on the contours property. When you do this, you get a comma-separated list of references to internal NodeBox contour pointers. I was aware of this, but thought you couldn't do much with them; they just generate errors if you hook them to anything else.

The first thing I noticed was that Rioch's lookup somehow generated a list of separate items instead of single comma-separated item in parens (which is what happens by default). It took me awhile to figure out that you can achieve this affect by simply rendering the node, opening the Metadata dialog, and, under Settings, change Output Range from "Value" to "List". I was also aware of this setting but had forgotten about it since I have never before found a use for it. The result is shown in the attached screenshot.

So far so good, but I still didn't see what good this would do. The contour references are not normal NodeBox objects. If you try to colorize them or do most anything else, NodeBox will bark at you. But it turns out that there is one thing you can do with them: resample them (which is what Rioch's network did). This leaves them as contours but at least doesn't generate an error. I realized that if you could resample, you could also turn them into full-fledged NodeBox points by simply feeding them into a point node. You could then reconnect them to form fully-functioning paths.

One more challenge remained. When you use a connect node you have to decide whether or not to check the "Closed" checkbox. Some contours are closed; others are not. How can you tell? There is a closed property, but unfortunately it doesn't work. This is a known bug which I complained about years ago to no avail. You could inspect this property using Python but then you'd be back to using a custom node.

My solution (based on the closed node already in my node library) is to lookup the length of each contour (which fortunately also does not trigger an error) then connect it as a closed path and check the length of that. If the two lengths match, the contour must be closed. If not, I use a switch node to choose an unclosed connect path instead.

So now I have a general purpose Contours node which does not require I was also able to update several other nodes which used my old Contours node and so required the custom code as well; now they are unshackled as well. The next release of my node library (coming soon!) will include all these updates.

Sadly I still need a custom node, join_contours, to reassemble a set of contours into a single multi-contour path. But one step at a time.

A small, very arcane triumph. But it made me happy. Thanks, Rioch!


Reply to this discussion

Internal reply

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

Attaching KB article:


Already uploaded files

  • contour_objects.png 359 KB

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 Jun, 2022 05:30 AM
15 Jun, 2022 06:03 AM
06 Jun, 2022 01:07 PM
02 Jun, 2022 11:58 PM
30 May, 2022 07:48 AM


24 May, 2022 06:27 PM
20 May, 2022 04:12 PM
05 May, 2022 02:25 AM
03 May, 2022 04:46 AM
01 May, 2022 09:22 AM
18 Apr, 2022 09:01 PM