Copy link to clipboard
Copied
I want to delete a pattern by using its name.
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(stringIDT
Copy link to clipboard
Copied
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).
Copy link to clipboard
Copied
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"));
Copy link to clipboard
Copied
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))
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
I have not tried JS code, because don't know how to do it. Can you please explain what is "name" in below line. And which pattern names list it will give ?
presetManager.getObjectValue(4).getList(objApp.stringIDToTypeID("name")).
So I can change that line and test it again.
Thank you.
Copy link to clipboard
Copied
"name" refers to the names of the patterns.
You can run JavaScript code from ExtendScript Toolkit for testing and subsequently position the jsx file in the appropriate Scripts folder to have it represented in the File > Scripts menu.
Copy link to clipboard
Copied
I downloaded Xtools and installed it. But, it is not allowing me to create .atn file. So I manually changed the path in the XML file and generated .atn file.
Then tried to run Presetmanager.jsx file from photoshop and it gives me an error. xToId function not valid.
Thank you.
Copy link to clipboard
Copied
I don’t understand what you are trying to do.
To get a list of the Patterns’ names the code from post 2 should suffice.
To delete the intended one you should use a for-clause to check for the name and use Action Manager code to delete it.
Copy link to clipboard
Copied
Your code is perfect and it will work to, I tried it, but as i said earlier that i was getting error on below line. It is not allowing to use getString function.
theNames(cnt) = patternNames.getString(cnt)
Error Message : General Photoshop error occurred. This functionality may not be available in this version of Photoshop.
Copy link to clipboard
Copied
I have no clue when it comes to VB but could if be you are trying to use a String as an Array?
Dim theNames(patternNames.count) As String
Copy link to clipboard
Copied
Yes, it is a string array. And, i am storing all pattern names in string array.
Let me try it once again today and I will let you know if i am able to run it.
Thank you very much for your assistance.
Copy link to clipboard
Copied
Hello Sir,
I tried your solution and it's working perfectly.
Thank you very much. I really appreciate your help.
Copy link to clipboard
Copied
s2t = stringIDToTypeID;
(r = new ActionReference()).putName(s2t('pattern'), 'pattern group name');
(d = new ActionDescriptor()).putReference(s2t('target'), r);
executeAction(s2t('delete'), d, DialogModes.NO);