Search code examples
javascriptjsxadobe-illustrator

Show and select all live text on the document in Illustrator?


I'm trying to write a script that unlocks all the layers then goes through all the layers showing and selecting the live text that is in the active document, what I have wrote so far only unlocks the layers. Could anyone help please? Thanks

This is what I have written so far...

// Make script launchable via double-click / CMD + O.
#target illustrator

// Create an object to hold global variables.
var g = {}

// Call main function.
main();

// Destoying global variables.
g = null;

// Main function will call all the usable functions in order.
function main() {
	try{
		// Check if there is an active document of if one needs to be opened.
		OpenFile();
    	// The Variable for the current document that is open.
    	g.activeDoc = app.activeDocument;
    	// Search though all the layers in the document and make sure that they are unlocked and visable.                                               
    	UnlockLayers();
    	// Outline all of the text to make it un-editable
    	OutlineText(g.activeDoc.layers);
   }
   // Catch any errors that the script has thrown.	
catch(e){
    alert( e + " ...An error has risen...")
    }
}

// Make sure that file is accessable and open.
function OpenFile(){
    
    //check if there are any files already open
    if ( app.documents.length == 0 ) {
        
    // If there is not, let the user choose an illustrator file and open that file.
    var fileToOpen = File.openDialog ("Please select illustrator file", "*.ai",false);
        
    // Open the file.
    app.open (File (fileToOpen));
   
    } 
 
}

// Unlock all layers.
function UnlockLayers(){
    // Loop through the docs layers and capture the locked states of each one.
				for ( var i = 0 ; i < app.activeDocument.layers.length; i++ ) {

						// Unlock/Unhide layers here.
						app.activeDocument.layers[i].locked = false;
						app.activeDocument.layers[i].visible = true;
						
				}
    }

// Search through and select all live text.
function OutlineText( objArray ) {   
          for ( var i = 0; i < objArray.length; i++ ) {
  
                    // Record previous value with conditional change.
                    var l = objArray[i].locked;
                    if ( l ) objArray[i].locked = false;
  
                    // Record previous value with conditional change.
                    var v = objArray[i].visible;
                    if ( !v ) objArray[i].visible = true;
          }
}


Solution

  • I've just created an action to run that will run the menu command 'Show Hidden Characters' and that's the way I have found to get around the issue.