15 Replies Latest reply on Nov 11, 2015 8:32 AM by CuriosC1152

    History Brush Blending Mode

    ian-barber Level 1

      I remember some time ago following a thread on PS-Scripts.com about not been able to access and change the blending mode of the history brush through a script.

       

      Unfortunately, PS-Scripts.com is no longer online and I was wondering if things have changed with regards to changing the History Brush blending mode through a script.

        • 1. Re: History Brush Blending Mode
          StrongBeaver Level 3

          Ps-Scripts.com is dead, did this happen recently, can anyone verify ? If so the only source for scripting in Photoshop is the Adobe communities.

          • 2. Re: History Brush Blending Mode
            JJMack Most Valuable Participant

            I think if you set a tool preset for the history brush with the blending mode you want.  You could use scriptlistener action manager code to select the preset by preset name. The would select the history brush tool with the settings you want.

             

            There are few Photoshop scripting resources on the web. Only a few Photoshop Books will cover Photoshop in any depth.

            Adobe has some documentation on the web over years I have downloaded some of their documents.

            Capture.jpg

            • 3. Re: History Brush Blending Mode
              StrongBeaver Level 3

              The site just abruptly ceased to exist. Thanks for the heads up ian. 

              • 4. Re: History Brush Blending Mode
                ian-barber Level 1

                I have just read elsewhere that unfortunately, the owner of the site Mr Mike Hale passed away which is why I am guessing the site has been taken down.
                although I never met or spoke to Mike, I found some of the information, code snippets and help on his site to be excellent.

                 

                Ian

                • 5. Re: History Brush Blending Mode
                  c.pfaffenbichler Level 9

                  In post 11 xbytor provides a link to an archived version of ps-scripts.com:

                  PS-Scripts.com temporarily suspended?

                  • 6. Re: History Brush Blending Mode
                    CuriosC1152 Level 1

                    I'm having a similar issue – I would like to switch the blend mode of a brush from Normal to Clear.  I know that the shortcuts do that, but my goal is to be able to record the action and since this event is not recordable… here I am asking for help.

                     

                    It would be grate to find a solution or a work around.

                     

                    I've tried:

                    1. Script listener - doesn't work, no event is captured

                    2. Actions - do not record

                    3. and I looked through the reference guide for photoshop JS scripting for sample code that I could rework (I'm no programmer)

                    4. Of course Google search but nothing there

                     

                    The closest thing I found was this: toggle brush mode 'Behind' on/off with keyboard shortcut? But the scrip is no longer available…

                     

                    I was thinking of an alternative… if there's a ways to write a script that executes the keyboard shortcut that may do the trick, but I've not fount any way of doing that with code.

                     

                    Any help would be greatly appreciated.

                     

                    Cheers,

                     

                    C

                    • 7. Re: History Brush Blending Mode
                      JJMack Most Valuable Participant

                      I do not know if this will work or not.  It may.  If you want a script that toggles between two states you need to have a way to know the current state  and if the is not possible to pick a state set that state and set some state indicator that you can test to know the current state.  With a Photoshop scriptt it is possible to set a custom option or record the current state some how.

                       

                      If you have the state indicator you also need to be able to switch states.  As you have found some thing are not  recorded. The scriptlistener does nothing when something can not be recorded. There may also be no DOM interface to switch the state or a standard menu item to switch states.

                       

                      So what can one try?  Often over look is the ability to set some none standard things. What do I mean?  Before I get to that. There is a problem with what you want to do.  For what you want to do in not possible in Photoshop.  While there is a normal blend mode there is no "Clear" blend mode. You would need to write a Plug-in to implement a new feature for Photoshop.    However I believe it would be possible to toggle between to blending mode that are possible.  Often overlook are Presets.   Preset you define/create can be use in Photoshop automation.  The Automation will fail it these name preset have not been added to you Photoshop presets.   You will see that selecting a preset will record in Actions and be recorded by the Scriptlistener.  So you can create a two history brush presets.  "Normal" and "Clear" and use these in your script.  "Clear" would need to set some valid blending mode.

                       

                      Capture.jpg

                      • 8. Re: History Brush Blending Mode
                        CuriosC1152 Level 1

                        Thanks for the replay JJKack,

                         

                        The blend mode "Clear" is available only for brushes an not for layers. 

                         

                        Sadly I'm not a programmer and writing a plug in is definitely out of the scopes of the time I have available for this task.

                         

                        My goal is be able to record my strokes with the action pallet as I'm illustrating.  Unfortunately if I switch the blend mode or change the spacing of a brush that parameter change is not recorded, and when I play it back… well the end result is not what it I would expect.

                         

                        The "Clear" mode is a really handy mode, it practically turns each brush into an eraser, so that one can work in positive and negative shapes.  I could create an eraser tool for every brush but that is really an unusable workaround for my workflow and it still leaves the issue that any other bush adjustment (besides brush size) does not get recorded.

                         

                        Hopefully someone else has a work around that make sense for this.

                        • 9. Re: History Brush Blending Mode
                          SuperMerlin Level 5

                          There are ways of doing this, but depends on the OS.

                          One Windows workaround would be:

                          Download the exe files from http://wikisend.com/download/416666/Brush Blendmodes.zip

                          Unzip and copy the required BlendModes files to your Presets/Scripts folder

                          An example ExtendScript to toggle Normal and Clear

                           

                          #target photoshop;
                          app.bringToFront();
                          
                          
                          var SCRIPTS_FOLDER =  decodeURI(app.path + '/' + localize("$$$/ScriptingSupport/InstalledScripts=Presets/Scripts"));
                          var Normal = new File(SCRIPTS_FOLDER + "/Brush_Normal.exe");
                          var Clear = new File(SCRIPTS_FOLDER + "/Brush_Clear.exe");
                          
                          
                          switch($.getenv("BrushMode")){
                              case null : $.setenv("BrushMode","Clear"); Clear.execute(); break;
                              case "Normal" : $.setenv("BrushMode","Clear"); Clear.execute(); break;
                              case "Clear" : $.setenv("BrushMode","Normal"); Normal.execute(); break;
                          }
                          
                          
                          
                          
                          
                          
                          
                          • 10. Re: History Brush Blending Mode
                            CuriosC1152 Level 1

                            SuperMerlin,

                             

                            Thanks for landing a hand!

                             

                            It looks like what you have there is the ticket!


                            I'm on OSX 10.8.5, is there a way that you could compile the app for MAC or if it's jsx code maybe I could embedded in the script?

                             

                            Cheers,

                             

                            C

                            • 11. Re: History Brush Blending Mode
                              SuperMerlin Level 5

                              I'm afraid the compiled code will not be able to re-compile on a Mac.

                              You might be able to find someone on a Mac site that can write a couple of AppleScripts to send the appropriate codes to Photoshop, these would need to be compiled then they could be called from the JavaScript.

                              Just the following lines would have to be amended for the AppleScript filenames, then it should work.

                              1. var Normal = new File(SCRIPTS_FOLDER + "/Brush_Normal.exe"); 
                              2. var Clear = new File(SCRIPTS_FOLDER + "/Brush_Clear.exe");


                              • 12. Re: History Brush Blending Mode
                                SuperMerlin Level 5

                                Had a quick look and it seems that you can do it with AppleScript.

                                From what I have seen it will be something on the lines of:-

                                Normal Blendmode

                                tell application "Adobe Photoshop CC 2015"
                                tell application "System Events" to keystroke "n" using {shift down, option down}
                                end tell
                                
                                

                                 

                                 

                                Clear Blendmode

                                tell application "Adobe Photoshop CC 2015"
                                tell application "System Events" to keystroke "r" using {shift down, option down}
                                end tell
                                
                                

                                 

                                It should give you a starting point.

                                The AppleScripts might require tweaking to get them to work as I don't have a Mac.

                                • 13. Re: History Brush Blending Mode
                                  JJMack Most Valuable Participant

                                  CuriosC1152 wrote:

                                   

                                  Thanks for the replay JJKack,

                                   

                                  The blend mode "Clear" is available only for brushes an not for layers.

                                   

                                  Well if you want to toggle between the history brush in blend mode normal and a paint brush in clear mode I would think that would be posible using preset for the two brushes.  I did a quick test using two function keys set to two actions that select one of the presets. Seemed to work well.

                                  Capture.jpg

                                  • 14. Re: History Brush Blending Mode
                                    Pedro Cortez Marques Level 3

                                    Give a look to this.

                                    Is it possible to script brush opacity?

                                     

                                    I think you can use this with any brush kind tool. Just create a preset tool (they contain: all brush vars + all tool properties)

                                     

                                    // first, prepare your historybrush tool and use this to save its preset name (or save it directly on the tool properties);
                                    save_preset("AAAA");
                                    
                                    // then, use this wherever you want to get the preset (including belending mode)
                                    app.currentTool = "historyBrushTool"; // select historybrush
                                    select_preset("AAAA");
                                    
                                    // function to create the preset tool
                                    function save_preset(name) {
                                        try {
                                            var desc21 = new ActionDescriptor();
                                            var ref18 = new ActionReference();
                                            ref18.putClass( stringIDToTypeID( "toolPreset" ) );
                                            desc21.putReference( charIDToTypeID( "null" ), ref18 );
                                            var ref19 = new ActionReference();
                                            ref19.putProperty( charIDToTypeID( "Prpr" ), charIDToTypeID( "CrnT" ) );
                                            ref19.putEnumerated( charIDToTypeID( "capp" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
                                            desc21.putReference( charIDToTypeID( "Usng" ), ref19 );
                                            desc21.putString( charIDToTypeID( "Nm  " ), name );
                                            executeAction( charIDToTypeID( "Mk  " ), desc21, DialogModes.NO );
                                        } catch(e) { }
                                    }
                                    // function to select the preset tool
                                    function select_preset(name) {
                                        try {
                                            var desc = new ActionDescriptor();
                                            var ref = new ActionReference();
                                            ref.putName( stringIDToTypeID( "toolPreset" ), name );
                                            desc.putReference( charIDToTypeID( "null" ), ref );
                                            executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO );
                                            ref = null;
                                            desc = null;
                                        } catch(e) { }
                                    }
                                    
                                    • 15. Re: History Brush Blending Mode
                                      CuriosC1152 Level 1

                                      Thanks for all your replays!

                                       

                                      I think I should've started a new thread, as the issue I'm having is more about the brush blending modes and recording the strokes for playback.

                                       

                                      GOAL: record my brush strokes while illustrating and play them back so that can be screen captured

                                      ISSUE: switching brush blending mode is not being captured when recording via actions

                                       

                                      Here's an update on my status. SuperMerlin's suggestion is what came closest to my end goal.

                                       

                                      I've tried that approach and got it to work but I ran into a couple of problems:

                                       

                                      1. When the jsx calls the .app file (.exe on window) the screen flickers as the app executes the code.  When capturing the screen at playback time that will cause a problem not to mention the eye fatigue while working.  I remember (I think) there's some jsx code that freezes the screen until the script has fished running, but I couldn't find any reference on that or if there is a way to run the app in the background… either would solve that problem, which I would really like to achieve. 

                                       

                                      2. The execution of the script is recorded by the action panel but the blending mode does not change at playback. This is infuriating!

                                       

                                       

                                       

                                      Here's the working code up to date:

                                       

                                      In AppleScript then save it as an .app (Brush_Mode_Normal.app)

                                      tellapplication "Adobe Photoshop CC 2015" toactivate
                                      tell application "System Events"
                                        tell process "Photoshop"
                                        keystroke "n" using {shift down, option down}
                                        end tell
                                      endtell
                                      

                                       

                                      In AppleScript then save it as an .app (Brush_Mode_Clear.app)

                                      tellapplication "Adobe Photoshop CC 2015" toactivate
                                      tell application "System Events"
                                        tell process "Photoshop"
                                        keystroke "r" using {shift down, option down}
                                        end tell
                                      endtell
                                      

                                       

                                      Put those two files in /Applications/Adobe Photoshop CC 2015/Presets/Scripts/Apple_Scripts
                                      (I've created a separate folder for the Apple Scripts) but you can put them anywhere you want as long as the directory in the the jsx file matches upPresets/ScriptsPresets/Scripts

                                       

                                      The code works as a switcher between any brush and it's inverse (erases).  All you need to remember is one key combination allocated to the JSX script rather then the 3 keys per blending mode.

                                       

                                      And this is the updated code from SuperMerlin that switches between the two states

                                      #target photoshop;  
                                      app.bringToFront();  
                                        
                                        
                                      var SCRIPTS_FOLDER =  decodeURI(app.path + '/' + localize("$$$/ScriptingSupport/InstalledScripts=Presets/Scripts"));  
                                      var Normal = new File(SCRIPTS_FOLDER + "/Apple_Scripts/Brush_Mode_Normal.app");  
                                      var Clear = new File(SCRIPTS_FOLDER + "/Apple_Scripts/Brush_Mode_Clear.app");  
                                        
                                        
                                      switch($.getenv("BrushMode")){  
                                          case null : $.setenv("BrushMode","Clear"); Clear.execute(); break;  
                                          case "Normal" : $.setenv("BrushMode","Clear"); Clear.execute(); break;  
                                          case "Clear" : $.setenv("BrushMode","Normal"); Normal.execute(); break;  
                                      }