1. NodeBox 1
    1. Homepage
    2. NodeBox 3Node-based app for generative design and data visualization
    3. NodeBox OpenGLHardware-accelerated cross-platform graphics library
    4. NodeBox 1Generate 2D visuals using Python code (Mac OS X only)
  2. Gallery
  3. Documentation
  4. Forum
  5. Blog

Path to layer problem

Posted by Alexey on Aug 05, 2009

Guess I don't quite get the thing with Core Image library.
I have a grid of ovals and I need to add some filters to the image.
Here's the code...

ximport("coreimage")
 
#--------INIT DOCUMENT---------
size(297*mm,210*mm)
colormode(CMYK)
background(1,0.60,0,0.60)
 
#-------------------------------
 
canvas = coreimage.canvas(WIDTH, HEIGHT)
 
class soundGrid:
    def __init__(self, filePath="test.dat"):
        self.txt = open(filePath).readlines()
        self.i=0.0
        self.j=0
        self.data = []            
        self.fileToArray() 
        self.path = BezierPath()   
    def fileToArray(self):
        for l in self.txt:
            if self.i==100:
                str=l
                line1=str.split()
                newx=float(line1[0])*3000
                newy=float(line1[1])*10
                self.data.append(newy)    
                self.i=0
            self.i=self.i+1
 
    def makesoundGrid(self):
        self.j=0
        for x, y in grid(29,21,10*mm,10*mm):
            push()
            nostroke()
            scale(self.data[self.j])
            c1 = color(1,0,0,0,random(0,0.5))
            fill(c1)
            fig = oval(x,y,10*mm,10*mm)
            path = drawpath(fig)
            c2 = color(1,0,0,0,random(0,0.8))
            strokewidth(random())
            stroke(c2)
            c2 = color(1,0,0,0,random(0,0.8))
            self.j+=1
            pop()
        return self.path
 
#makesoundGrid()
newsound = soundGrid()
newsound.makesoundGrid()
 
 
canvas.layer = canvas.append(
    newsound.makesoundGrid(), 
)
 
 
canvas.layer.filter("zoomblur", amount=10)
canvas.draw()
I keep getting the "AttributeError: 'NoneType' object has no attribute 'filter'" stuff...
Need help!
Thanks in advance


 
Posted by Josh Caswell on Aug 14, 2009

There's a couple of funny things about this code.

You're returning an empty BezierPath from makesoundGrid(), and when you append an empty path onto your canvas, it just appends None. Then when you call filter() on None, you get that error.

In makesoundGrid(), assigning to path:

path = drawpath(fig)
creates a new variable, local to makesoundGrid, called path. It doesn't assign to self.path, which I assume is what you want.

Also, assigning the result of append() to canvas.layer is kind of weird, since layer() is actually a method of canvas (it does the same as append()). I think you probably want to create your own variable there.