是否可以在Adobe illustrator UI中编辑静态文本?例如,我在底部有一个数字,它显示某些事物的进度。我想循环更新以显示进度(X个项目中的X个项目)。

我尝试使用UI创建文本并稍后更新变量,但是由于GUI代码不会再次运行(除非通过事件侦听器),因此无法正常工作。

我也尝试在循环中编辑文本,但是没有内置方法(就像Java中一样)。

我只想知道这是否有可能(仍在学习AI脚本)。如果不可能,那很好,那不是至关重要的,只是一个精巧的功能来显示长/慢循环的进度。

 function startGUI() {
        var inputText, inputNum;

        // Create Main Window
        win = new Window( "dialog", "title", undefined );

        // Enable use of 'Enter' key
        win.addEventListener ("keydown", function(kd) {enter(kd) });

        // Style for Main Window
        win.orientation = "column";
        win.alignChildren = ["fill", "fill"];
        win.preferredSize = [250, 150];

        // Style for group
        var objGrp = win.add("panel", undefined, "group");
        objGrp.orientation = "column";
        objGrp.alignChildren = ["fill", "fill"];

        var titleMsg = objGrp.add ("statictext", undefined, "name:");
        var txt_Input = objGrp.add("edittext { characters: 1, justify: 'center', active: true }");
        txt_Input.helpTip = "";

        var titleMsg = objGrp.add ("statictext", undefined, "Number to start from:");
        var txt_Num = objGrp.add("edittext { characters: 1, justify: 'center' }");
        txt_Num.helpTip = "Object number to start from, other than 1";

        var txt_Count = win.add("statictext", undefined, "Current object: ".concat (itemCount).concat(" out of: ").concat(countTotal));

        // Button
        var objBtn = objGrp.add("button", undefined, "Start");
        objGrp.helpTip = "";
        objGrp.onClick = function() {
            inputText = txt_Input.text;
            inputNum = txt_Num.text;

            start(inputText, inputNum);
            app.redraw();
        }

        // Use Enter key
        function enter(k) {
            if (k.keyName == "Enter") {
                inputText = txt_Input.text;
                inputNum = txt_Num.text;

                start(inputText, inputNum);
                app.redraw();
            }
        }

        // Listener for the input
        txt_Input.onChanging = function() {
            app.redraw();
        }


        // Close button
        var quitBtn = win.add("button", undefined, "Close");
        quitBtn.helpTip = "Press Esc to Close";

        // Event listener for the quit button
        quitBtn.onClick = function() {
            win.close();
        }

        // Centering & Show Window
        win.center();
        win.show();
    }// end startGUI


更新:

#target illustrator

if (app.documents.length > 0) {

    // Update with new script versions
    var alphaLayersFile = "/AlphabatizeLayers-v1.03.jsx";
    var deleteLayersFile = "/DeleteEmptyLayers-v1.00.jsx";

    var dialogName = "Layer Search Selection"
    var doc = app.activeDocument;
    var docLayers = doc.layers;

    var inputText;
    var caseSense = false;
    var exactWord = false;
    var match = false;
    var textSearch = false;
    var itemCount = 0, countTotal;

    // Display GUI
    startGUI();

    // Main Search function
    function searchAll(layers, txt_Count, win) {
        match = false;
        searchLayers(layers, txt_Count, win);

        // When match is found, show dialog
        if (match) {
            alert("Found match!");
            match = false;
        } else {
            alert("No match found.");
            match = false;
        }
    }


    // Recursive loop to search all layers in active document
    function searchLayers ( layers, txt_Count, win ) {
        var input = inputText;
        var length = layers.length;
        var currentLayer ;

        try {
            countTotal = length;
            for (var i = length; i--;) { //var i = length; i--; //var i = 0; i <= length; i++
                currentLayer = layers[i];

                itemCount++;
                txt_Count.text = "Current object: ".concat(itemCount).concat(" out of: ").concat(countTotal);
                win.update();
                $.sleep(1000);

                var locked = currentLayer.locked;
                var visible = currentLayer.visible;

                if (visible == true || locked == false) {
                    searchLayerName(input, currentLayer);

                    // Search for sublayers, page items or group items
                    if (currentLayer.layers) {
                        searchLayers(currentLayer.layers);
                        searchLayers(currentLayer.groupItems);
                        searchLayers(currentLayer.pathItems);
                        searchLayers(currentLayer.compoundPathItems);
                        searchLayers(currentLayer.symbolItems);
                        searchLayers(currentLayer.textFrames);
                    }
                }
            }
        } catch (error) {
            logger (error);
        }
    }// end SearchLayers

    // Search for match between input and layer name
    function searchLayerName( inputText, currentLayer ) {
        try {
            if (inputText) {
                var layerName = "";
                var layerType = currentLayer.typename;
                var searchIndex = -1;
                var exact = false;

                switch (layerType) {
                    default:
                        layerName = currentLayer.name;
                        searchIndex = searchLayer(inputText, layerName);

                        selectLayer(searchIndex, currentLayer, layerType)
                        break;
                    case "SymbolItem":
                        layerName = currentLayer.symbol.name;
                        searchIndex = searchLayer(inputText, layerName);

                        selectLayer(searchIndex, currentLayer, layerType)
                        break;
                    case "TextFrame":
                        layerName = currentLayer.contents;
                        searchIndex = searchLayer(inputText, layerName);

                        selectLayer(searchIndex, currentLayer, layerType)
                        break;
                    case "Layer":
                        layerName = currentLayer.name;
                        searchIndex = searchLayer(inputText, layerName);

                        selectLayer(searchIndex, currentLayer, layerType)
                        break;
                } // end Switch


            } // end inputText
        } catch (error) {
            logger(error);
        }
    } // end Search

    function searchLayer(inputText, layerName) {
        var searchIndex = -1;
        var caseSensitive = caseSense;
        var exact = exactWord;

        //inputText = fixString(inputText);

        if (caseSensitive) {
            searchIndex = layerName.indexOf(inputText) ;
        } else if (exact) {
            if (layerName === inputText) {
                    searchIndex = 0;
            }
        } else {
            searchIndex = layerName.toLowerCase().indexOf(inputText.toLowerCase());
        }

        return searchIndex;
    }

    function selectLayer(searchIndex, currentLayer, layerType) {

        if ( searchIndex != -1 ) {
            if (layerType != "Layer") {
                currentLayer.selected = true;
                match = true;
            } else if (layerType == "Layer") {
                currentLayer.hasSelectedArtwork = true;
                //layer.selected = true;
                match = true;
            }
        }
    } // end selectLayer

    // Display GUI
    function startGUI() {

        // Create Main Window
        var win = new Window( "dialog", dialogName );

        // Style for Main Window
        win.orientation = "column";
        win.alignChildren = ["fill", "fill"];
        //win.preferredSize = [150, 350];

        // Style for Search group
        var searchGrp = win.add("panel", undefined, "Search Layers");
        searchGrp.orientation = "column";
        searchGrp.alignChildren = ["fill", "fill"];

        var titleMsg = searchGrp.add ("statictext", undefined, "Layer name to search:");
        var txt_Input = searchGrp.add("edittext { characters: 1, justify: 'center', active: true }");
        txt_Input.helpTip = "Input letters to search";

        countTotal = docLayers.length;

        txt_Count = win.add("statictext", undefined, "Current object ".concat(itemCount).concat(" out of: ").concat(countTotal));

        // Search Button
        var searchBtn = searchGrp.add("button", undefined, "Search");
        searchBtn.helpTip = "Search from text items";
        searchBtn.onClick = function() {
            inputText = txt_Input.text;
            searchAll(docLayers, txt_Count, win);
            app.redraw();
        }

        // Listener for the input
        txt_Input.onChanging = function() {
            app.redraw();
        }

        // Options
        var optionsGrp = win.add("panel", undefined, "Options");
        optionsGrp.orientation = "row";
        optionsGrp.margins = [10, 15, 10, 6];
        optionsGrp.alignChildren = ["fill", "fill"];

        // Radio button: Case Sensitive
        var rdb_caseSensitive = optionsGrp.add ("radiobutton", undefined, "Match Case");
        rdb_caseSensitive.helpTip = "Case sensitive search";
        rdb_caseSensitive.value = false;

        // Listener: Case Sensitive
        rdb_caseSensitive.onClick = function() {
            caseSense = rdb_caseSensitive.value;
            app.redraw();
        }

        // Radio button: Exact Word
        var rdb_exactWord = optionsGrp.add ("radiobutton", undefined, "Match Exact Word");
        rdb_exactWord.helpTip = "Search exact word";
        rdb_exactWord.value = false;

        // Listener: Exact Word
        rdb_exactWord.onClick = function() {
            exactWord = rdb_exactWord.value;
            app.redraw();
        }

        // Radio button: None
        var chk_none = optionsGrp.add ("radiobutton", undefined, "None");
        chk_none.helpTip = "Use no extra option";
        chk_none.value = false;

        // Radio button: None
        chk_none.onClick = function() {
            exactWord = false;
            caseSense = false;
            //textSearch = chk_textSearch.value;
            app.redraw();
        }

        // Close button
        var quitBtn = win.add("button", undefined, "Close");
        quitBtn.helpTip = "Press Esc to Close";

        // Event listener for the quit button
        quitBtn.onClick = function() {
            win.close();
        }

        // Centering & Show Window
        win.center();
        win.show();
    }// end startGUI

        // Check to see if parent layer is visible
        // Sometimes child layers that inheirit locked/hidden
        // status from parent will return 'undefined' for visibility
        function checkParentVisibility(layer) {
            for(var parent = layer.parent; parent.typename=='Layer'; parent = parent.parent) {
                var pvis = parent.visible;
                if(!pvis) {
                    return false;
                } else {
                    return true;
                }
            }
         }
    }

    function fixString(str) {
        str = str.split("_").join(" ");
        return str;
    }

    // Prints stack trace
    // Note: Don't print error message unless debugging
    function logger(e) {
        var errorMsg = "";

        errorMsg = errorMsg.concat(e.line, "\n", e.message, "\n", e.stack);
        $.writeln(errorMsg);
    }
} else {
        alert("You do not have any document opened!");
}

最佳答案

我建议使用进度条。我在这里使用JSX在Illustrator中为进度条创建了一个演示(以及其他一些演示):https://github.com/iconifyit/illustrator-jsx-demos

如果您对演示有任何疑问,请告诉我,我将尽一切可能澄清。

08-08 03:09