12 Replies Latest reply: Oct 7, 2014 8:11 PM by Delete Pattern By Name RSS

    Script for deleting a pattern by name

    Delete Pattern By Name Community Member

      I want to delete a pattern by using its name.

        • 1. Re: Script for deleting a pattern by name
          c.pfaffenbichler Community Member

          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

          • 2. Re: Script for deleting a pattern by name
            c.pfaffenbichler Community Member

            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. Re: Script for deleting a pattern by name
              Delete Pattern By Name Community Member

              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))

              • 4. Re: Script for deleting a pattern by name
                c.pfaffenbichler Community Member

                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?

                • 5. Re: Script for deleting a pattern by name
                  Delete Pattern By Name Community Member

                  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.

                  • 6. Re: Script for deleting a pattern by name
                    c.pfaffenbichler Community Member

                    "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.

                    • 7. Re: Script for deleting a pattern by name
                      Delete Pattern By Name Community Member

                      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.

                      • 8. Re: Script for deleting a pattern by name
                        c.pfaffenbichler Community Member

                        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.

                        • 9. Re: Script for deleting a pattern by name
                          Delete Pattern By Name Community Member

                          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.

                          • 10. Re: Script for deleting a pattern by name
                            c.pfaffenbichler Community Member

                            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
                            • 11. Re: Script for deleting a pattern by name
                              Delete Pattern By Name Community Member

                              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.

                              • 12. Re: Script for deleting a pattern by name
                                Delete Pattern By Name Community Member

                                Hello Sir,

                                 

                                I tried your solution and it's working perfectly.

                                 

                                Thank you very much. I really appreciate your help.