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

Error while creating a text layer, when 2+ artboards are available in the document

New Here ,
Oct 13, 2015 Oct 13, 2015

Copy link to clipboard

Copied

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!

TOPICS
Actions and scripting

Views

593

Translate

Translate

Report

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 , Nov 13, 2015 Nov 13, 2015

var doc = activeDocument;

var currentArtboard = getActiveArtboard();

function makeTextLayer() {

    var desc = new ActionDescriptor();

    var desc2 = new ActionDescriptor();

    var ref = new ActionReference();

    ref.putClass(app.charIDToTypeID('TxLr'));

    desc.putReference(app.charIDToTypeID('null'), ref);

    desc2.putString(app.charIDToTypeID('Txt '), "text");

    var list2 = new ActionList();

    desc2.putList(app.charIDToTypeID('Txtt'), list2);

    desc.putObject(app.charIDToTypeI

...

Votes

Translate

Translate
Adobe
New Here ,
Nov 13, 2015 Nov 13, 2015

Copy link to clipboard

Copied

I got this error too when I was trying to use the specKing photoshop plug-in for measuring and design specifications plugin ... Bizzaro ... worked like 2 months ago *subscribing*

Votes

Translate

Translate

Report

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
Participant ,
Nov 13, 2015 Nov 13, 2015

Copy link to clipboard

Copied

var doc = activeDocument;

var currentArtboard = getActiveArtboard();

function makeTextLayer() {

    var desc = new ActionDescriptor();

    var desc2 = new ActionDescriptor();

    var ref = new ActionReference();

    ref.putClass(app.charIDToTypeID('TxLr'));

    desc.putReference(app.charIDToTypeID('null'), ref);

    desc2.putString(app.charIDToTypeID('Txt '), "text");

    var list2 = new ActionList();

    desc2.putList(app.charIDToTypeID('Txtt'), list2);

    desc.putObject(app.charIDToTypeID('Usng'), app.charIDToTypeID('TxLr'), desc2);

    executeAction(app.charIDToTypeID('Mk  '), desc, DialogModes.NO);

    return doc.activeLayer

}

var newLayer = makeTextLayer();

newLayer.move(currentArtboard, ElementPlacement.INSIDE);

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 doc

    }

}

Votes

Translate

Translate

Report

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 ,
Nov 15, 2015 Nov 15, 2015

Copy link to clipboard

Copied

LATEST

This is the correct workaround. There is a bug in the current javascript interface to create text layers, I guess.

Votes

Translate

Translate

Report

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