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

Adobe script

Community Beginner ,
Mar 18, 2025 Mar 18, 2025

Hi, I need help to write an Adobe Illustrator script to select the enveloped effect layer and change it's text with data set

TOPICS
Experiment , How-to , Scripting , Type
265
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
Adobe
Community Expert ,
Mar 18, 2025 Mar 18, 2025

Hi @viraj_5116 first let's understand what you have in your document:

 

(A) you have a text frame (or group containing text frame(s), etc) that has a Warp Live Effect on it created via Effects > Warp menu? or

 

(B) you have an envelope object containing containing text frame(s) created via Object > Envelope Distort menu.

 

If the answer is (A) I think you can access the text frame normally via scripting (eg. app.activeDocument.textFrames will collect it).

 

However, If the answer is (B) unfortunately Illustrator's scripting API doesn't support this although there is a hack that can retrieve text frames from inside an envelope but it comes with a significant limitation: that the envelope item must be in "Edit Contents" mode (Object > Envelope Distort > Edit Contents menu) or it won't work. Here is a function that implements the hack:

/**
 * @file Get TextFrames From Envelope.js
 *
 * Demonstration of hack for getting text frame
 * references from inside an envelope (plug in item).
 *
 * NOTE: if necessary the envelope item will be placed
 * in "Edit contents" mode by the script.
 *
 * @author m1b
 * @version 2025-03-19
 */
(function () {

    var doc = app.activeDocument,
        item = doc.selection[0];

    var textFrames = textFramesInEnvelope(doc, item);

    alert(textFrames.length + ' text frames found in envelope.');

})();

/**
 * Returns text frames found in the given envelope.
 * Note: we create a temporary text frame, because
 * when the only story in the document is inside
 * an envelope, it won't appear in doc.stories,
 * but when there are two stories they both appear.
 * @version 2023-12-17
 * @param {Document} doc - an Illustrator Document.
 * @param {PluginItem} envelope - an envelope.
 * @returns {Array<TextFrame>}
 */
function textFramesInEnvelope(doc, envelope) {

    var frames = [],
        tempFrame = doc.textFrames.add(),
        stories = doc.stories;

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

        var story = stories[i],
            frame = story.textFrames[0],
            parent = getEnvelopeForItem(frame);

        if (undefined == parent)
            continue;

        if (parent === envelope)
            frames.push(frame);
    }

    tempFrame.remove();

    return frames;

};

/**
 * Returns the envelope item, given a child
 * page item, eg. a text frame inside an envelope.
 * Will return nothing if no envelope found.
 * Note: Illustrator throws error when asking
 * for the parent of an envelope's item while
 * the envelope is in "edit envelope" mode.
 * @version 2023-12-17
 * @param {PageItem} item - the item inside an envelope.
 * @returns {PluginItem}
 */
function getEnvelopeForItem(item) {

    switch (item.typename) {

        case 'PluginItem':
            return item;

        case 'Layer':
        case 'Document':
            return;

        default:
            try {
                return getEnvelopeForItem(item.parent);
            } catch (error) {
                doActionFromString(
                    'Toggle Edit Envelope',
                    'Temp',
                    '/version 3 /name [ 4 54656d70 ] /isOpen 1 /actionCount 1 /action-1 { /name [ 20 546f67676c65204564697420456e76656c6f7065 ] /keyIndex 0 /colorIndex 0 /isOpen 0 /eventCount 1 /event-1 { /useRulersIn1stQuadrant 0 /internalName (ai_plugin_envelope) /localizedName [ 8 456e76656c6f7065 ] /isOpen 1 /isOn 1 /hasDialog 0 /parameterCount 1 /parameter-1 { /key 1835363957 /showInPalette 4294967295 /type (enumerated) /name [ 20 546f67676c65204564697420436f6e74656e7473 ] /value 3 } } }'
                );
                try {
                    return getEnvelopeForItem(item.parent);
                } catch (error) {
                    return alert('getEnvelopeForItem: envelope item must be in "edit contents" mode.');
                }
            }

    };

};

/**
* Create and execute an action using the parameters supplied.
* The action file and action will be removed afterwards.
* @author Charu Rajput
* @version 2022-08-13
* @discussion https://community.adobe.com/t5/illustrator-discussions/quot-duplicate-layer-quot-command-in-script/m-p/13131761
* 
* @param {String} actionName - the action name (must match the name encoded in the markup).
* @param {String} actionSetName - the action set name (must match the name encoded in the markup).
* @param {String} markup - the action markup.
*/
function doActionFromString(actionName, actionSetName, markup) {

    var tmp = File(Folder.temp + '/' + actionSetName + '.aia');
    tmp.open('w');
    tmp.write(markup);
    tmp.close();
    app.loadAction(tmp);
    app.doScript(actionName, actionSetName, false);
    app.unloadAction(actionSetName, '');
    tmp.remove();

};

Edit 2025-03-19: added `doActionFromString` by Charu Rajput and I made an action that invoked the toggle Envelope Edit menu which is executed in the case where the first attempt fails.

 

If you still need more help, please post an example document (save as pdf with illustrator compatibility for this forum) along with a description of exactly what you want.

- Mark

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
Community Beginner ,
Mar 19, 2025 Mar 19, 2025

Hey @m1b 

Thanks so much for getting back to me!
This script is fantastic!

I was wondering if it’s possible to add a double-click trigger on the enveloped layer through a script?

Thanks again!

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
Community Expert ,
Mar 19, 2025 Mar 19, 2025

@viraj_5116 Yes, good idea! I made an action that does the toggle and the script will now run it if the first attempt fails. It works in my simple test, but you should try it out. I've updated the script above.

- Mark

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
Community Beginner ,
Mar 20, 2025 Mar 20, 2025
LATEST

Hey @m1b 
Will this be achievable from the script?

  • Select an "Envelope effect" layer.

  • Make it isolated.

  • Select a text layer.

  • Make it dynamic text in a variable with the imported .csv.

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