fill with auto creat pattern and fill pattern script
Copy link to clipboard
Copied
Hello guys, I need a bit of help to automate my work.
I work with patterns (as a pattern designer), but I need to slightly automate my work.
There is this great function now "fill with ... pattern" and then you have scripts for those.
This said what I usually do is that I wokr on a couple of patterns, make the design then test test them on a big format blank file.
so
1. I do my drawing, then
2. click "define as a new pattern" and then
3. I open a fresh new fbig big file and
4. use "fill it with... pattern" and
5. select the last one I created...
So I tried to create an action / script so that I could you know, work in batches, having to decide which of the patterns are good on a big format only later.
AND HERE COMES THE BUG!
When I Added exactly the same steps in the actions macro - it will work for the first file, but for the second it will still use the same pattern used previously, as the actions macro sees it as "fill it with pattern XXX" (namely, not as "last one used"), so I land up with all of the pictures in big format filled with the same pattern instead of different ones.
I was thinking about then modifying the macro so when I g oto step 4
4. use "fill it with... pattern" and
add " use script" among the scripts loading there, that would define something like "use the last pattern defined" - can be as well a code as "use newest pattern defined" or "use newest pattern added to the lot"
I understand the logic but I have no clue how to edit the scripts in this area.
This will save me hours of work, so all of your help will be more than appreciated.
Explore related tutorials & articles
Copy link to clipboard
Copied
#target photoshop;
main();
function main(){
if(!documents.length) return;
var patt = new File(Folder.temp + "/tempPatterns");
if(patt.exists) patt.remove();
savePatterns(patt);
var patterns = getPatternsFromFile(patt);
fillPattern(patterns[patterns.length-1][0].toString(),patterns[patterns.length-1][1].toString(), 100);
};
function savePatterns(file) {
var desc625 = new ActionDescriptor();
desc625.putPath( charIDToTypeID('null'), new File( file ) );
var ref462 = new ActionReference();
ref462.putProperty( charIDToTypeID('Prpr'), charIDToTypeID('Ptrn') );
ref462.putEnumerated( charIDToTypeID('capp'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
desc625.putReference( charIDToTypeID('T '), ref462 );
executeAction( charIDToTypeID('setd'), desc625, DialogModes.NO );
};
function getPatternsFromFile(file){
file.open("r");
file.encoding = 'BINARY';
var str = file.read();
file.close();
var patterns=[];
var re = /(\x00\w|\x00\d)(\x00\-|\x00\w|\x00\s|\x00\d)+\x00\x00\$[-a-z\d]+/g;
var parts = str.match(re);
for (var i = 0; i < parts.length; i++) {
var p = parts;
var sp = p.replace(/\x00/g, '').split('$');
patterns.push([[sp[0]], [sp[1]]]);
}
return patterns;
};
function fillPattern(name, id, opacity) {
var desc6 = new ActionDescriptor();
desc6.putEnumerated( charIDToTypeID('Usng'), charIDToTypeID('FlCn'), charIDToTypeID('Ptrn') );
var desc7 = new ActionDescriptor();
desc7.putString( charIDToTypeID('Nm '), name );
desc7.putString( charIDToTypeID('Idnt'), id);
desc6.putObject( charIDToTypeID('Ptrn'), charIDToTypeID('Ptrn'), desc7 );
desc6.putUnitDouble( charIDToTypeID('Opct'), charIDToTypeID('#Prc'), opacity );
desc6.putEnumerated( charIDToTypeID('Md '), charIDToTypeID('BlnM'), charIDToTypeID('Nrml') );
try{
executeAction( charIDToTypeID('Fl '), desc6, DialogModes.NO );
}catch(e){}
};
Copy link to clipboard
Copied
I found this script but it doesn't work
Copy link to clipboard
Copied
AND HERE COMES THE BUG!
What bug?
Please post a screenshot of the fully expanded Action in the Actions Panel.
Why do you use whatever you mean by »"fill with ... pattern"« instead of creating a Pattern Fill Layer?
Are you using Scripted Patterns?
Please post screenshots to illustrate what exactly you are doing.
Copy link to clipboard
Copied
NO, sir. THis is not write way.
When I Added exactly the same steps in the actions macro - it will work for the first file, but for the second it will still use the same pattern used previously, as the actions macro sees it as "fill it with pattern XXX" (namely, not as "last one used"), so I land up with all of the pictures in big format filled with the same pattern instead of different ones.
Copy link to clipboard
Copied
If you record using Pattern X then the Action uses Pattern X when played again – that would obviously not be a bug.
Please post the requested screenshots and explain what your process is exactly.
How are you filling the larger image with the pattern exactly?
Edit:
// create pattern layer with last pattern;
// 2023, use it at your own risk;
if (app.documents.length > 0) {
try {
var ref = new ActionReference();
ref.putProperty(stringIDToTypeID ("property"), stringIDToTypeID("presetManager") );
ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var applicationDesc = executeActionGet(ref);
var presetManager = applicationDesc.getList(stringIDToTypeID("presetManager"));
var patternNames = presetManager.getObjectValue(4).getList(stringIDToTypeID("name"));
var theNames = new Array;
for (m = 0; m < patternNames.count; m++) {
theNames.push(patternNames.getString(m))
};
makePatternLayer (theNames[theNames.length-1], 100);
} catch (e) {};
};
////// make pattern layer //////
function makePatternLayer (thePatternName, theScale) {
// =======================================================
var idMk = charIDToTypeID( "Mk " );
var desc3 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref1 = new ActionReference();
var idcontentLayer = stringIDToTypeID( "contentLayer" );
ref1.putClass( idcontentLayer );
desc3.putReference( idnull, ref1 );
var idUsng = charIDToTypeID( "Usng" );
var desc4 = new ActionDescriptor();
var idType = charIDToTypeID( "Type" );
var desc5 = new ActionDescriptor();
var idScl = charIDToTypeID( "Scl " );
var idPrc = charIDToTypeID( "#Prc" );
desc5.putUnitDouble( idScl, idPrc, theScale );
var idPtrn = charIDToTypeID( "Ptrn" );
var desc6 = new ActionDescriptor();
var idNm = charIDToTypeID( "Nm " );
desc6.putString( idNm, "rust400x400" );
var idIdnt = charIDToTypeID( "Nm " );
desc6.putString( idIdnt, thePatternName );
var idPtrn = charIDToTypeID( "Ptrn" );
desc5.putObject( idPtrn, idPtrn, desc6 );
var idpatternLayer = stringIDToTypeID( "patternLayer" );
desc4.putObject( idType, idpatternLayer, desc5 );
var idcontentLayer = stringIDToTypeID( "contentLayer" );
desc3.putObject( idUsng, idcontentLayer, desc4 );
executeAction( idMk, desc3, DialogModes.NO );
return app.activeDocument.activeLayer
};
Copy link to clipboard
Copied
Copy link to clipboard
Copied
When you record a specific Pattern in an Action, then that’s the recorded one.
Calling that a »bug« seems like an obvious misuse of the word.
And you do use »Brick Fill« Scripted Patterns.
I am not sure if that can be recorded in a Script, but if it can be recorded in an Action it should also be recordable with ScriptingListener.plugin
So if you don’t have that yet please download it and do that!
Copy link to clipboard
Copied
I did that scriptingListener. but it doesn't work
Copy link to clipboard
Copied
Is there any other alternative?
Copy link to clipboard
Copied
How important is the Scripted Pattern?
Could a plain Pattern Layer suffice?
Does ScriptingListener.plugin record no code for the Fill at all?
Copy link to clipboard
Copied
Can you give me a script that will get my work done?
Copy link to clipboard
Copied
Can you answer my questions?
Copy link to clipboard
Copied
I did that scriptingListener. but it doesn't work
Brick Fill seems to record just fine with SriptingListener.plugin (see screenshot).
Please explain what you have been doing and show the code you got.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
By MJ ST
What is that post supposed to illustrate?
Copy link to clipboard
Copied
Please answer questions properly.
Anyway, the operation appears to have recorded just fine so what is the problem?
You are aware you should to wrap that code into a function that takes the Pattern’s name as an argument?
If the Patterns all have unique names I would just ignore the ID.
// =======================================================
var idFl = charIDToTypeID( "Fl " );
var desc246 = new ActionDescriptor();
var idUsng = charIDToTypeID( "Usng" );
var idFlCn = charIDToTypeID( "FlCn" );
var idPtrn = charIDToTypeID( "Ptrn" );
desc246.putEnumerated( idUsng, idFlCn, idPtrn );
var idPtrn = charIDToTypeID( "Ptrn" );
var desc247 = new ActionDescriptor();
var idNm = charIDToTypeID( "Nm " );
desc247.putString( idNm, """dreamstime_xxl_219662609.jpg""" );
var idIdnt = charIDToTypeID( "Idnt" );
desc247.putString( idIdnt, """30912de4-6deb-df49-941d-45f55d5f2316""" );
var idPtrn = charIDToTypeID( "Ptrn" );
desc246.putObject( idPtrn, idPtrn, desc247 );
var idOpct = charIDToTypeID( "Opct" );
var idPrc = charIDToTypeID( "#Prc" );
desc246.putUnitDouble( idOpct, idPrc, 100.000000 );
var idMd = charIDToTypeID( "Md " );
var idBlnM = charIDToTypeID( "BlnM" );
var idNrml = charIDToTypeID( "Nrml" );
desc246.putEnumerated( idMd, idBlnM, idNrml );
var iddecoScriptFile = stringIDToTypeID( "decoScriptFile" );
desc246.putPath( iddecoScriptFile, new File( "C:\\Program Files\\Adobe\\Adobe Photoshop 2022\\Presets\\deco\\Brick Fill.jsx" ) );
var iddecoScriptParameters = stringIDToTypeID( "decoScriptParameters" );
desc246.putString( iddecoScriptParameters, """({patternScale:1, offset:-100, spacing:0, colorRandomness:0, brightnessRandomness:0, rotateAngle:0})""" );
executeAction( idFl, desc246, DialogModes.NO );
Copy link to clipboard
Copied
sorry sir. my english is weak. please suport me
Copy link to clipboard
Copied
Copy link to clipboard
Copied
By MJ ST
Again a post that essentially signifies nothing.
What code did you use?
And please don’t post screenshots without the pertinent Panels (Toolbar, Layers, Options Bar, …) visible.
Copy link to clipboard
Copied
MJ ST wrote:
sorry sir. my english is weak. please suport me
Then please don’t write in english but your native or preferred tongue and let’s see if auto-translation can do better for this.
You have the code for Scripted Patterns, now you need to bring it into the form you need.
A couple of posts back I posted code that creates a Pattern Layer with the last Pattern, you can adapt that to apply Fill with the Scripted Pattern instead.
Copy link to clipboard
Copied
I don't know how to put the code in the right place
Copy link to clipboard
Copied
I added some code to a previous post – did you copy that already?
There you can dump the original content of the function and replace it with the code for your Brick Fill, feed it the argument »thePatternName« (like in the existing code) and comment out or delete the two lines referring to the ID.
Copy link to clipboard
Copied
yes i copied


-
- 1
- 2