Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


executeAction fails on delete tool preset

Explorer ,
Dec 18, 2016 Dec 18, 2016

Copy link to clipboard

Copied

I've recorded a script using ScriptListener to delete a tool preset:

var idDlt = charIDToTypeID( "Dlt " );

    var desc6 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref6 = new ActionReference();

        var idtoolPreset = stringIDToTypeID( "toolPreset" );

        ref6.putIndex( idtoolPreset, 1 );

    desc6.putReference( idnull, ref6 );

executeAction( idDlt, desc6, DialogModes.NO );

If I run this script either in ExtendScript Toolkit or directly from Photoshop I get an error on the executeAction, saying that the functionality may not be available in this version of Photoshop.  I've also tried to delete the tool preset by name and I get the same error.  The executeAction fails whether or not 'Current Tool Only' checkbox is ticked.

A similar script works fine for deleting brushes.

I've tested this on CC 2017 and CS6

Is this a bug in Photoshop ... and if so, is there a workaround?

Thanks.

TOPICS
Actions and scripting

Views

536

Likes

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 1 Correct answer

Explorer , Dec 19, 2016 Dec 19, 2016
Actually one way around the performance issue on ztggizgiz script (if one wishes to delete many tool presets) is to pass an array of tool presets to the function and then go through the presets in reverse order, so that there is no need to get the list of presets every time:function deleteToolPresets(toolPresets){      var ref = new ActionReference();      ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );      var appDesc = executeActionGet(ref);      v...

Likes

Translate

Translate
Advocate ,
Dec 18, 2016 Dec 18, 2016

Copy link to clipboard

Copied

 

//https://www.ps-scripts.com/viewtopic.php?t=16452

//usage:

//deleteToolPreset("Air Brush");

 

function deleteToolPreset(name){

    var ref = new ActionReference();

    ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

    var appDesc = executeActionGet(ref);

 

    var pmList = appDesc.getList(stringIDToTypeID("presetManager"));

    var nameList = pmList.getObjectValue(7).getList(charIDToTypeID('Nm  '));

 

    for (var index = 0; index < nameList.count; index++){

        if (nameList.getString(index) == name){

            index++;

            var idDlt = charIDToTypeID( "Dlt " );

            var desc2 = new ActionDescriptor();

            var idnull = charIDToTypeID( "null" );

            var list1 = new ActionList();

            var ref2 = new ActionReference();

            var idtoolPreset = stringIDToTypeID( "toolPreset" );

            ref2.putIndex( idtoolPreset, index );

            list1.putReference( ref2 );

            desc2.putList( idnull, list1 );

            executeAction( idDlt, desc2, DialogModes.NO );

            break;

            }

        else {}

        }

    }

 

Source: Delete Tool Preset by Name

Likes

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
Explorer ,
Dec 18, 2016 Dec 18, 2016

Copy link to clipboard

Copied

Many thanks! That works perfectly. However it's very slow if there are many tool presets to delete (I need to delete around 300, and this takes minutes).

The recorded script would be much faster if it did work. Any idea why it doesn't work?

Thanks

Robert

Likes

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
Explorer ,
Dec 19, 2016 Dec 19, 2016

Copy link to clipboard

Copied

The script from ztggizgiz works fine by index, so this script works:

            var idDlt = charIDToTypeID( "Dlt " ); 

            var desc2 = new ActionDescriptor(); 

            var idnull = charIDToTypeID( "null" ); 

            var list1 = new ActionList(); 

            var ref2 = new ActionReference(); 

            var idtoolPreset = stringIDToTypeID( "toolPreset" ); 

            ref2.putIndex( idtoolPreset, 1 );                                     // By index

            list1.putReference( ref2 ); 

            desc2.putList( idnull, list1 ); 

            executeAction( idDlt, desc2, DialogModes.NO );

However, deleting by name does not:

          var idDlt = charIDToTypeID( "Dlt " ); 

            var desc2 = new ActionDescriptor(); 

            var idnull = charIDToTypeID( "null" ); 

            var list1 = new ActionList(); 

            var ref2 = new ActionReference(); 

            var idtoolPreset = stringIDToTypeID( "toolPreset" ); 

            ref2.putName(idtoolPreset, "Charcoal Pencil" );           // By name 

            list1.putReference( ref2 ); 

            desc2.putList( idnull, list1 ); 

            executeAction( idDlt, desc2, DialogModes.NO );

Unfortunately I need to delete by name and although ztggizgiz's script does that fine, it's too slow.

Any ideas why deleting by name doesn't work?

Thanks

Robert

Likes

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
Explorer ,
Dec 19, 2016 Dec 19, 2016

Copy link to clipboard

Copied

Actually one way around the performance issue on ztggizgiz script (if one wishes to delete many tool presets) is to pass an array of tool presets to the function and then go through the presets in reverse order, so that there is no need to get the list of presets every time:

function deleteToolPresets(toolPresets)

    var ref = new ActionReference(); 

    ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 

    var appDesc = executeActionGet(ref); 

    var pmList = appDesc.getList(stringIDToTypeID("presetManager")); 

    var nameList = pmList.getObjectValue(7).getList(charIDToTypeID('Nm  ')); 

     for (var index = nameList.count-1; index >0 ; index--)

    { 

        var toolPreset = nameList.getString(index);

  

        for(var i = 0; i< toolPresets.length; i++)    

        {

                if (toolPreset == toolPresets)

                { 

                    var idDlt = charIDToTypeID( "Dlt " ); 

                    var desc2 = new ActionDescriptor(); 

                    var idnull = charIDToTypeID( "null" ); 

                    var list1 = new ActionList(); 

                    var ref2 = new ActionReference(); 

                    var idtoolPreset = stringIDToTypeID( "toolPreset" ); 

                    ref2.putIndex( idtoolPreset, index+1 ); 

                    list1.putReference( ref2 ); 

                    desc2.putList( idnull, list1 ); 

                    try   {executeAction( idDlt, desc2, DialogModes.NO ) }

                    catch (e) {}

                    break;

                } 

                else {} 

        }

    }

}

Thanks for you help!

Robert

Likes

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
Advocate ,
Jul 17, 2021 Jul 17, 2021

Copy link to clipboard

Copied

how to script delete a named default tool

I saw it on the forum and did not find anything

I tried to do this via Plug-in ScriptingListener
but it does not memorize the name

 

AAR.jpg

Likes

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 Community Professional ,
Jul 17, 2021 Jul 17, 2021

Copy link to clipboard

Copied

Script Listener logs manual deletetion of Tools by Preset Manager.

Check the name with given index and delete those you don't need.

And do not say there are no such topics, because there are A LOT.

Show to us how you tried to find them and failed: presetManager

Likes

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
Advocate ,
Jul 17, 2021 Jul 17, 2021

Copy link to clipboard

Copied

Kukurikus

 

Thank you for your availability
this is a link where you can delete a preset
but I have to do it manually
I would like to do it automatically

Delete default tool presets 

 

if I do it via script listener
I get this code

var idDlt = charIDToTypeID ("Dlt");
var desc27 = new ActionDescriptor ();
var idnull = charIDToTypeID ("null");
var ref12 = new ActionReference ();
var idtoolPreset = stringIDToTypeID ("toolPreset");
ref12.putIndex (idtoolPreset, 4);
desc27.putReference (idnull, ref12);
executeAction (idDlt, desc27, DialogModes.NO);

but that's not good for me
instead of number 4 I would need the name of the preset

Likes

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 Community Professional ,
Jul 17, 2021 Jul 17, 2021

Copy link to clipboard

Copied

The code you pasted is malfunctional. What is that: "Dlt"?

 

I left you link to posts where you can check the name of indexed tool preset item. Just rewrite one of them and delete with a code you pasted (after you correct it) the Tool Preset by index.

Likes

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
Advocate ,
Jul 17, 2021 Jul 17, 2021

Copy link to clipboard

Copied

Kukurikus

now take a look at the link above

 

thanks for your help

Likes

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 Community Professional ,
Jul 17, 2021 Jul 17, 2021

Copy link to clipboard

Copied

The link you used in your post? I clicked it again and I don't understand what else should I look in open thread? You may also by the script delete "Deafult Tool Presets.tpl" from:

 

"C:\Program Files\Adobe\Adobe Photoshop 2021\Required"

 

...and load other (non-default) presets if you can't use given hints.

Likes

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
Advocate ,
Jul 17, 2021 Jul 17, 2021

Copy link to clipboard

Copied

OK! I got it

Likes

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 Community Professional ,
Jul 17, 2021 Jul 17, 2021

Copy link to clipboard

Copied

If I understand correctly, then try it

 

var nm = "Your tool Preset Name"

var d = new ActionDescriptor();
var r = new ActionReference();
r.putName(stringIDToTypeID("toolPreset"), nm);
d.putReference(stringIDToTypeID("null"), r);
executeAction(stringIDToTypeID("select"), d, DialogModes.NO);

var d = new ActionDescriptor();
var r = new ActionReference();
r.putName(stringIDToTypeID("toolPreset"), nm);
d.putReference(stringIDToTypeID("null"), r);
executeAction(stringIDToTypeID("delete"), d, DialogModes.NO);

 

 

Likes

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
Advocate ,
Jul 18, 2021 Jul 18, 2021

Copy link to clipboard

Copied

Mr. r-bin
You are always the best
Thank you for your help.

Likes

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 Community Professional ,
Jul 18, 2021 Jul 18, 2021

Copy link to clipboard

Copied

LATEST

Why did you not use the one of threads I linked you to where you have shown how to get name from indexed preset? What was problem? Btw. what did you mean by 'OK! I got it'?

 

Ps. I asked you what you did to find how to delete tool preset, and you did not answer. You want others to help you because you don't want to make little effort yourself to do simple task. Was that hard to use in search box 'delete toolPreset'. What keywords you used?

Likes

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