0

having problems with a little javascript. Pixate is UI design tool that allows you to build custom actions in JS. I am trying to build a little JS action with a few lines of code, but obviously i am overseeing something evident (sorry, i am not a real coder). Here is my script so far:

var layers = getSelectedLayers();
var erg = "";

for (var elem in layers) {
  erg += layers[elem] + ", ";
}

alert(erg);

var group = createLayer("MyGroup");
group.y = group.x = 0;
group.width = Screen.width;;
group.height = Screen.height;;
group.backgroundColor = 'transparent';

nestLayers(group, erg);

The commands "getSelectedLayers" "createLayers" ans "nestLayers" are offered by Pixate. If i try to run my code, the "getSelectedLayers" seems to be working (the alert function gives back an array of the selected layers). Creating the new layer works also. The problem is, that after starting the "nestLayers" function, after nesting the first selected layer the script stops with an error on my last line "undefined is not a function"...

Any help is greatly appreciated – Thanks!

  • Can you paste the row where the problem occurred? – Lajos Arpad May 22 '15 at 08:18
  • 2
    So is it "Pixate" or "Pirate"? – Pavlo May 22 '15 at 08:19
  • [`nestLayers`](http://www.pixate.com/docs/actions/#nestlayer) takes Layer as parameter, are you sure about the `erg` param ? – Hacketo May 22 '15 at 08:22
  • @Lajos: well, basically it is the last line where the functions stops. As i wrote earlier, the first selected layer will be nested but after that the function stops with "undefined is not a function"... Sorry but there's no better debug in Pixate... – Sandor Rozsa May 26 '15 at 15:15
  • @Lajos Arpad: well, basically it is the last line where the functions stops. As i wrote earlier, the first selected layer will be nested but after that the function stops with "undefined is not a function"... Sorry but there's no better debug in Pixate… Hacketo: – yeah, i think nestLayers should take some parameters. I am trying to get the „elements“ there. Curiously - the alert function is giving them back as expected… Pavlo – Heheh… Good catch. It is my Mac that is writing those funny things :-) „Pixate of the Caribbean“ :-) – Sandor Rozsa May 26 '15 at 15:21

1 Answers1

0

There are two issues with your nestLayers call: it expects all the layers as parameters (not an array), and you were passing an array of strings, not layer objects (see the docs here: http://www.pixate.com/docs/actions/#nestlayer).

The correct action should look like this:

var layers = getSelectedLayers();

var group = createLayer("MyGroup");
group.y = group.x = 0;
group.width = Screen.width;
group.height = Screen.height;
group.backgroundColor = 'transparent';

nestLayers.apply(this, [].concat(group, layers));

apply calls a function with the supplied array as parameters (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply), and I'm just concatenating the group layer and the rest of the layers into a single array.

  • – thanks mate! Your solution is working good. The only problem is that it is handling only "non nested" layers. If the layers you select are not nested, it is working well. If you select "grouped" layers it will crash the application. But I am afraid that checking/respecting a hierarchy of layers would be too complicated – right? – Sandor Rozsa May 28 '15 at 09:33