4 Replies Latest reply on Sep 24, 2014 4:29 AM by Sakari Niittyma

    Is there a way to select all text objects containing specified character?

    zawij

      Is there a way to select all text objects containing specified character?

       

      For instance,

      My artwork consists of dots and numbers.

      Dots are on separated text frames, so are numbers.

       

      I would like to select all dots, so I can group them.

      Or numbers, and group them.

       

      Screen Shot 2014-09-23 at 14.48.52.png

        • 1. Re: Is there a way to select all text objects containing specified character?
          CarlosCanto Adobe Community Professional & MVP

          yes,

          - loop thru all text items

          - get each contents

          - compare to "."

          - if matching, save a reference to that text frame

          - when done with all frames

          - loop thru all saved references and move to a group

          • 2. Re: Is there a way to select all text objects containing specified character?
            zawij Level 1

            Thanks, probably you are right, but

            in fact I never started scripting in Illustrator and I am not able to write it myself..

             

            So the question should be posted as: Do anyone has a script...

            • 3. Re: Is there a way to select all text objects containing specified character?
              CarlosCanto Adobe Community Professional & MVP

              I see, it is unlikely there is a ready made script for such particular need...One would need to be written. If time permits, some of us contributors might give it a try.

              • 4. Re: Re: Is there a way to select all text objects containing specified character?
                Sakari Niittyma Level 1

                I'm still quite new with this whole scripting, but I wrote simple script for this. Just copy&paste it from here or download it from here Dropbox - TextSearchSelection.jsx

                Hope it helps!

                 

                // Text Search Selection
                //
                // JavaScript Script for Adobe Illustrator CC 2014
                // Tested with Adobe Illustrator CC 2014, Windows 7 64-bit.
                // This script provided "as is" without warranty of any kind.
                // Free to use and distribute.
                //
                // Copyright(c) 2014 Sakari Niittymaa
                // http://www.niittymaa.com
                //
                // 2014-09-24
                
                
                #target illustrator
                
                
                if (app.documents.length > 0) {
                    
                var script_name = "Text Search Selection"
                var doc = app.activeDocument;
                var find_char;
                
                
                // Loop all items
                function getTextItems (item) {
                
                
                    for (var i=0; i < item.length; i++) {
                        
                        if (item[i].groupItems) {
                            
                            getTextItems (item[i].groupItems);
                            getTextItems (item[i].textFrames);
                            
                        } else if (item[i].typename == "TextFrame") {
                            
                            // Set selection
                            item[i].selected = findCharacter (item[i].contents);            
                        }
                    }
                }
                
                
                // Parse selected text item
                function findCharacter( item ) {
                    
                    var char_found = false;
                    
                    // Parse selected string characters
                    for (var i=0; i < item.length; i++) {
                        
                        // Mark character found if there is same character in text item
                        if ( item[i].toLowerCase() == find_char.toLowerCase() ) {
                            char_found = true;
                        }
                    }
                    
                    // If character found return true value for selection
                    if (char_found) {
                        return true;
                    } else { return false }
                }
                
                
                // GUI
                startGUI();
                function startGUI() {
                    
                    // Create Main Window
                    var win = new Window( "dialog", script_name, undefined );
                    
                    // Style for Main Window
                    win.orientation = "column";
                    win.alignChildren = ["fill", "fill"];
                    
                    // Style for Search group
                    var searchGrp = win.add("panel", undefined, "Find Character");
                    searchGrp.orientation = "column";
                    searchGrp.alignChildren = ["fill", "fill"];
                    
                    var titleMsg = searchGrp.add ("statictext", undefined, "Select all text items with this character:");
                    var singleChar = searchGrp.add("edittext { characters: 1, justify: 'center', active: true }");
                    singleChar.helpTip = "Enter single character";
                    
                    // Listener for the find button
                    singleChar.onChanging = function() {
                        if (singleChar.text.length > 1) { singleChar.text = ""; };
                        app.executeMenuCommand ('selectall');
                        find_char = singleChar.text;
                        getTextItems ( doc.selection  );
                        app.redraw();
                    }
                
                    // Style for Extra
                    var extraGrp = win.add("panel", undefined, "Extra");
                    extraGrp.orientation = "column";
                    extraGrp.alignChildren = ["fill", "fill"];
                
                    // Button: Edges
                    var btnEdges = extraGrp.add('button', undefined, "Edges");
                    btnEdges.helpTip = "Show/Hide Edges";
                    btnEdges.onClick = function () { 
                        app.executeMenuCommand ('edge'); app.redraw(); 
                    };
                    
                    // Button: Bounding Box
                    var btnBoundingBox = extraGrp.add('button', undefined, "Bounding Box");
                    btnBoundingBox.helpTip = "Show/Hide Bounding Box";
                    btnBoundingBox.onClick = function () { 
                        app.executeMenuCommand ('AI Bounding Box Toggle'); 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(); 
                }
                } else {
                    alert("You do not have any document opened!");
                }