8 Replies Latest reply on Jul 2, 2012 12:38 PM by jacobolus

    A simple Photoshop Scripting solution.

    intacop

      Hello,

       

      I'm trying to do something very repetitive but very simple in Photoshop CS6, I've tried to record the task in actions but it doesn't work. So i've turned to photoshop scripting. All I am trying to do is make a line of brushstroke marks that are seperated by exactly 6 pixels. I want the line to consist of 400 marks. Can anyone provide some code I can execute that will do this? I would prefer Javascript since I am familiar with it.

       

      P.S. I know its rude to have other people do my work, but the Javascript Photoshop Reference is very long, and I'll probably never need to use Photoshop scripting again. I would think there is a simple solution though.

       

      Thankyou

        • 1. Re: A simple Photoshop Scripting solution.
          jacobolus

          I wouldn’t do this through scripting. Instead, adjust the "spacing" property of your brush settings so that each mark will be 6 pixels apart. Then there are two ways to make the marks: either just click at the beginning and shift-click at the end of your desired line, or else create a line using the pen tool, and then use "stroke path" to make the marks along it.

          • 2. Re: A simple Photoshop Scripting solution.
            intacop Level 1

            I did indeed think of that, but photoshop adjusts the spacing by a precentage, not a pixel amount. Is there a way to calculate a pixel amount from the percentage? If there is then it would be alot faster. If not, then I would think a simple loop in PS scripting could get the job done.

            • 3. Re: A simple Photoshop Scripting solution.
              intacop Level 1

              I just experimented more with the spacing property and found that the percentage is based off the brush size which IS based off of pixels. If the brush size I'm using is 30px, I set to spacing to 20% to get 6 pixels. What if I have an ugly brush size like 18? That would give me a percentage of 33.333333333333333333 and so on. This isn't far from exact, but after 400 marks it adds up.

              • 4. Re: A simple Photoshop Scripting solution.
                jacobolus Level 1

                Is this a one-off, or do you need to do it many times? To do it just once, I’d just make a single brush mark, then duplicate the layer, move it 6 pixels, and merge down. Then I would duplicate the layer, move 12 pixels, and merge. Duplicate the layer, move 24 pixels, and merge. move 48 pixels. move 96 pixels. move 192 pixels. And then possibly add another couple brush strokes at the end.

                • 5. Re: A simple Photoshop Scripting solution.
                  Michael L Hale Level 5

                  There is not a simple scripting solution because a brush stroke can be scripted directly. I can think of several workarounds, two of which jacobolus has already suggested.

                   

                  A new suggestion would be to try creating a path and then stoke the path with your brush. If that looks like you want it a script could then move the path 6 pixels and stroke it again. This has the advantage of not needing to create new layers and merge so should be faster. The disadvantage is the stoked path may not look the way you want.

                   

                  If that doesn't work or you don't like that approach, I agree with the setting the spacing as a percentage of the brush size. All the stokes are made at one time and your done.

                   

                  If you don't like that one need to do this more that once I would suggest that instead of merging down after each dupe you create an action that dupe the brush layer and moves it six pixels. The create another action that play the dupe'n'move action as many times as you need. You can also add your choice of how to merge to that last action if wanted.

                  • 6. Re: A simple Photoshop Scripting solution.
                    Paul Riggott Level 6

                    Another option would be to record the brush stroke as this now possible in CS6, then try to convert the action to javaScript.

                    N.B. ScriptListener should be turned off first.

                    • 7. Re: A simple Photoshop Scripting solution.
                      Muppet Mark Level 5

                      define a pattern with a brush dab in it plus 3 pixels either side… ( edit: resize canvas then ) make pattern fill layer…?

                      • 8. Re: A simple Photoshop Scripting solution.
                        jacobolus Level 1

                        Another option would be to record the brush stroke as this now possible in CS6, then try to convert the action to javaScript.

                        This might work, but I think it could be tricky. A single click of a simple brush created a 60 kilobyte opaque and undocumented "raw data" blob in the resulting action. Reverse engineering the format could be difficult.

                         

                        Easier would be to record an action of a single brush click, and then make a script that incorporated a "play action" step.