Skip to main content
Participant
October 11, 2020
Question

Install Brushes via script

  • October 11, 2020
  • 2 replies
  • 545 views

I'm creating some Photoshop actions that are going to work via HTML Panel, some of them uses tool presets and others use tool presets and brushes and right now I don't know how check if X brush exist and if not install the .abr file from some route, don't know if it's possible do it or in some way change the script that I have for the .tpl files to do the same.

 

Right now I use this to detect if there's a X preset tool and if not install it:

 

var presetSet  = 'fileName';
  var presetName = 'tool name';

  function setTools(){
    try {
        selectToolPreset(presetName);
    } catch(e) {
        if (loadToolPresetSet(presetSet)) {
            try {
                selectToolPreset(presetName);
            } catch(e) {
                alert("Was unable to Select the Tools Preset "+presetName);
            }               
        } else {
            alert("Was unable to load Tools Presets Set "+presetSet);
        }       
    };
  };

  function selectToolPreset(PresetName) {
      var desc = new ActionDescriptor();
      var ref = new ActionReference();
      ref.putName( stringIDToTypeID( "toolPreset" ), PresetName );
      desc.putReference( charIDToTypeID( "null" ), ref );
      executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO );
  }

  function loadToolPresetSet(SetName) {
      returncode = true;
      var thisFile = new File($.fileName);
      var path = thisFile.path+'/';
      var SetFile = new File(path + SetName + ".tpl");

      if (!SetFile.exists) {
          returncode = false;
      } else {
          var desc = new ActionDescriptor();
          var ref = new ActionReference();
          ref.putProperty( charIDToTypeID( "Prpr" ), stringIDToTypeID( "toolPreset"  ));
          ref.putEnumerated( charIDToTypeID( "capp" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt"  ) );
          desc.putReference( charIDToTypeID( "null" ), ref );
          desc.putPath( charIDToTypeID( "T   " ), new File( SetFile ) );
          desc.putBoolean( charIDToTypeID( "Appe" ), true );
          try {
              executeAction( charIDToTypeID( "setd" ), desc, DialogModes.NO );
          } catch(e) {
              returncode = false;
          }
      }
      return returncode ;
  }
This topic has been closed for replies.

2 replies

Participating Frequently
October 11, 2020

Bonjour

 

I have this script which I do not use and which seems to me to be suitable:

 

//Chris Whitaker
//www.Funkybunnies3d.com
//
//simply cycle through a few important tools,
//you can edit this by checking the list of tools at the bottom
//
//PaulMR did most of this work, I just set it up to cycle through... which was only a few lines, so big thanks to him!

/* .................. */

//Simplifie par moi : trouver l outil en cours

function findCurrentTool(){
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var cTool = typeIDToStringID( executeActionGet(ref).getEnumerationType(stringIDToTypeID('tool')) );
return cTool;
};

var cToolAngl = findCurrentTool();
//alert( cToolFranc );
var cToolFranc = cToolAngl //cToolFranc


switch ( cToolFranc )
{

    case 'moveTool':
          cToolFranc = 'Outil Deplacement';
    break;
    
    default:  
          cToolFranc = 'Outil INDEFINI';
    
    case 'marqueeRectTool':
          cToolFranc = 'Outil Rectangle de selection';
    break;  
    
    case 'marqueeEllipTool':
          cToolFranc = 'Outil Ellipse de selection';
    break;          
    
    case 'marqueeSingleRowTool':
          cToolFranc = 'Outil Rectangle de selection 1 rangee';
    break;          
    
    case 'marqueeSingleColumnTool':
          cToolFranc = 'marqueeSingleColumnTool';
    break;          
    
    case 'lassoTool':
          cToolFranc = 'Outil Lasso';
    break;          
    
    case 'polySelTool':
          cToolFranc = 'Outil Lasso polygonal';
    break;          
    
    case 'magneticLassoTool':
          cToolFranc = 'Outil Lasso magnetique';
    break;          
    
    case 'quickSelectTool':
          cToolFranc = 'Outil Selection rapide';
    break;          
    
    case 'magicWandTool':
          cToolFranc = 'Outil Baguette magique';
    break;          
    
    case 'cropTool':
          cToolFranc = 'Outil Recadrage';
    break;          
    
    case 'sliceTool':
          cToolFranc = 'Outil Tranche';
    break;          
    
    case 'sliceSelectTool':
          cToolFranc = 'Outil Selection de tranche';
    break;          
    
    case 'eyedropperTool':
          cToolFranc = 'Outil Pipette';
    break;          
    
    case 'colorSamplerTool':
          cToolFranc = 'Outil Echantillonnage de couleur';
    break;          
    
    case 'rulerTool':
          cToolFranc = 'Outil Regle';
    break;          
    
    case 'textAnnotTool':
          cToolFranc = 'Outil Annotation';
    break;          
    
    case 'countTool':
          cToolFranc = 'Outil Comptage';
    break;          
    
    case 'spotHealingBrushTool':
          cToolFranc = 'Outil Correcteur localise';
    break;          
    
    case 'magicStampTool':
          cToolFranc = 'Outil Correcteur';
    break;          
    
    case 'patchSelection':
          cToolFranc = 'Outil Piece';
    break;          
    
    case 'redEyeTool':
          cToolFranc = 'Outil Œil rouge';
    break;          
    
    case 'paintbrushTool':
          cToolFranc = 'Outil Pinceau';
    break;          
    
    case 'pencilTool':
          cToolFranc = 'Outil Crayon';
    break;          
    
    case 'colorReplacementBrushTool':
          cToolFranc = 'Outil Remplacement de couleur';
    break;          
    
    case 'wetBrushTool':
          cToolFranc = 'Outil Pinceau melangeur';
    break;          
    
    case 'cloneStampTool':
          cToolFranc = 'Outil Tampon de duplication';
    break;          
    
    case 'patternStampTool':
          cToolFranc = 'Outil Tampon de motif';
    break;          
    
    case 'historyBrushTool':
          cToolFranc = 'Outil Forme d historique';
    break;          
    
    case 'artBrushTool':
          cToolFranc = 'Outil Forme d historique artistique';
    break;          
    
    case 'eraserTool':
          cToolFranc = 'Outil Gomme';
    break;          
    
    case 'backgroundEraserTool':
          cToolFranc = 'Outil Gomme d arriere-plan';
    break;          
    
    case 'magicEraserTool':
          cToolFranc = 'Outil Gomme magique';
    break;          
    
    case 'gradientTool':
          cToolFranc = 'Outil Degrade';
    break;          
    
    case 'bucketTool':
          cToolFranc = 'Outil Pot de peinture';
    break;          
    
    case 'blurTool':
          cToolFranc = 'Outil Goutte d eau';
          break;          
    
    case 'sharpenTool':
          cToolFranc = 'Outil Nettete';
    break;          
    
    case 'smudgeTool':
          cToolFranc = 'Outil Doigt';
    break;          
    
    case 'dodgeTool':
          cToolFranc = 'Outil Densite -';
    break;          
    
    case 'burnInTool':
          cToolFranc = 'Outil Densite +';
    break;          

    case 'saturationTool':
          cToolFranc = 'Outil Eponge';
    break;          
    
    case 'penTool':
          cToolFranc = 'Outil Plume';
    break;          
    
    case 'freeformPenTool':
          cToolFranc = 'Outil Plume libre';
    break;          
    
    case 'addKnotTool':
          cToolFranc = 'Outil Ajout de point d ancrage' ;
    break;          
    
    case 'deleteKnotTool':
          cToolFranc = 'Outil Suppression de point d ancrage';
    break;          
    
    case 'convertKnotTool':
          cToolFranc = 'Outil Conversion de point';
    break;          
    
    case 'typeCreateOrEditTool':
          cToolFranc = 'Outil Texte horizontal';
    break;          
    
    case 'typeVerticalCreateOrEditTool':
          cToolFranc = 'Outil Texte vertical';
    break;          
    
    case 'typeCreateMaskTool':
          cToolFranc = 'Outil Masque de texte horizontal';
    break;   
   
    case 'typeVerticalCreateMaskTool':
          cToolFranc = 'Outil Masque de texte vertical';
    break; 
    
    case 'pathComponentSelectTool':
          cToolFranc = 'Outil Selection de trace';
    break;
     
    case 'directSelectTool':
          cToolFranc = 'Outil Selection directe';
    break; 
    
    case 'rectangleTool':
          cToolFranc = 'Outil Rectangle';
    break; 
    
    case 'roundedRectangleTool':
          cToolFranc = 'Outil Rectangle arrondi';
    break; 
    
    case 'ellipseTool':
          cToolFranc = 'Outil Ellipse';
    break; 
    
    case 'polygonTool':
          cToolFranc = 'Outil Polygone';
    break; 
    
    case 'lineTool':
          cToolFranc = 'Outil Trait';
    break; 
    
    case 'customShapeTool':
          cToolFranc = 'Outil Forme personnalisee';
    break; 
    
    case 'soundAnnotTool':
          cToolFranc = 'Outil Annotation audio';
    break; 
    
    case 'handTool':
          cToolFranc = 'Outil Main';
    break; 
    
    case 'rotateTool':
          cToolFranc = 'Outil Rotation de l affichage';
    break; 
    
    case 'zoomTool':
          cToolFranc = 'Outil Zoom';
    break; 

    
            
}          

alert( cToolAngl );
alert( cToolFranc );
          
//selectTool('moveTool'); = 'Outil Deplacement'
//selectTool('marqueeRectTool'); = 'Outil Rectangle de selection'
//selectTool('marqueeEllipTool'); = 'Outil Ellipse de selection'
//selectTool('marqueeSingleRowTool'); = 'Outil Rectangle de selection 1 rangee'
//selectTool('marqueeSingleColumnTool'); = 'Outil Rectangle de selection 1 colonne'
//selectTool('lassoTool'); = 'Outil Lasso'
//selectTool('polySelTool'); = 'Outil Lasso polygonal'
//selectTool('magneticLassoTool'); = 'Outil Lasso magnetique'
//selectTool('quickSelectTool'); = 'Outil Selection rapide'
//selectTool('magicWandTool'); = 'Outil Baguette magique'
//selectTool('cropTool'); = 'Outil Recadrage'
//selectTool('sliceTool'); = 'Outil Tranche'
//selectTool('sliceSelectTool'); = 'Outil Selection de tranche'
//selectTool('eyedropperTool'); = 'Outil Pipette'
//selectTool('colorSamplerTool'); = 'Outil Echantillonnage de couleur'
//selectTool('rulerTool'); = 'Outil Regle'
//selectTool('textAnnotTool'); = 'Outil Annotation'
//selectTool('countTool'); = 'Outil Comptage'
//selectTool('spotHealingBrushTool'); = 'Outil Correcteur localise'
//selectTool('magicStampTool'); = 'Outil Correcteur'
//selectTool('patchSelection'); = 'Outil Piece'
//selectTool('redEyeTool'); = 'Outil Œil rouge'
//selectTool('paintbrushTool'); = 'Outil Pinceau'
//selectTool('pencilTool'); = 'Outil Crayon'
//selectTool('colorReplacementBrushTool'); = 'Outil Remplacement de couleur'
//selectTool('wetBrushTool'); = 'Outil Pinceau melangeur'
//selectTool('cloneStampTool'); = 'Outil Tampon de duplication'
//selectTool('patternStampTool'); = 'Outil Tampon de motif'
//selectTool('historyBrushTool'); = 'Outil Forme d historique'
//selectTool('artBrushTool'); = 'Outil Forme d historique artistique'
//selectTool('eraserTool'); = 'Outil Gomme'
//selectTool('backgroundEraserTool'); = 'Outil Gomme d arriere-plan'
//selectTool('magicEraserTool'); = 'Outil Gomme magique'
//selectTool('gradientTool'); = 'Outil Degrade'
//selectTool('bucketTool'); = 'Outil Pot de peinture'
//selectTool('blurTool'); = 'Outil Goutte d eau'
//selectTool('sharpenTool'); = 'Outil Nettete'
//selectTool('smudgeTool'); = 'Outil Doigt'
//selectTool('dodgeTool'); = 'Outil Densite -'
//selectTool('burnInTool'); = 'Outil Densite +'
//selectTool('saturationTool'); = 'Outil Eponge'
//selectTool('penTool'); = 'Outil Plume'
//selectTool('freeformPenTool'); = 'Outil Plume libre'
//selectTool('addKnotTool'); = 'Outil Ajout de point d ancrage'
//selectTool('deleteKnotTool'); = 'Outil Suppression de point d ancrage'
//selectTool('convertKnotTool'); = 'Outil Conversion de point'
//selectTool('typeCreateOrEditTool'); = 'Outil Texte horizontal'
//selectTool('typeVerticalCreateOrEditTool'); = 'Outil Texte vertical'
//selectTool('typeCreateMaskTool'); = 'Outil Masque de texte horizontal'
//selectTool('typeVerticalCreateMaskTool'); =  'Outil Masque de texte vertical'
//selectTool('pathComponentSelectTool'); = 'Outil Selection de trace'
//selectTool('directSelectTool'); = 'Outil Selection directe'
//selectTool('rectangleTool'); = 'Outil Rectangle'
//selectTool('roundedRectangleTool'); = 'Outil Rectangle arrondi'
//selectTool('ellipseTool'); = 'Outil Ellipse'
//selectTool('polygonTool'); = 'Outil Polygone'
//selectTool('lineTool'); = 'Outil Trait'
//selectTool('customShapeTool'); = 'Outil Forme personnalisee'
//selectTool('soundAnnotTool'); = 'Outil Annotation audio' // n existe pas dans  version
//selectTool('handTool'); = 'Outil Main'
//selectTool('rotateTool'); = 'Outil Rotation de l affichage'
//selectTool('zoomTool'); = 'Outil Zoom'

 

JJMack
Community Expert
Community Expert
October 11, 2020

I do not think the  tool preset code you posted will work all the time.  A tool preset may exist but selecting the tool preset may fail because of current state the Photoshop UI.   It is best to set the current tool  to be the tool the preset is for before you try to select the preset. For it depends on the current state of Photoshop UI if any tools preset can be selected or just current tool preset can be selected.

JJMack
Participant
October 11, 2020

Actually I ended using your modified code:

 

var brush = 'watercolor_b_diffuse';
var brushSet = 'brushes'
try{
    selectBrush(brush);
} catch(e){
    if (loadBrushes()){
        try {
            selectBrush(brush);
        } catch(e) {
            alert("no se encontro "+brush);
        }               
    } else {
        alert("no brochas");
    } 
}
function selectBrush(PresetName) {
    var desc = new ActionDescriptor();
    var ref = new ActionReference();
    ref.putName( stringIDToTypeID( "brush" ), PresetName );
    desc.putReference( charIDToTypeID( "null" ), ref );
    executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO );
}
function loadBrushes(brushSet) {
      returncode = true;
      var thisFile = new File($.fileName);
      var path = thisFile.path+'/';
      var SetFile = new File(path + brushSet + ".abr");

      if (!SetFile.exists) {
          returncode = false;
      } else {
          var desc = new ActionDescriptor();
          var ref = new ActionReference();
          ref.putProperty( charIDToTypeID( "Prpr" ), stringIDToTypeID( "brush"  ));
          ref.putEnumerated( charIDToTypeID( "capp" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt"  ) );
          desc.putReference( charIDToTypeID( "null" ), ref );
          desc.putPath( charIDToTypeID( "T   " ), new File( SetFile ) );
          desc.putBoolean( charIDToTypeID( "Appe" ), true );
          try {
              executeAction( charIDToTypeID( "setd" ), desc, DialogModes.NO );
          } catch(e) {
              returncode = false;
          }
      }
      return returncode ;
  }

 

The only thing I don't know it's how load the patterns to be used via code