Skip to main content
Participant
March 26, 2008
Question

batch pattern creation and naming

  • March 26, 2008
  • 3 replies
  • 1279 views
hello. first of all I apologize if this forum is not the right place to ask, but I suspect what I want to do involves a script, so I thought I'd ask here even if I'm completely ignorant in this matter.

I have a folder with many, many small pattern images in png format, which I want to convert to patterns in photoshop. I have created a "define pattern" action, and then I have run the folder via "automate". but of course, the pattern swatches get all the same name, the name I specified for the pattern I made while recording the action. So, my question is, is there a way to assign the file name to each pattern? I really have no idea what to try..

If anyone can come up with a way to do this, I'd really appreciate it, because renaming every single pattern would probably take me hours..

thanks in advance for any help

cristina
This topic has been closed for replies.

3 replies

Participant
March 27, 2008
I hadn't thought calling a script could be recorded into an action! Well thanks a lot Herb, it works great! you saved me a ton of work :)

I think when I have time I'll have to look into learning some scripting.. It looks incredibly useful!

cristina
Participant
March 27, 2008
Thanks a lot for your reply, Herb. However, as I said this is my first time dealing with scripts and I'm not sure I understand how they work. What I did is save the text to a file named "DefinePattern.jsx", and then run it via scripts, browse, etc., on an open document. But I get an error:

Error 1220: Illegal Argument
Line: 8
> var id18 = charIDToTypeID( "Mk " );

do you know what could be wrong?

and second question.. even if this worked, I assume I have to apply the script to an open document at a time, right? Would there be a way to further automate the process in order to apply this to a whole folder of documents at once?

thanks again for you help. :)

cristina
Known Participant
March 27, 2008
cristina_garcia@adobeforums.com schrieb:

> But I get an error:
>
> Error 1220: Illegal Argument Line: 8
>
> var id18 = charIDToTypeID( "Mk " );

Seems to be a problem with how the web forum works. Originally, there
had been two blanks in "Mk ", one of them got lost. Explanation is that
each argument to charIDToTypeID is required to hold exactly four
characters. So you should add a second blank to "Mk ". Same is true for
line 25 where "Nm " should be padded with another trailing space
character to a total length of four.

Sorry for the inconvenience... had not been aware of this issue.

> and second question.. even if this worked, I assume I have to apply
> the script to an open document at a time, right?

Jepp. This is done like your initial approach. Record an action which
calls the script (and maybe close the image after that). Then use
Automate > Batch.. as you did before, with the new action.

Herb
Known Participant
March 26, 2008
Hello Cristina.

This is perfectly the right place to ask, I think. The following is a
script to call in your action instead of the built-in menu item "define
pattern". What it does is to get the filename from the active document
and hand it to a "define pattern" call recorded with ScriptListener.

Herb


// DefinePattern.jsx
#target photoshop

function definePattern(patternName)
{
// ScriptListener output with only pattern name replaced
// =======================================================
var id18 = charIDToTypeID( "Mk " );
var desc3 = new ActionDescriptor();
var id19 = charIDToTypeID( "null" );
var ref1 = new ActionReference();
var id20 = charIDToTypeID( "Ptrn" );
ref1.putClass( id20 );
desc3.putReference( id19, ref1 );
var id21 = charIDToTypeID( "Usng" );
var ref2 = new ActionReference();
var id22 = charIDToTypeID( "Prpr" );
var id23 = charIDToTypeID( "fsel" );
ref2.putProperty( id22, id23 );
var id24 = charIDToTypeID( "Dcmn" );
var id25 = charIDToTypeID( "Ordn" );
var id26 = charIDToTypeID( "Trgt" );
ref2.putEnumerated( id24, id25, id26 );
desc3.putReference( id21, ref2 );
var id27 = charIDToTypeID( "Nm " );
desc3.putString( id27, patternName );
executeAction( id18, desc3, DialogModes.NO );
}

var doc = app.activeDocument;
definePattern(doc.name);
leannefriedberg
Participant
July 22, 2024

this is golden!

It does leave all the files from the batch open.  Is there a way to include a "close file" into the script?  I am NOT a programmer, sorry if it's obvious.

Stephen Marsh
Community Expert
Community Expert
July 22, 2024

@leannefriedberg wrote:

this is golden!

It does leave all the files from the batch open.  Is there a way to include a "close file" into the script?  I am NOT a programmer, sorry if it's obvious.



That can be done, presuming that you have added a save as step into the action:

 

app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

 

However, you can just as easily include the close step in the action without scripting it.