Hi, I have encountered a weird error while trying to generate a new text layer.
When a single artboard is available in the document, the script runs fine and create an empty text layer;
When 2 or more artboards are available in the document, the scripts generates the layer, but it then gets stuck while trying to convert it to a text one. The console says "The layer cannot contain text".
Pasting my code here, with comments.
#target photoshop //this script attempts to create a text layer above the selected layer contained into an artboard. //For some reason, it works on the first available artboard, but not on the other ones. The error is "The layer cannot contain text" //get active PS document var doc = activeDocument; //get active artboard var currentArtboard = getActiveArtboard(); //create new art layer in the current artboard var newLayer = currentArtboard.artLayers.add(); //trying to convert to text layer. Fails when 2+ artboards are available int the document newLayer.name = "test"; newLayer.kind = LayerKind.TEXT; function getActiveArtboard() { var key = false; var l = doc.activeLayer; var p = l.parent; try { while (!key) { doc.activeLayer = p; var ref = new ActionReference(); ref.putEnumerated(charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt')); key = executeActionGet(ref).getBoolean(stringIDToTypeID("artboardEnabled")); if (key) { return p } p = p.parent; } } catch (e) { alert('This layer is not contained within an artboard'); return undefined; } }
Any help is greatly appreciated. Thank you in advance!