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

Script to get brush group when getting brush name

Community Beginner ,
Mar 18, 2023 Mar 18, 2023

Copy link to clipboard

Copied

Hi, firstly I'm only tagging because that was recommended in a previous post and it got a hit almost immediately after a couple of days lingering. If it's considered pestering then let me know...and I won't do it so often 😉 

Tags : @jazz-y , @c.pfaffenbichler , @r-bin , @Stephen_A_Marsh
I use the script below to get brush names in Photoshop. I've just come across a case of duplicate brush names and have two questions:
1. Having done some testing it seems Photoshop will create a new brush group and append a suffix when there are duplicates. However the brush name remains the same. Is this correct?
2. If the above is correct how does Photoshop know which brush to load when a brush is selected? ScriptListener only seems to note the brush name. There must be a unique ID somewhere?
2. Is there any way of getting the brush group name along with the brush name in the script below (or any other script)?

 

//script start
var names = getPresetList(0);

function getPresetList(presetIndex)
{
// presetIndex: 0 to 7
// 0: Brushes
// 1: Swatches
// 2: Gradients
// 3: Styles
// 4: Patterns
// 5: Contours
// 6: Custom Shapes
// 7: Tools

var presetNames = [];
var ref = new ActionReference();
ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("presetManager"));
ref.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
var desc = executeActionGet(ref);
var list = desc.getList(stringIDToTypeID("presetManager"));
var nameList = list.getObjectValue(presetIndex).getList(stringIDToTypeID("name"));
for (var nameIndex = 0; nameIndex < nameList.count; nameIndex++)
{
var n = nameList.getString(nameIndex);
presetNames.push(n);
}
return presetNames;
};
//script end

 

duplicatebrush2.jpg

 

TOPICS
Windows

Views

1.7K

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 3 Correct answers

Community Expert , Mar 18, 2023 Mar 18, 2023

Thank you for including me in such a prestigious list of scripters, however, this is above my pay grade! :]

 

Edit: Part of the answer may be found here from @r-bin:

 

https://community.adobe.com/t5/photoshop-ecosystem-discussions/select-refer-to-brushes-by-name-within-brush-sets-by-name/td-p/9979111

Votes

Translate

Translate
Community Expert , Mar 19, 2023 Mar 19, 2023

Above mine, too. 

 

I suspect one could deduce the indices from the result of the function show_brushes_object() – starting at 1, with every group counting as well. 

Screenshot 2023-03-19 at 12.22.15.png

 

@VahxLar , what is the ultimate point here? What are you trying to achieve with the information you are trying to collect? 

Votes

Translate

Translate
Community Beginner , Mar 20, 2023 Mar 20, 2023

Yes, trying to support it beyond a local environment would be ruinous! It's a few machines within control, but users can do what they choose with their instance of Photoshop. And some like to do goodness knows what with their brushes 😉
That code which was referred to by yourself and @Stephen_A_Marsh seems to be the answer. I haven't had a chance to understand it fully, but if I isolate the function select_brush_idx() and use some arbitrary indices it seems to select a brush by id rather than nam

...

Votes

Translate

Translate
Adobe
Community Expert ,
Mar 18, 2023 Mar 18, 2023

Copy link to clipboard

Copied

Thank you for including me in such a prestigious list of scripters, however, this is above my pay grade! :]

 

Edit: Part of the answer may be found here from @r-bin:

 

https://community.adobe.com/t5/photoshop-ecosystem-discussions/select-refer-to-brushes-by-name-withi...

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 ,
Mar 19, 2023 Mar 19, 2023

Copy link to clipboard

Copied

Above mine, too. 

 

I suspect one could deduce the indices from the result of the function show_brushes_object() – starting at 1, with every group counting as well. 

Screenshot 2023-03-19 at 12.22.15.png

 

@VahxLar , what is the ultimate point here? What are you trying to achieve with the information you are trying to collect? 

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 Beginner ,
Mar 19, 2023 Mar 19, 2023

Copy link to clipboard

Copied

@c.pfaffenbichler"What are you trying to achieve with the information you are trying to collect?"

I've got a C#.Net application that calls javascript files to apply random brush strokes on a Photoshop document.
In the C# app, the user is presented with a list of brushes that have come from Photoshop. The script will then use the brush/brushes the user has selected by passing the brush names from the C# app to the script.
If there are duplicate brushes in Photoshop then Photoshop will eventually use the wrong brush because the only current means of identifying the brush that I'm aware of in script is the brush name. Ideally there should be some sort of unique ID to identify the brush.
If not, the next step would be to inform the user which group is holding the duplicate brushes so the user can then maybe clone the group/brush and rename it or maybe I can script this cloning process (haven't tried) and then ignore the duplicates. But that's starting to get messy if there are potentially thousands of brushes in Photoshop. Dunno, I'm up for any ideas.

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 Beginner ,
Mar 21, 2023 Mar 21, 2023

Copy link to clipboard

Copied

LATEST

The behaviour is exactly as you indicated - if I index everything in the tree including groups the indices of the brushes match the desired brush to be selected. Trying to pass an index that corresponds to a group throws a script error as would be expected. Can't ask for more than that.

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 ,
Mar 20, 2023 Mar 20, 2023

Copy link to clipboard

Copied

quote

1. Having done some testing it seems Photoshop will create a new brush group and append a suffix when there are duplicates. However the brush name remains the same. Is this correct?

 

I don’t quite understand what you mean. 

Why are you duplicating the Groups? 

It is perefctly possible to have two Brushes of the same name in one Group. 

Screenshot 2023-03-20 at 08.15.53.png

 

quote

Ideally there should be some sort of unique ID to identify the brush.

You can get the indices from r-bin’s code. 

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 Beginner ,
Mar 20, 2023 Mar 20, 2023

Copy link to clipboard

Copied

quote

Why are you duplicating the Groups? 

I'm not, Photoshop is. Or at least that is the behaviour on my instance of version 2022 (23.5.4) when I tested this. If I import a brush (ie double click the abr file) then Photoshop creates a new group (the name of which seems to be based on the abr filename). If that group was already in Photoshop then it uses the name and appends an index suffix. But it will use the same brush name as the originally exported brush.

 

Also, as you've pointed out, Photoshop allows duplicate brush names in the same group. So internally Photoshop must be using a unique identifier. Why they don't expose this for use in scripts is is odd. I can only surmise that duplicate brush names are perceived as poor management and hence a user issue. The problem though is if you are someone that likes to purchase 3rd party packages (actions, brushes etc) it can be easy to end up with duplicate brush names.

 

I was just checking the behaviour with patterns, and pattern selection seems to use a GUID (unless I've misinterpreted the code below).

var idMk = charIDToTypeID( "Mk  " );
    var desc238 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref1 = new ActionReference();
        var idcontentLayer = stringIDToTypeID( "contentLayer" );
        ref1.putClass( idcontentLayer );
    desc238.putReference( idnull, ref1 );
    var idUsng = charIDToTypeID( "Usng" );
        var desc239 = new ActionDescriptor();
        var idType = charIDToTypeID( "Type" );
            var desc240 = new ActionDescriptor();
            var idPtrn = charIDToTypeID( "Ptrn" );
                var desc241 = new ActionDescriptor();
                var idNm = charIDToTypeID( "Nm  " );
                desc241.putString( idNm, """Grass-Autumn""" );
                var idIdnt = charIDToTypeID( "Idnt" );
                desc241.putString( idIdnt, """b25bc481-1c2d-ae45-8e7a-5cafcf44db94""" );
            var idPtrn = charIDToTypeID( "Ptrn" );
            desc240.putObject( idPtrn, idPtrn, desc241 );
        var idpatternLayer = stringIDToTypeID( "patternLayer" );
        desc239.putObject( idType, idpatternLayer, desc240 );
    var idcontentLayer = stringIDToTypeID( "contentLayer" );
    desc238.putObject( idUsng, idcontentLayer, desc239 );
executeAction( idMk, desc238, DialogModes.NO );

 

Thanks for that code - I will experiment with the indices.

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 ,
Mar 20, 2023 Mar 20, 2023

Copy link to clipboard

Copied

I think a global unique numbering of brushes could be problematic – considering the number of Photoshop users and how many Brushes they might create and share. 

 

What kind of brushes do you intend to use – plain round Brushes, Bristle and Erodible Brushes, Sampled Brushes? 

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 Beginner ,
Mar 20, 2023 Mar 20, 2023

Copy link to clipboard

Copied

quote

What kind of brushes do you intend to use – plain round Brushes, Bristle and Erodible Brushes, Sampled Brushes? 


I'm trying to use all of the installed brushes. As you know, it's impossible to get all the desired brush behaviour through scripting especially when trying to tweak brush settings for more complex brushes but the workarounds for most are acceptable.
However, the current stumbling block is Photoshop using the wrong brush because of duplicate brush namess. Currently I can't even trust the thumbnail I export from the brush, let alone be 100% sure that Photoshop is using the right brush while the script is running. I need to explore the options.

 

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 ,
Mar 20, 2023 Mar 20, 2023

Copy link to clipboard

Copied

All of the already installed Brushes on other machines or only your own one?

Because for computers »out of your control« that would seem a gamble. 

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 Beginner ,
Mar 20, 2023 Mar 20, 2023

Copy link to clipboard

Copied

Yes, trying to support it beyond a local environment would be ruinous! It's a few machines within control, but users can do what they choose with their instance of Photoshop. And some like to do goodness knows what with their brushes 😉
That code which was referred to by yourself and @Stephen_A_Marsh seems to be the answer. I haven't had a chance to understand it fully, but if I isolate the function select_brush_idx() and use some arbitrary indices it seems to select a brush by id rather than name without a problem.
On the surface this seems to be exactly what's needed. Many thanks.

function select_brush_idx(idx)

    {

    try

        {

        if (idx)

            {

            var d = new ActionDescriptor();

            var r = new ActionReference();

            r.putIndex(stringIDToTypeID("brush"), idx);

            d.putReference(stringIDToTypeID("null"), r);

            executeAction(stringIDToTypeID("select"), d, DialogModes.NO);

            return true;

            }

        return false;

        }

    catch (e) { return false; }

    }

 

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 ,
Mar 20, 2023 Mar 20, 2023

Copy link to clipboard

Copied

Any Photoshop user could remove, rename, change, … the default Brushes so I suspect the reliable way to make sure the selected Brush is the one you want would be 

• to load an abr each time (and then remove it again) for sampled Brushes or

• create the Brush anew in the case of the basic Brushes. 

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