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

Associate Brush/Tool Preset with Layer

Enthusiast ,
Nov 13, 2013 Nov 13, 2013

Copy link to clipboard

Copied

I know there's a way to do this via scriptinglistener, so I figured I'd post it here. Wondering if there's a way to select a brush or tool preset automatically whenever you select a layer.

For example, there are 2 layers:

'Airbrush' - I only want to use the tool preset 'MyAirbrush' on this layer and never use any other brush or tool preset

'Pastel' - I only want to use the tool preset 'MyPastel' on this layer and never use any other brush or tool preset

So, when I select the layer 'Airbrush', it will automatically select the tool preset 'MyAirbrush' along with it. And whenever I switch to the layer 'Pastel', it will automatically select the tool preset 'MyPastel'. This would eliminate having to select the tool preset after selecting the layer (no big deal but could save time and eliminate a step)

Like I said I can acheive it via scriptinglistener, but then it becomes confusing because instead of simply switching layers in the layer panel, I'd have to run the script instead, and each script would reflect only one individual layer and the tool preset to go with it- I'd have to create a script for every layer doing it this way - not feasible. I was wondering if there was another way to do it somewhere in Photoshop, such as 'link tool preset to layer' or 'associate tool preset with layer'

thanks!

TOPICS
Actions and scripting

Views

6.1K

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
Adobe
Guru ,
Nov 14, 2013 Nov 14, 2013

Copy link to clipboard

Copied

You should be able to do something like that using a 'select' eventListener. The event script should first check that a layer was selected( not a path, channel, tool, etc ) then check the active layer name and switch the presets.

The key is the event handler runs the script for you. You will not need a different script for each layer. Just have a switch or multiple if statements to handle as many layers as needed.

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
Enthusiast ,
Nov 15, 2013 Nov 15, 2013

Copy link to clipboard

Copied

Thanks Michael, I'm going to look into this. I'm also looking for a way to do it with 3rd party apps (there's a few good ones that can automate the process)

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
Guru ,
Nov 15, 2013 Nov 15, 2013

Copy link to clipboard

Copied

function _selectLayerHandler(desc) {

  var layerName = app.activeDocument.activeLayer.name;

  switch( layerName ){

      case "Airbrush": selectPreset('Airbrush-Grainy Opaque'); break;

      case "Pastel": selectPreset('Angle - Flat Opaque'); break;

  }

};

function selectPreset(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 );

};

try {

  if (arguments.length >= 2) {

    var desc = arguments[0];

    var event = arguments[1];

    if (event == charIDToTypeID('slct')) {

      var ref = desc.getReference(charIDToTypeID('null'));

      var cls = ref.getDesiredClass();

      if (cls == charIDToTypeID('Lyr ')) {

        _selectLayerHandler(desc);

      }

    }

  }

} catch (e) {

  alert( "Error: " + e + ":" + 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
Community Expert ,
Nov 15, 2013 Nov 15, 2013

Copy link to clipboard

Copied

That's interesting, Mike.  How would you go about setting up and running the script that uses the eventListener?  Is that something that you run when you start PS, or put in the startup folder?

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
Guru ,
Nov 15, 2013 Nov 15, 2013

Copy link to clipboard

Copied

There are two ways to add an eventHander. One is by using the menu. Choose File-Scripts-Scripts Event Manager... then set it up in the dialog that opens.

I prefer to install with a sperate script.

if(!app.notifiersEnabled) app.notifiersEnabled =  true;

var hasSelectEvent = false;

for(var e = 0;e<app.notifiers.length;e++){

   if(app.notifiers.event == 'slct') hasSelectEvent = true;

}

if(!hasSelectEvent) {

   var eventFile = new File('~/desktop/layerPreset.jsx');

   app.notifiers.add( "slct", eventFile);

}

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
Community Expert ,
Nov 15, 2013 Nov 15, 2013

Copy link to clipboard

Copied

Thanks, Mike!  Made me start thinking about some posibilities.

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
Enthusiast ,
Nov 15, 2013 Nov 15, 2013

Copy link to clipboard

Copied

I ensured that my photohop document had layers named 'Airbrush' and 'Pastel'. I also ensured that my active tool presets file had presets named 'Airbrush-Grainy Opaque' and 'Angle - Flat Opaque' . I then ran Michael's first script but I didn't see anything happen. Is there something I'm missing?   

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
Guru ,
Nov 16, 2013 Nov 16, 2013

Copy link to clipboard

Copied

It is an event script. You don't run it directly. It gets run every time there is a select event. That is if you have installed it as an event script using either the menu or by adding a notifier with the second script I posted. If you use the script to install make sure you edit the path to the event script.

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
Enthusiast ,
Nov 16, 2013 Nov 16, 2013

Copy link to clipboard

Copied

ok, I'm making some progress with it. I've placed the event handler script onto my desktop and named it 'layerPreset.jsx'. My tool presets has the brushes and layers (as named in post#7 above).

It seems to be working! Micheal you're a genius as usual - the possibilities here are just becoming evident

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
Guru ,
Nov 16, 2013 Nov 16, 2013

Copy link to clipboard

Copied

LATEST

It would be better if you added the eventClass argument when setting up the notifier. That way the script would run only when a layer is selected. As it is now it would run when anything is selected. Becasue the script checks the class it will not do anything if it wasn't a layer selected but the script still runs.

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