• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

get Pattern ID

Explorer ,
Mar 01, 2019 Mar 01, 2019

Copy link to clipboard

Copied

Hi,

is there a way to retrieve the ID of a pattern besides the name?

function getAllPatterns() {

    var ref = new ActionReference();

    ref.putEnumerated(cTID("capp"), cTID("Ordn"), cTID("Trgt"));

    var desc = executeActionGet(ref);

    var List = desc.getList(sTID('presetManager'));

    var patterns = [];

    var list = List.getObjectValue(4).getList(charIDToTypeID('Nm  '));

    for (var i = 0; i < list.count; i++) {

        var str = list.getString(i);

        // $.writeln('str: ' + str);

        patterns.push(str);

    }

    return patterns;

};

getAllPatterns();

Kind Regards

Joe

TOPICS
Actions and scripting

Views

1.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Guide , Mar 01, 2019 Mar 01, 2019

You can get them from the pat files I.E.

var patFolder = Folder("/C/Program Files/Adobe/Adobe Photoshop CS6 (64 Bit)/Presets/Patterns");

var pattern = patFolder.getFiles( "*.pat")[0];

alert(getPatterns(pattern).join("\n"));

function getPatterns(file){

  file.open("r");

  file.encoding = 'BINARY';

  var str = file.read();

  file.close();

  var patterns=[];

  //Thanks to X for the regex

  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

...

Votes

Translate

Translate
Engaged , Mar 01, 2019 Mar 01, 2019

QQ截图20190302145157.png

if (app.documents.length > 0) {

var ref = new ActionReference();

//ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("layerEffects"));

ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

var layerDesc = executeActionGet(ref);

var layerDesc = layerDesc.getObjectValue(stringIDToTypeID("currentToolOptions"));  

layerDesc = layerDesc.getObjectValue(stringIDToTypeID("pattern"));       

checkDesc2 (layerDesc);

};

//////

////// based on code by michael

...

Votes

Translate

Translate
Adobe
Guide ,
Mar 01, 2019 Mar 01, 2019

Copy link to clipboard

Copied

You can get them from the pat files I.E.

var patFolder = Folder("/C/Program Files/Adobe/Adobe Photoshop CS6 (64 Bit)/Presets/Patterns");

var pattern = patFolder.getFiles( "*.pat")[0];

alert(getPatterns(pattern).join("\n"));

function getPatterns(file){

  file.open("r");

  file.encoding = 'BINARY';

  var str = file.read();

  file.close();

  var patterns=[];

  //Thanks to X for the regex

  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;

};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 01, 2019 Mar 01, 2019

Copy link to clipboard

Copied

Thanks SuperMerlin​,

there is no way to get the ID's of all loaded patterns?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Mar 01, 2019 Mar 01, 2019

Copy link to clipboard

Copied

Not that I know of.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 01, 2019 Mar 01, 2019

Copy link to clipboard

Copied

QQ截图20190302145157.png

if (app.documents.length > 0) {

var ref = new ActionReference();

//ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("layerEffects"));

ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

var layerDesc = executeActionGet(ref);

var layerDesc = layerDesc.getObjectValue(stringIDToTypeID("currentToolOptions"));  

layerDesc = layerDesc.getObjectValue(stringIDToTypeID("pattern"));       

checkDesc2 (layerDesc);

};

//////

////// based on code by michael l hale //////

function checkDesc2 (theDesc) {

var c = theDesc.count;

var str = '';

for(var i=0;i<c;i++){ //enumerate descriptor's keys

  str = str + 'Key '+i+' = '+typeIDToStringID(theDesc.getKey(i))+'/'+typeIDToCharID(theDesc.getKey(i))+': '+theDesc.getType(theDesc.getKey(i))+':'+getValues (theDesc, i)+'\n';

  };

alert("desc\n\n"+str);

logInfo(str);

};

////// check //////

function getValues (theDesc, theNumber) {

   

        var key = theDesc.getKey(theNumber); 

        var type = theDesc.getType(key); 

           

switch (type) {

case DescValueType.ALIASTYPE:

return theDesc.getPath(key);

break;

case DescValueType.BOOLEANTYPE:

return theDesc.getBoolean(key);

break;

case DescValueType.CLASSTYPE:

return theDesc.getClass(key);

break;

case DescValueType.DOUBLETYPE:

return theDesc.getDouble(key);

break;

case DescValueType.ENUMERATEDTYPE:

return (typeIDToStringID(theDesc.getEnumerationValue(key))+"_"+typeIDToCharID(theDesc.getEnumerationType(key)));

break;

case DescValueType.INTEGERTYPE:

return theDesc.getInteger(key);

break;

case DescValueType.LISTTYPE:

return theDesc.getList(key);

break;

case DescValueType.OBJECTTYPE:

return (theDesc.getObjectValue(key)+"_"+typeIDToStringID(theDesc.getObjectType(key))+"_"+typeIDToCharID(theDesc.getObjectType(key)));

break;

case DescValueType.RAWTYPE:

//return theDesc.getReference(theDesc.getData(theNumber));

break;

case DescValueType.REFERENCETYPE:

return theDesc.getReference(key);

break;

case DescValueType.STRINGTYPE:

return theDesc.getString(key);

break;

case DescValueType.UNITDOUBLE:

return (theDesc.getUnitDoubleValue(key)+"_"+typeIDToStringID(theDesc.getUnitDoubleType(key))+"_"+typeIDToCharID(theDesc.getUnitDoubleType(key)));

break;

default: val =  theDesc.getType(key).toString();

break;

};

};

function logInfo(Txt){ 

var file = new File(Folder.desktop + "/style2.txt"); 

file.open("w", "TEXT", "????"); 

file.seek(0,2); 

$.os.search(/windows/i)  != -1 ? file.lineFeed = 'windows'  : file.lineFeed = 'macintosh'; 

file.writeln(Txt); 

file.close(); 

};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Mar 02, 2019 Mar 02, 2019

Copy link to clipboard

Copied

The pattern can be set in the pattern adjustment layer using only the pattern name, and then you can read the ID from this pattern adjustment layer.

And why do you need it?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 02, 2019 Mar 02, 2019

Copy link to clipboard

Copied

LATEST

I first tried the name, but there were problems with the included  patterns.

For the supplied pattern would be another approach necessary as self-created. Thats my Problem

function createPatternFill(name, scale) {

  try {

  //does not work because the name is localized

  // alert(localize("$$$/Presets/Patterns/" + name));


  //included  Pattern
  //German Version
  alert(localize("$$$/Presets/Patterns/" + "Rechts-diagonale Linie 1"));

  var desc1 = new ActionDescriptor();
  var ref = new ActionReference();
  ref.putClass( sTID('contentLayer') );
  desc1.putReference( cTID('null'), ref );
  var desc2 = new ActionDescriptor();
  var desc3 = new ActionDescriptor();
  desc3.putUnitDouble( cTID('Scl '), cTID('#Prc'), scale );
  var desc4 = new ActionDescriptor();

  //included  Patterns
  desc4.putString( cTID('Nm '), localize("$$$/Presets/Patterns/" + name) );

    //for all others
  desc4.putString( cTID('Nm ')name );


  // desc4.putString( cTID('Idnt'), "bf565312-67b6-1177-9181-9d5762aa7056" );
  desc3.putObject( cTID('Ptrn'), cTID('Ptrn'), desc4 );
  desc2.putObject( cTID('Type'), sTID('patternLayer'), desc3 );
  desc1.putObject( cTID('Usng'), sTID('contentLayer'), desc2 );
  executeAction( cTID('Mk '), desc1, DialogModes.NO );
  }

  catch (e){

  alert(e + "\n" + e.line);
  }

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines