project.activeLayer.children[i] returns a weird object

93 views
Skip to first unread message

Benz Muircroft

unread,
Feb 27, 2015, 4:49:43 PM2/27/15
to pap...@googlegroups.com
I can see that I have 5 pen paths drawn to the canvas, but, when I loop through them like this

var i=project.activeLayer.children.length;
   
while(i--){
        console
.dir(project.activeLayer.children[i]);
       
// i try to do the next part here...
       
}

I have no access to anything about the pathItems

//... some tests inside the loop..

project
.activeLayer.children[i].visible=false; //has no effect

project.activeLayer.children[i].moveTo(new Point(50,50)); //has no effect

var group1=new Group();
project
.activeLayer.removeChildren(group1.addChildren(project.activeLayer.children[i])); //causes errors


I expect to see pathitem properties and options shown here > http://paperjs.org/reference/pathitem/

But instead I get this:

A.extend.initialize
    _applyMatrix
: true
    _bounds
: Object
    _clockwise
: undefined
    _closed: false
    _currentPath: undefined
    _curves: undefined
    _decomposed: undefined
    _globalMatrix: se
    _id: 6
    _index: 4
    _length: undefined
    _matrix: se
    _monoCurves: undefined
    _parent: w.extend.initialize
    _position: undefined
    _project: s.extend.initialize
    _segments: Array[13]
    _selectedSegmentState: 0
    _style: e.extend.initialize
    _updateVersion: 76
    applyMatrix: (...)
    area: (...)
    blendMode: (...)
    bounds: (...)
    children: (...)
    className: (...)
    clipMask: (...)
    clockwise: (...)
    closed: (...)
    curves: (...)
    dashArray: (...)
    dashOffset: (...)
    data: (...)
    fillColor: (...)
    firstChild: (...)
    firstCurve
: (...)
    firstSegment
: (...)
    font
: (...)
    fontFamily
: (...)
    fontSize
: (...)
    fontWeight
: (...)
    fullySelected
: (...)
    globalMatrix
: (...)
    guide
: (...)
    handleBounds
: (...)
    id
: (...)
    index
: (...)
    interiorPoint
: (...)
    internalBounds
: (...)
    internalRoughBounds
: (...)
    justification
: (...)
    lastChild
: (...)
    lastCurve
: (...)
    lastSegment
: (...)
    layer
: (...)
    leading
: (...)
    length
: (...)
    locked
: (...)
    matrix
: (...)
    miterLimit
: (...)
    name
: (...)
    nextSibling
: (...)
    onClick
: (...)
    onDoubleClick
: (...)
    onFrame
: (...)
    onLoad
: (...)
    onMouseDown
: (...)
    onMouseDrag
: (...)
    onMouseEnter
: (...)
    onMouseLeave
: (...)
    onMouseMove
: (...)
    onMouseUp
: (...)
    opacity
: (...)
    parent
: (...)
    pathData
: (...)
    pivot
: (...)
    position
: (...)
    previousSibling
: (...)
    project
: (...)
    registration
: (...)
    rotation
: (...)
    roughBounds
: (...)
    scaling
: (...)
    segments
: (...)
    selected
: (...)
    selectedColor
: (...)
    shadowBlur
: (...)
    shadowColor
: (...)
    shadowOffset
: (...)
    strokeBounds
: (...)
    strokeCap
: (...)
    strokeColor
: (...)
    strokeJoin
: (...)
    strokeScaling
: (...)
    strokeWidth
: (...)
    style
: (...)
    transformContent
: (...)
    view
: (...)
    visible
: (...)
    windingRule
: (...)
__proto__
: A.extend.initialize

Benz Muircroft

unread,
Feb 27, 2015, 8:30:58 PM2/27/15
to pap...@googlegroups.com
var paths=project.activeLayer.getItems({type:'path'});

for(var i=0;i<paths.length;i++){paths[i].remove();}//for example

This helps! but it would be good if we could say 'but not type retangle, circle'...

And this btw doesnot work at all

project.activeLayer.getItems({type:'path',inside:hitResult.item},function(){console.log('done');});

done is never called, but if I do

var result=project.activeLayer.getItems({type:'path',inside:hitResult.item},function(){console.log('done');});

then result will be array of zero and 'done' never shows

the way to do it for now seams to be

var result=project.activeLayer.getItems({type:'path'});
//then filter the results manually as the results are an array..


Benz Muircroft

unread,
Feb 27, 2015, 9:00:29 PM2/27/15
to pap...@googlegroups.com
also if I do this in the console (with 5 items on the canvas)

console.log(paper.project.activeLayer.getItems({id:1}).closed)

I get undefined. but if i console dir this

paper.project.activeLayer.getItems({id:1})

I get the weird object again

What is that object?????

Jürg Lehni

unread,
Mar 1, 2015, 6:43:46 AM3/1/15
to pap...@googlegroups.com
It looks like you're working with the minified library, thus debug logging makes less sense.

But even with the unminified library, Chrome prints our constructors and instances of them in a bit of a weird way, instead of their name, it says things like "Base.extend.initialize", which is a shame (the constructors are named constructors). You can always inspect the item, e.g. item.className, to find out more.

Not sure what else is going wrong in your code, and it's impossible to say without seeing the content.

--
You received this message because you are subscribed to the Google Groups "Paper.js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to paperjs+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jürg Lehni

unread,
Mar 1, 2015, 6:47:35 AM3/1/15
to pap...@googlegroups.com
One more thing:

I'm not sure where you got the idea from that your "done" function should be fired...

This is not node.js, paper.js functions don't execute asynchronously so we don't need such callbacks. Also, the document doesn't mention such a 2nd parameter:


This helps! but it would be good if we could say 'but not type retangle, circle'...

You can provide a function instead of the match object, and in that function you can do all kinds of checks for the filtering.

J
Reply all
Reply to author
Forward
0 new messages