Skip to main content
October 5, 2014
Answered

Script for deleting a pattern by name

  • October 5, 2014
  • 3 replies
  • 1790 views

I want to delete a pattern by using its name.

This topic has been closed for replies.
Correct answer c.pfaffenbichler

This might suffice to get an Array of the Patterns’ names.

// get array of patterns’ names;

// based on code by michael l hale;

// 2014, use it at your own risk;

#target "photoshop-70.032"

var ref = new ActionReference();

ref.putProperty(stringIDToTypeID ("property"), stringIDToTypeID("presetManager") );

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

var applicationDesc = executeActionGet(ref);

var presetManager = applicationDesc.getList(stringIDToTypeID("presetManager"));

var patternNames = presetManager.getObjectValue(4).getList(stringIDToTypeID("name"));

var theNames = new Array;

for (m = 0; m < patternNames.count; m++) {

theNames.push(patternNames.getString(m))

};

alert (theNames.join("\n"));

3 replies

akmia51
Inspiring
July 28, 2023
s2t = stringIDToTypeID;
(r = new ActionReference()).putName(s2t('pattern'), 'pattern group name');
(d = new ActionDescriptor()).putReference(s2t('target'), r);
executeAction(s2t('delete'), d, DialogModes.NO);
Abdul karim mia
c.pfaffenbichler
Community Expert
c.pfaffenbichlerCommunity ExpertCorrect answer
Community Expert
October 6, 2014

This might suffice to get an Array of the Patterns’ names.

// get array of patterns’ names;

// based on code by michael l hale;

// 2014, use it at your own risk;

#target "photoshop-70.032"

var ref = new ActionReference();

ref.putProperty(stringIDToTypeID ("property"), stringIDToTypeID("presetManager") );

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

var applicationDesc = executeActionGet(ref);

var presetManager = applicationDesc.getList(stringIDToTypeID("presetManager"));

var patternNames = presetManager.getObjectValue(4).getList(stringIDToTypeID("name"));

var theNames = new Array;

for (m = 0; m < patternNames.count; m++) {

theNames.push(patternNames.getString(m))

};

alert (theNames.join("\n"));

October 7, 2014

Thank so much for your prompt reply.

I am using Photoshop CS3 and i have converted this code to VB.Net, but i am getting error on below line

theNames(cnt) = patternNames.getString(cnt).

Error Message : General Photoshop error occurred. This functionality may not be available in this version of Photoshop.

I think this function is not available in CS3. Would you please guide me on this error.

Thank you.

This is the code that i have converted.

'REM =======================================================

        Dim objApp

        objApp = CreateObject("Photoshop.Application")

        'REM Use dialog mode 3 for show no dialogs

        Dim dialogMode

        dialogMode = 3

        Dim desc5

        desc5 = CreateObject("Photoshop.ActionDescriptor")

        Dim ref1

        ref1 = CreateObject("Photoshop.ActionReference")

        Call ref1.PutProperty(objApp.StringIDToTypeID("property"), objApp.StringIDToTypeID("presetManager"))

        Call ref1.PutEnumerated(objApp.charIDToTypeID("capp"), _

                                objApp.charIDToTypeID("Ordn"), _

                                objApp.charIDToTypeID("Trgt"))

        Dim applicationDesc = objApp.executeActionGet(ref1)

        Dim presetManager = applicationDesc.getList(objApp.stringIDToTypeID("presetManager"))

        Dim patternNames = presetManager.getObjectValue(4).getList(objApp.stringIDToTypeID("name"))

        Dim theNames(patternNames.count) As String

        For cnt As Integer = 0 To patternNames.count

            theNames(cnt) = patternNames.getString(cnt)

        Next

        MessageBox.Show(String.Join(",", theNames))

c.pfaffenbichler
Community Expert
Community Expert
October 7, 2014

I work on Macintosh (so no VB) and don’t have CS3 installed anymore, so I’m afraid I cannot help you troubleshoot the issue.

Does the JavaScript code itself error out, too?

c.pfaffenbichler
Community Expert
Community Expert
October 6, 2014

With "PresetLister.js" from xbytors’s xtools you can get a list of the patterns’ names and from that determine the index of the one you want to remove, then use the index in the Action Manager code (as recorded with ScriptingListener.plugin).

xtools