Old Topic: Working with Photoshop Patterns

Discussion of Photoshop Scripting, Photoshop Actions and Photoshop Automation in General

Moderators: Tom, Kukurykus

jay

Old Topic: Working with Photoshop Patterns

Post by jay »

Hello everyone,

From researching the internet and this forum, it looks like the only way to work with Patterns in Photoshop is by using the 'ScriptingListener'. I think this will work but had 2 questions:

1. I just want to verify that the 'scriptingListener' code will always pull the last 'Pattern' added if the ID isn't there? I'm assuming it's safe to add an empty string for the ID? I will be adding the proper name though.

Code: Select allvar idNm = charIDToTypeID( "Nm  " );
        desc10.putString( idNm, "test" );
        var idIdnt = charIDToTypeID( "Idnt" );
        desc10.putString( idIdnt, "" );  // Empty string originally had an ID number


2. Is the only good way to delete 'Patterns' using Mike Hale's code (below) or Xbytor's xtools library? Is there any way to count the amount of Patterns so I wouldn't have to use a 'try' block?


Code: Select allfunction deleteAllPatterns() {
   var go = true;
   while( go ) {
      try{
         var desc = new ActionDescriptor();
            var list = new ActionList();
               var ref = new ActionReference();
               ref.putIndex( charIDToTypeID( "Ptrn" ), 1 );//when a pattern is deleted the others are reindexed
            list.putReference( ref);
         desc.putList( charIDToTypeID( "null" ), list );
         executeAction( charIDToTypeID( "Dlt " ), desc, DialogModes.NO );
      }catch( e ) {
         go = false;
      }
   }
};

I'm mainly working with CS5, but will need this to work for CS4 as well.

Thanks for taking the time to look at my questions.

Jay

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

xbytor

Old Topic: Working with Photoshop Patterns

Post by xbytor »

xtools/xlib/PresetsManager.js has code for this:

Code: Select allvar mgr = PresetsManager.getManager(PresetType.PATTERNS);
while (mgr.count() > 0) {
  mgr.deleteElementAt(0);
}

You can always extract out the bits you need if you don't want to include the entire file.
jay

Old Topic: Working with Photoshop Patterns

Post by jay »

Thank you, Xbytor. I always appreciate your help here, and thanks for your generosity with your code.

Jay