Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Problem creating sublayer ("not a function")

New Here ,
May 21, 2016 May 21, 2016

Hello. I came up with an ideia of a script to read a set of data and use it to manipulate objects inside AI. The data is a simple table with several key:values, one which is the identifier of a "row set". I stored these values in an Array of Objects, where each Object is a row.

First I wanted to create a layer strucuture, where 1) each key of these data Objects would create a sub layer inside a main layer. 2) each value of a key would create a sub layer inside the previous created key sub layer. For now I am bypassing the problem of duplication, because the object will share several keys and values, and I don't want duplicates of those.

At the moment I can't complete the task (2) coz of the error: "parent.add(); is not a function". Can't find out why, but I must declare that my programming skills are low. Hope you can help me out on this

var doc = app.activeDocument;

var layerPrincipal=doc.layers.getByName("RES");

var subLayers=layerPrincipal.layers;

//loteObj's are omitted for brevity.

var lotesArrCom=[loteObj1,loteObj2];

//Snipped that from the forum.

function doesLayerExist(layers, name) {

  for (i=0; i<layers.length; i++) {

  if (layers.name==name) return true;

  }

  return false;

}

//Snipped that from the forum.

function createLayer(parent,nome){

  var lay = parent.add();

  lay.name = nome;

}

//Loop trough an Array of Objects storing pairs of data.

for(var i=0;i<lotesArrRes.length;i++){

  var loteObj=lotesArrRes;

  for (var key in loteObj) {

  if (loteObj.hasOwnProperty(key)&&key!="nome") {

  var keyValue=loteObj[key];

  if(!doesLayerExist(subLayers, key)){

  createLayer(subLayers,key){

  var keyValue=loteObj[key];

  var sLayers=subLayers.getByName(key);

  //It seems to stuck here. The previous function is executed as expected, but the following triggers the error in the 'CreateLayer' function declaration that "parent.add(); is not a function".

  createLayer(sLayers,keyValue){

  }

  }

 

TOPICS
Scripting
546
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Participant , May 22, 2016 May 22, 2016

In the first case, you call "createLayer (subLayers, key);" - Where subLayers = object [Layers], in the second case where you call "createLayer (sLayers, keyValue);" - Where sLayers = object [Layer] and layer property "add ()" is not available.

I.e in the first case, you call "createLayer (doc.layers.getByName (" RES "). Layers, key)", in the second case, you call "createLayer ( doc.layers.getByName (" RES "). Layers.getByName (key), keyValue) "- but in this case you forgot to add ".layers " - "c

...
Translate
Adobe
Participant ,
May 22, 2016 May 22, 2016

In the first case, you call "createLayer (subLayers, key);" - Where subLayers = object [Layers], in the second case where you call "createLayer (sLayers, keyValue);" - Where sLayers = object [Layer] and layer property "add ()" is not available.

I.e in the first case, you call "createLayer (doc.layers.getByName (" RES "). Layers, key)", in the second case, you call "createLayer ( doc.layers.getByName (" RES "). Layers.getByName (key), keyValue) "- but in this case you forgot to add ".layers " - "createLayer(

doc.layers.getByName ( "RES") layers.getByName (key) .layers)"..

//It seems to stuck here. The previous function is executed as expected, but the following triggers the error in the 'CreateLayer' function declaration that "parent.add(); is not a function". 

createLayer( sLayers.layers, keyValue );

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 22, 2016 May 22, 2016
LATEST

Well... Little ashamed for this. Thank you

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines