Copier le lien dans le Presse-papiers
Copié
Recently the issue of full-color brush-tips has been raised yet again and I got to thinking about how to emulate if not a proper brush stroke then at least dabbing.
One tool very few image editors and illustrators seem to be using with any considerable frequency in Photoshop and that is intended to give position is the Count Tool.
So by linking a Script to creating counters it would be possible to create Smart Object instances at manually defined positions without sacrificing a more frequently used tool (like Colour Sampler Tool or Pen Tool).
Depending on the size of the SO this could go fairly speedily or take some time but still …
So if anyone would like to give it a try let me know what your impression is.
One can add the appropriate event in the file »Script Events Manager.xml« and link the Script to the event in Script Events Manager, then clicking with the Count Tool should create a copy of the active Layer (or one of the selected Layers) with randomisation depending on the filename.
// duplicate layer to position of last counter of last count group and remove the counter; // only if one pixel layer is selected; // if "_minXX" and "_maxXX" are part of the layer name scale to between the two numbers; // 2017, use it at your own risk; #target photoshop if (app.documents.length > 0) { activeDocument.suspendHistory ("duplicate", "main ()") }; //////////////////////////////////// ////// main ////// function main () { var myDocument = app.activeDocument; // pixels,; var originalRulerUnits = app.preferences.rulerUnits; app.preferences.rulerUnits = Units.PIXELS // collect layers; var theLayers = smartifyAndGetSelectedLayersIdxEtc(); // get coordinates; var ref = new ActionReference(); ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); var docDesc = executeActionGet(ref); var counter =docDesc.getList(stringIDToTypeID("countClass")); var thePoints = new Array; for (var c = 0; c < counter.count; c++) { var thisOne = counter.getObjectValue(c); thePoints.push([thisOne.getUnitDoubleValue(stringIDToTypeID("x")), thisOne.getUnitDoubleValue(stringIDToTypeID("y")), thisOne.getUnitDoubleValue(stringIDToTypeID("group")), thisOne.getUnitDoubleValue(stringIDToTypeID("itemIndex"))]) }; // duplicate to last point; if (counter.count > 0) { var theIndex = 0; // chose a layer if more than one are selected; if (theLayers.length > 1) { theIndex = Math.floor((theLayers.length)*Math.random()); }; // get numbers; var theMinRegExp = new RegExp(/_min[0-9]*/i); var theMaxRegExp = new RegExp(/_max[0-9]*/i); var theAngRegExp = new RegExp(/_ang[0-9]*/i); // set range; var theMin = theLayers[theIndex][5].match(theMinRegExp); var theMax = theLayers[theIndex][5].match(theMaxRegExp); var theAng = theLayers[theIndex][5].match(theAngRegExp); if (theMin != null && theMax != null) { var random = Math.random(); var theScale = random*(Number(String(theMax).slice(4))-Number(String(theMin).slice(4)))+Number(String(theMin).slice(4)); } else {var theScale = 100}; if (theAng != null) { var random = Math.random()-0.5; var theAngle = random*(Number(String(theAng).slice(4))); } else {var theAngle = 0}; layerDuplicateOffsetScaleRotate (theLayers[theIndex][0], thePoints[thePoints.length - 1][0] - theLayers[theIndex][1], thePoints[thePoints.length - 1][1] - theLayers[theIndex][2], theScale, theScale, theAngle) // move to top; if (theLayers.length > 1) { // ======================================================= var idmove = charIDToTypeID( "move" ); var desc6 = new ActionDescriptor(); var idnull = charIDToTypeID( "null" ); var ref3 = new ActionReference(); var idLyr = charIDToTypeID( "Lyr " ); var idOrdn = charIDToTypeID( "Ordn" ); var idTrgt = charIDToTypeID( "Trgt" ); ref3.putEnumerated( idLyr, idOrdn, idTrgt ); desc6.putReference( idnull, ref3 ); var idT = charIDToTypeID( "T " ); var ref4 = new ActionReference(); var idLyr = charIDToTypeID( "Lyr " ); var idOrdn = charIDToTypeID( "Ordn" ); var idFrnt = charIDToTypeID( "Frnt" ); ref4.putEnumerated( idLyr, idOrdn, idFrnt ); desc6.putReference( idT, ref4 ); executeAction( idmove, desc6, DialogModes.NO ); }; // reselect layers; selectLayerByID(theLayers[0][0], false); if (theLayers.length > 1) { for (var d = 1; d < theLayers.length; d++) { selectLayerByID(theLayers[d][0], true); }; }; // delete last counter; // ======================================================= var desc11 = new ActionDescriptor(); desc11.putInteger( charIDToTypeID( "ItmI" ), counter.count ); desc11.putInteger( charIDToTypeID( "Grup" ), 0 ); executeAction( stringIDToTypeID( "countDelete" ), desc11, DialogModes.NO ); }; // reset preferences; app.preferences.rulerUnits = originalRulerUnits; }; //////////////////////////////////// ////// get array of arrays of smart objects witrh index, center and half-dimensions ////// function smartifyAndGetSelectedLayersIdxEtc(){ var selectedLayers = new Array; var ref = new ActionReference(); ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); var desc = executeActionGet(ref); if( desc.hasKey( stringIDToTypeID( 'targetLayers' ) ) ){ desc = desc.getList( stringIDToTypeID( 'targetLayers' )); var c = desc.count; var selectedLayers = new Array(); for(var i=0;i<c;i++){ try{ activeDocument.backgroundLayer; selectedLayers.push( desc.getReference( i ).getIndex() ); }catch(e){ selectedLayers.push( desc.getReference( i ).getIndex()+1 ); }; } }else{ var ref = new ActionReference(); ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "ItmI" )); ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); try{ activeDocument.backgroundLayer; selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-1); }catch(e){ selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))); }; }; //////////////////////////////////// var theArray = new Array; var theIDs = new Array; for (var m = 0; m < selectedLayers.length; m++) { var thisIndex = selectedLayers[m]; var ref = new ActionReference(); ref.putIndex( charIDToTypeID("Lyr "), thisIndex); var layerDesc = executeActionGet(ref); var thisID = layerDesc.getInteger(stringIDToTypeID("layerID")); var theKind = layerDesc.getInteger(stringIDToTypeID("layerKind")); var theName = layerDesc.getString(stringIDToTypeID("name")); var theVisibility = layerDesc.getInteger(stringIDToTypeID("visible")); var theBounds = layerDesc.getObjectValue(stringIDToTypeID("bounds")); var halfWidth = theBounds.getUnitDoubleValue(stringIDToTypeID("width")) / 2; var halfHeight = theBounds.getUnitDoubleValue(stringIDToTypeID("height")) / 2; var theX = theBounds.getUnitDoubleValue(stringIDToTypeID("left")) + halfWidth; var theY = theBounds.getUnitDoubleValue(stringIDToTypeID("top")) + halfHeight; // is normal, shape, smart object, pattern, gradiet, solid color; if (theKind == 1 || theKind == 4 || theKind == 5 || theKind == 9 || theKind == 10 || theKind == 11) { if (theVisibility == true) { theIDs.push ([thisID, theX, theY, halfWidth, halfHeight, theName]) } } }; //////////////////////////////////// for (var n = 0; n < theIDs.length; n++) { if (hasSmartObject(theIDs[n][0]) == false) { try { selectLayerByID(theIDs[n][0], false); var id557 = charIDToTypeID( "slct" ); var desc108 = new ActionDescriptor(); var id558 = charIDToTypeID( "null" ); var ref77 = new ActionReference(); var id559 = charIDToTypeID( "Mn " ); var id560 = charIDToTypeID( "MnIt" ); var id561 = stringIDToTypeID( "newPlacedLayer" ); ref77.putEnumerated( id559, id560, id561 ); desc108.putReference( id558, ref77 ); executeAction( id557, desc108, DialogModes.NO ); theArray.push([getLayerId(app.activeDocument.activeLayer), theIDs[n][1], theIDs[n][2], theIDs[n][3], theIDs[n][4], theIDs[n][5]]); } catch (e) {} } else {theArray.push(theIDs[n])}; }; //////////////////////////////////// //alert (theArray[0].join("\n")) return theArray //////////////////////////////////// }; // by mike hale, via paul riggott; function getLayerId(theLayer){ app.activeDocument.activeLayer = theLayer; //Assumes activeDocument and activeLayer var ref = new ActionReference(); ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt")); d = executeActionGet(ref); return d.getInteger(charIDToTypeID('LyrI')); }; ////// smart object or not ////// function hasSmartObject(idx){ var ref = new ActionReference(); ref.putProperty( charIDToTypeID("Prpr") , stringIDToTypeID( "smartObject" )); ref.putIdentifier( charIDToTypeID( "Lyr " ), idx); var desc = executeActionGet(ref); if(desc.hasKey(stringIDToTypeID('smartObject'))) {return true} else {return false}; }; ////// based on code by mike hale and paul riggott ////// function selectLayerByID(index,add){ add = undefined ? add = false:add var ref = new ActionReference(); ref.putIdentifier(charIDToTypeID("Lyr "), index); var desc = new ActionDescriptor(); desc.putReference(charIDToTypeID("null"), ref ); if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) ); desc.putBoolean( charIDToTypeID( "MkVs" ), false ); try{ executeAction(charIDToTypeID("slct"), desc, DialogModes.NO ); }catch(e){ alert(e.message); } }; //////////////////////////////////// ////// duplicate layer (id, xOffset, yOffset, theXScale, theYScale, theAngle) ////// function layerDuplicateOffsetScaleRotate (theID, xOffset, yOffset, theXScale, theYScale, theAngle) { selectLayerByID(theID, false); // ======================================================= var desc23 = new ActionDescriptor(); var idnull = charIDToTypeID( "null" ); var ref2 = new ActionReference(); // ref2.putIdentifier ( charIDToTypeID( "Lyr " ), theID ); ref2.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) ); desc23.putReference( idnull, ref2 ); desc23.putEnumerated( charIDToTypeID( "FTcs" ), charIDToTypeID( "QCSt" ), charIDToTypeID( "Qcsa" ) ); var idOfst = charIDToTypeID( "Ofst" ); var desc24 = new ActionDescriptor(); var idPxl = charIDToTypeID( "#Pxl" ); desc24.putUnitDouble( charIDToTypeID( "Hrzn" ), idPxl, xOffset ); desc24.putUnitDouble( charIDToTypeID( "Vrtc" ), idPxl, yOffset ); var idOfst = charIDToTypeID( "Ofst" ); desc23.putObject( idOfst, idOfst, desc24 ); var idPrc = charIDToTypeID( "#Prc" ); desc23.putUnitDouble( charIDToTypeID( "Wdth" ), idPrc, theXScale ); desc23.putUnitDouble( charIDToTypeID( "Hght" ), idPrc, theXScale ); desc23.putUnitDouble( charIDToTypeID( "Angl" ), charIDToTypeID( "#Ang" ), theAngle ); desc23.putEnumerated( charIDToTypeID( "Intr" ), charIDToTypeID( "Intp" ), stringIDToTypeID( "bicubicAutomatic" ) ); desc23.putBoolean( charIDToTypeID( "Cpy " ), true ); executeAction( charIDToTypeID( "Trnf" ), desc23, DialogModes.NO ); }; ////// duplicate layer (id, xOffset, yOffset, theXScale, theYScale, theAngle) ////// function layerDuplicateOffset (theID, xOffset, yOffset, theXScale, theYScale, theAngle) { selectLayerByID(theID, false); // ======================================================= var idcopy = charIDToTypeID( "copy" ); var desc6 = new ActionDescriptor(); var idnull = charIDToTypeID( "null" ); var ref1 = new ActionReference(); var idLyr = charIDToTypeID( "Lyr " ); ref1.putIdentifier ( idLyr, theID ); desc6.putReference( idnull, ref1 ); var idT = charIDToTypeID( "T " ); var desc7 = new ActionDescriptor(); var idHrzn = charIDToTypeID( "Hrzn" ); var idPxl = charIDToTypeID( "#Pxl" ); desc7.putUnitDouble( idHrzn, idPxl, xOffset ); var idVrtc = charIDToTypeID( "Vrtc" ); desc7.putUnitDouble( idVrtc, idPxl, yOffset ); var idOfst = charIDToTypeID( "Ofst" ); desc6.putObject( idT, idOfst, desc7 ); executeAction( idcopy, desc6, DialogModes.NO ); }; ////// bring to front ////// function bringToFront () { // ======================================================= var idmove = charIDToTypeID( "move" ); var desc6 = new ActionDescriptor(); var idnull = charIDToTypeID( "null" ); var ref3 = new ActionReference(); var idLyr = charIDToTypeID( "Lyr " ); var idOrdn = charIDToTypeID( "Ordn" ); var idTrgt = charIDToTypeID( "Trgt" ); ref3.putEnumerated( idLyr, idOrdn, idTrgt ); desc6.putReference( idnull, ref3 ); var idT = charIDToTypeID( "T " ); var ref4 = new ActionReference(); var idLyr = charIDToTypeID( "Lyr " ); var idOrdn = charIDToTypeID( "Ordn" ); var idFrnt = charIDToTypeID( "Frnt" ); ref4.putEnumerated( idLyr, idOrdn, idFrnt ); desc6.putReference( idT, ref4 ); executeAction( idmove, desc6, DialogModes.NO ); };
Copier le lien dans le Presse-papiers
Copié
I think problem is that "countAdd" has not "charID". I am afraid that regular script event manager works only with charIDs
This is what I can get from arguments inside on event executed script. I am using event "everything" ("All ")
Copier le lien dans le Presse-papiers
Copié
And here comparsion with making color sampler which has additional class and charIDs:
It's above counting tool in you screenshot.
Copier le lien dans le Presse-papiers
Copié
Thanks in any case for checking it out.
Copier le lien dans le Presse-papiers
Copié
It works perfectly fine on my computer. (The gif shows a screen recording.)
Have you tried entering in the xml directly or via the Script Events Manager?
Copier le lien dans le Presse-papiers
Copié
aah... sorry I thought that you are trying to solve something what is not working 😄
Copier le lien dans le Presse-papiers
Copié
Please forgive if I have expressed myself unclearly but the set-up seems to work.
Whether is can be useful is another question.
Copier le lien dans le Presse-papiers
Copié
Being new to scripts and such. This looks perfect for me but I am very unsure how to get this fully working in my photoshop. Googling has failed me as well here
Copier le lien dans le Presse-papiers
Copié
Did you place the jsx-file in the Scripts Forlder and add the event in the file »Scripts Events Manager.xml« as indicated?
Copier le lien dans le Presse-papiers
Copié
Hi, you pointed me to this entry from another question I had. It looks as if it will be really close to what I need. I've just got a small question. Above you mention adding into Script Events Manager.xml but I can only find Script Events Manager.jsx which contains various functions. Is this just an updated version, or am I looking in the wrong place?
I have also taken the script, named as per example, and saved in: Program Files,/Adobe/Adobe Photoshop 2022/ Presets/Scripts. I have added to the Script Events Manager through Photoshop - but these don't appear in the Script Events Manager.jsx
Any suggestions?
Copier le lien dans le Presse-papiers
Copié
Ui, been a while …
The xml-file is still there for me (see screenshot).
~/Library/Preferences/Adobe Photoshop 2022 Settings/Script Events Manager.xml
In the dialog try using »Browse« to select the jsx-file.
Copier le lien dans le Presse-papiers
Copié
Hi, I've attached a couple of screenshots. Yes, I used the browse to select the jsx file - it is now listed in the Script Events manager. I've also included a screenshot of the folder with both the scripts highlighted. At the moment, I'm running a full disk search to see if there is a Script Events Manager.xml anywhere on my PC - so, it might finish by Christmas. Will let you know either way.
Copier le lien dans le Presse-papiers
Copié
Have you checked
Users/[user name]/Library/Preferences/Adobe Photoshop 2022 Settings
?
Copier le lien dans le Presse-papiers
Copié
Yes, under Library there's only one folder - Containers. There's only one folder within Containers and that is for another program but not related to Photoshop.
Copier le lien dans le Presse-papiers
Copié
Just to make sure: That’s in your user folder?
Copier le lien dans le Presse-papiers
Copié
Yes, that's correct..
Copier le lien dans le Presse-papiers
Copié
One can add an event via »Add an Event« in the Script Events Manager dialog instead of editing the xml.
Copier le lien dans le Presse-papiers
Copié
Yes, On mine it looks slightly different (see file Script Events Manager above) but I think it is more or less the same. I'm going to try revisiting this setup (ie delete the one I created, and try it again) - perhaps I've used the wrong terms in the Descriptive Label. Unfortunately, I'm not going to get to look at this until later in the weekend. But will let you know how I get on. Have a good weekend.
Copier le lien dans le Presse-papiers
Copié
No hurry …
Have a good weekend, too!
Copier le lien dans le Presse-papiers
Copié
Fantastic - works perfectly. Thanks for all your help.
Copier le lien dans le Presse-papiers
Copié
You’re welcome.
It is a crude work-around to emulate full color brush-tips but it’s good to read that you got it up and running.
Trouvez plus d’idées, d’événements et de ressources dans la nouvelle communauté Adobe
Explorer maintenant