Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Looking for help with Photoshop javascript (changing variables))

    Hi,

    I'm very new to using javascript to program Photoshop, and was looking for some help with changing the variables in an action.

    The basic end result I'm looking for (in laymens terms) is:

    Set variables
    Perform action
    Change variables (iteratively, ie a=a+1)
    Repeat until condition met (ie, after 100 iterations, the script would end).

    I used a script that converts Photoshop actions to Javascript, so I have this as a base:

    Code:
     function step1(enabled, withDialog) {
        if (enabled != undefined && !enabled)
          return;
        var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
        var desc1 = new ActionDescriptor();
        desc1.putInteger(cTID('0001'), 215);
        desc1.putInteger(cTID('0002'), 172);
    etc etc (goes through many other variables)
        executeAction(sTID('Flaming Pear'), desc1,
    I've put the properties that would need to become variables in red. I have edited out a bunch of lines in this post as these seem to be the significant ones in terms of what I need to do (obviously keeping them in the script itself!).

    Other than that I think that's all I need to know for now - just that little thing would enhance my workflow no end.

    Also, I'm a graphic designer so if anyone would be interested in doing some skillshare or work swap - I'd be happy to provide help and service with graphics in exchange for small tidbits about javascript.

    Cheers,
    Jonathan

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,355
    Thanks
    11
    Thanked 558 Times in 551 Posts
    Although I've quite a lack of PS Javascript knowledge you should generally be able to declare global variables for this. Global variables are usually defined outside of functions and will then be available inside all the functions.

    e.g.
    Code:
    var count001 = 215;
    var count002 = 172;
    
    function step1(enabled, withDialog) {
        ...
        desc1.putInteger(cTID('0001'), count001);
        desc1.putInteger(cTID('0002'), count002);
        ...
        count001 = count001 + 1;  // change the values for use in next function
        count002 = count002 + 1;
    }


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •