Skip to main content
msgox2
Participant
February 2, 2022
Answered

Execute Action in Script

  • February 2, 2022
  • 1 reply
  • 856 views

I have over 4000 single file and all of them are the same layername and group items.

 

As following screenshot, I want to write script and this script opens file and execute action that is recorded by me before. I coded but it has problem. It says this action can not run something like that. 

 

 

Here is my code;

 

var sourceFolder, fileType, targetFile,destFolder, gridLayers,j,materialGridLayer;  
  
// Select the source folder.  
sourceFolder = Folder( '~/Desktop/Icon Pack/Export' );  
  
// If a valid folder is selected  
if ( sourceFolder != null )  
{  
    files = new Array();  
    fileType = ( '*.ai' );  
    
    // Get all files matching the pattern  
    files = sourceFolder.getFiles( fileType );  
   
    if ( files.length > 0 )  
    {  
        for ( i = 0; i < files.length; i++ )  
        {  
         
            sourceDoc = app.open(files[i]); // returns the document object  
            var mainLayers = sourceDoc.layers;
                        
            try
              {
 
                
                sourceDoc.activeLayer = mainLayers.getByName('Ana Ikonlar');    // variant 2

                var aLay = sourceDoc.activeLayer;
             
                var foregroundLayer =aLay.layers.getByName('foreground');

                var groudItemLayer = foregroundLayer.groupItems[0];
                
                groudItemLayer.selected = true;
             
                apps.doScript('actions_script','long_shadow_script');
             
                }
              catch(f)
              {

              }
            sourceDoc.close(SaveOptions.SAVECHANGES);  
        }  
    }  
    else  
    {  
        alert( 'Problem!!!' ); 
    }  
}  
This topic has been closed for replies.
Correct answer CarlosCanto

in addition, you seem to have the doScript arguments switched, it should be doScript ("action name", "set name")

 

change this

app.doScript('actions_script','long_shadow_script');

 

to this

app.doScript('long_shadow_script', 'actions_script');

1 reply

Silly-V
Legend
February 2, 2022

Try by changing this 

apps.doScript

to

app.doScript

 

msgox2
msgox2Author
Participant
February 2, 2022

Thank you, I did it but it says following error;

Object "play action" not available

 

 

The task is

1-Open document

2-Select layer by name "Ana Ikonlar" and groutItem by name "foreground"

3-Play action by name "long_shadow" in "actions_script"

4-Save and close

 

4 steps and I couldn't manage script 😞 

 
CarlosCanto
Community Expert
CarlosCantoCommunity ExpertCorrect answer
Community Expert
February 2, 2022

in addition, you seem to have the doScript arguments switched, it should be doScript ("action name", "set name")

 

change this

app.doScript('actions_script','long_shadow_script');

 

to this

app.doScript('long_shadow_script', 'actions_script');