Quitter
  • Communauté internationale
    • Langue:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티

full colour brush dabbing simulation script

Community Expert ,
Oct 08, 2017 Oct 08, 2017

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 …

countToolColorBrushDabSim.gif

 

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.

countToolScriptEventsManagerXml.jpgcountToolScriptEventsManager.jpg

// 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 );
};
SUJETS
Actions et scripting
3.2K
Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Adobe
Enthousiaste ,
Oct 08, 2017 Oct 08, 2017

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 ")

2017-10-08_235520.jpg

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Enthousiaste ,
Oct 08, 2017 Oct 08, 2017

And here comparsion with making color sampler which has additional class and charIDs:

It's above counting tool in you screenshot.

2017-10-09_000430.jpg

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Community Expert ,
Oct 08, 2017 Oct 08, 2017

Thanks in any case for checking it out.

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Community Expert ,
Oct 08, 2017 Oct 08, 2017

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?

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Enthousiaste ,
Oct 09, 2017 Oct 09, 2017

aah... sorry I thought that you are trying to solve something what is not working 😄

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Community Expert ,
Oct 09, 2017 Oct 09, 2017

Please forgive if I have expressed myself unclearly but the set-up seems to work.

Whether is can be useful is another question.

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Débutant dans la communauté ,
Apr 30, 2020 Apr 30, 2020

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

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Community Expert ,
May 01, 2020 May 01, 2020

Did you place the jsx-file in the Scripts Forlder and add the event in the file »Scripts Events Manager.xml« as indicated? 

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Explorateur ,
Nov 25, 2021 Nov 25, 2021

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?  

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Community Expert ,
Nov 25, 2021 Nov 25, 2021

Ui, been a while … 

 

The xml-file is still there for me (see screenshot). 

~/Library/Preferences/Adobe Photoshop 2022 Settings/Script Events Manager.xml

Screenshot 2021-11-25 at 14.27.02.png

 

In the dialog try using »Browse« to select the jsx-file. 

Screenshot 2021-11-25 at 14.29.05.png

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Explorateur ,
Nov 25, 2021 Nov 25, 2021

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.

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Community Expert ,
Nov 25, 2021 Nov 25, 2021

Have you checked 

Users/[user name]/Library/Preferences/Adobe Photoshop 2022 Settings

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Explorateur ,
Nov 25, 2021 Nov 25, 2021

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.

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Community Expert ,
Nov 25, 2021 Nov 25, 2021

Just to make sure: That’s in your user folder? 

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Explorateur ,
Nov 25, 2021 Nov 25, 2021

Yes, that's correct..

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Community Expert ,
Nov 26, 2021 Nov 26, 2021

One can add an event via »Add an Event« in the Script Events Manager dialog instead of editing the xml. 

Screenshot 2021-11-26 at 12.23.21.png

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Explorateur ,
Nov 26, 2021 Nov 26, 2021

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.

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Community Expert ,
Nov 26, 2021 Nov 26, 2021

No hurry … 

 

Have a good weekend, too! 

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Explorateur ,
Nov 27, 2021 Nov 27, 2021

Fantastic - works perfectly.  Thanks for all your help.

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Community Expert ,
Nov 27, 2021 Nov 27, 2021
LA PLUS RÉCENTE

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. 

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines