Delete Tool Preset by Name

Photoshop Script Snippets - Note: Full Scripts go in the Photoshop Scripts Forum

Moderators: xbytor, DavideBarranca, Paul MR

weipai

Delete Tool Preset by Name

Postby weipai » Sat Oct 26, 2013 1:20 am

Here's a function that will delete a tool preset by name and do so without selecting the preset.
Code: Select all
//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 {}
        }
    }



teslaball
Posts: 7
Joined: Wed Jan 25, 2017 2:32 pm

Re: Delete Tool Preset by Name

Postby teslaball » Fri Aug 25, 2017 5:23 pm

Hello,
I have tried to implement the code in hostscript.jsx and still does not work. And does getObjectValue(7) is a preset numbered 7th in order, and what if it is 10th, will it still be deleted?
Please help me on this because I am lost.
By the way I know it is old post, but it's worth to be here, especially if someone answers my question.
Thanks

User avatar
txuku
Posts: 43
Joined: Thu Jan 01, 1970 12:00 am
Contact:

Re: Delete Tool Preset by Name

Postby txuku » Sat Aug 26, 2017 6:40 am

Bonjour

You create a new predefined form and copy its name
You paste this name into the script
Line 2

Code: Select all

DeleteToolPreset ("Brush tool test0 2") // "test0") // "Air Brush");



And an alert line 14

Code: Select all

alert (index)

That works well !

teslaball
Posts: 7
Joined: Wed Jan 25, 2017 2:32 pm

Re: Delete Tool Preset by Name

Postby teslaball » Sat Aug 26, 2017 9:46 pm

Hi txuku,
Thanks for your answer, is this what you mean?
P.S. I placed dashes in the code where I made changes according to your answer so you can easily find them:

Code: Select all

//usage:
deleteToolPreset("MyBrush"); ------

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){
            alert(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 {}
        }
    }

User avatar
txuku
Posts: 43
Joined: Thu Jan 01, 1970 12:00 am
Contact:

Re: Delete Tool Preset by Name

Postby txuku » Sun Aug 27, 2017 7:41 am

Bonjour

I remove the new forms I have created by means of this function !

Is not that your case? :)

teslaball
Posts: 7
Joined: Wed Jan 25, 2017 2:32 pm

Re: Delete Tool Preset by Name

Postby teslaball » Tue Aug 29, 2017 1:44 pm

txuku wrote:Bonjour

I remove the new forms I have created by means of this function !

Is not that your case? :)


Hi txuku,
I am totally lost now, please if you feel like editing the above code so I can understand exactly what you mean.
Thank you

User avatar
txuku
Posts: 43
Joined: Thu Jan 01, 1970 12:00 am
Contact:

Re: Delete Tool Preset by Name

Postby txuku » Tue Aug 29, 2017 3:36 pm

Bonjour

What is the name of the new forms you create in English ?

teslaball
Posts: 7
Joined: Wed Jan 25, 2017 2:32 pm

Re: Delete Tool Preset by Name

Postby teslaball » Wed Aug 30, 2017 5:46 pm

Hi,
I actually messed something up in main.js and corrected the problem, actually the solution is to uncomment line 2 and everything is working fine now. Thanks again txuku, you helped me alot as I really understand now what you wanted to tell me all the time. My apollogies.

User avatar
txuku
Posts: 43
Joined: Thu Jan 01, 1970 12:00 am
Contact:

Re: Delete Tool Preset by Name

Postby txuku » Wed Aug 30, 2017 6:10 pm

:D


Return to “Photoshop Scripting: Code Snippets”

Who is online

Users browsing this forum: No registered users and 1 guest