2

First off, I'm on a desktop with OS X 10.9 & a macbook with OS X 10.10 with the latest version of Photoshop & ESTK. Which as of right now is: Photoshop CC 2015529.r.88 x64, ESTK 4.0.0.1 - ExtendedScript 4.5.5 & ScriptUI 6.2.2. Results are the same on either system.

In short, my problem isn't with setting the variable itself. It is with the value in the variable being used properly later in the script. Including passing the variable from on to another.

e.g.

    var dflt = 16
    var z = dflt

Primarily what I am trying to do is pass a numerical value from user input to variable. Then have that value used accurately in another part of the script. Everything works perfectly when the variable is defined in the script outside of user input. Soon as user input is added the variable can be repeated back accurately.

Such as using:

    alert('The variable is currently set to: ' + value);

However the results aren't as expected when run in photoshop.

What the script does or is supposed to do. Is take the active layer & cut the entire thing into a predefined grid. Each cut being placed on it's own layer. As I've already said. When the grid is predefined everything is flawless. But when user input is added. The grid is completely skewed. Only the first cell/layer of the grid is accurate. Everything else gets mosaiced strangely, though predictably.

I have tried using:

document.getElementById("numb")

Which works fine in Chrome & Firefox. But crashes when run in Photoshop or ESTK.

prompt

Which provides the skewed/mosaiced results.

As well as a dialog window:

    // begin dialog layout
    var GridLayersDialog = new Window('dialog');
    GridLayersDialog.text = 'Grid To Layers';
    GridLayersDialog.frameLocation = [70, 70];
    GridLayersDialog.alignChildren = 'center';


    GridLayersDialog.GridSizePnl = GridLayersDialog.add('panel', [2, 2, 200, 70], 'Grid Size');
    GridLayersDialog.GridSizePnl.add('statictext', [10, 16, 79, 48], 'Dimensions: ');
    GridLayersDialog.GridSizePnl.aspectDimension = GridLayersDialog.GridSizePnl.add('edittext', [85, 13, 120, 34], dfltCs, {name:'cellSize'});
    GridLayersDialog.GridSizePnl.aspectDimension.helpTip = 'Width & Height in pixels';


    var buttons = GridLayersDialog.add('group');
    buttons.orientation = 'row';
    var okBtn = buttons.add('button');
    okBtn.text = 'OK';
    okBtn.properties = {name: 'ok'};
    var cancelBtn = buttons.add('button');
    cancelBtn.text = 'Cancel';
    cancelBtn.properties = {name: 'cancel'};


    // display dialog and only continues on OK button press (OK = 1, Cancel = 2)
    if (GridLayersDialog.show() == 1) {
        cellSize = String(GridLayersDialog.GridSizePnl.cellSize.text); etc...

Which also provides skewed results.

The original, 'unflawed', script is as follows:

    // Size of cell in pixels
    var cellSize = 16;

    // Set the ruler type
    if (app.preferences.rulerUnits != Units.PIXELS)
    {
        app.preferences.rulerUnits = Units.PIXELS;
    }

    var layerRef = docRef.activeLayer;

    for (y = 0; y<docRef.height; y+=cellSize)
    {
        for (x = 0; x<docRef.width; x+=cellSize)
        {
            //activate the original layer
            docRef.activeLayer = layerRef;
            //make the selection
            docRef.selection.select(Array (Array(x, y), Array(x, y+cellSize), Array(x+cellSize,y+cellSize), Array(x+cellSize,y)), SelectionType.REPLACE, 0, false);

            //copy the selection
            docRef.selection.copy();
            //create and paste new layer
            docRef.artLayers.add();
            docRef.paste();
            }
        }
    }

I haven't tried making a predefined list, dropdown or otherwise. Nor have I setup a slider, check boxes or any similar alternative. As none are ideal. I hope to be able to set the cell size with a typable input field.

I'm not sure if this is expected behavior, a flaw in my code or a bug that needs reporting. Any help or insight as to why this is happening would be greatly appreciated.

This is getting a little long so rather than post my script in the text field. The current iteration of the script in it's entirety is available here. For those that wish to see it.

RobC
  • 22,977
  • 20
  • 73
  • 80
Terus
  • 203
  • 3
  • 12
  • New version of Photoshop released today. Currently updating, will inform if update resolves my issue. – Terus Jun 16 '15 at 23:11
  • The issue is still present in Photoshop CC 2015529.r.88 on both OS X 10.9 & 10.10. Along with some incompatibilities with OS X 10.9.1. Which may force me to update. – Terus Jun 17 '15 at 00:24
  • Well as a mediocre work around, I threw together a rough AppleScript that replaces the predefined value from the original script with user input. It's a touch messy, invoking an action in order to properly execute the .js file. As it's a touch convoluted, only works for OS X & is just a quick fix and/or work around. I do not wish to post as an answer. If anyone happens across this & needs the work around. Just ask & I'll do what I can to help. – Terus Jun 20 '15 at 12:58
  • Well the original problem still persists. I've tried everything & nothing works right. As such I have filed a bug report with Adobe. If it isn't a bug this script has beaten me. – Terus Jul 09 '15 at 02:25
  • It has been some time & the problem persists in all CC versions I've tried. Still no solution. Started me thinking it's a feature, not a bug. For the sake of it I tried the script in **CS6 & everything functions as I think it should**. Best I can figure is Adobe did something to their implementation of JS. When they migrated from CS to CC. – Terus Jun 11 '17 at 18:57

1 Answers1

1

I've gone over your script: This might help:

    var dfltCs = 16;

    // begin dialog layout
    var GridLayersDialog = new Window('dialog');
    GridLayersDialog.center();
    GridLayersDialog.text = 'Grid To Layers';
    GridLayersDialog.frameLocation = [70, 70];
    GridLayersDialog.alignChildren = 'center';


    GridLayersDialog.GridSizePnl = GridLayersDialog.add('panel', [2, 2, 200, 70], 'Grid Size');
    GridLayersDialog.GridSizePnl.add('statictext', [10, 16, 79, 48], 'Dimensions: ');
    GridLayersDialog.GridSizePnl.aspectDimension = GridLayersDialog.GridSizePnl.add('edittext', [85, 13, 120, 34], dfltCs, {name:'cellSize'});
    GridLayersDialog.GridSizePnl.aspectDimension.helpTip = 'Width & Height in pixels';
    // Room left for additional data in future update.
    cellSize = String(GridLayersDialog.GridSizePnl.cellSize.text); if (cellSize=="") { cellSize = dfltCs;} // Set user input to variable

    GridLayersDialog.add ("button", undefined, "OK");
    if (GridLayersDialog.show () == 1)
    {
    var v = GridLayersDialog.GridSizePnl.aspectDimension.text;
    alert('The variable is currently set to: ' + v);
    }

All the changes are in the last couple of lines. To get the value of the edittext (string) you need something like:

var v = GridLayersDialog.GridSizePnl.aspectDimension.text

I hope this helps.

Ghoul Fool
  • 6,249
  • 10
  • 67
  • 125
  • Thank you for your time & input. However I already pass the input to variable with the following: **cellSize = String(GridLayersDialog.GridSizePnl.cellSize.text); if (cellSize=="") { cellSize = dfltCs;}** Though your answer made me realize. That I carelessly put it in the wrong place. My problem isn't with setting the variable itself. It is with the value in the variable being used properly in the "Grid Layers" portion of the script, – Terus Jun 16 '15 at 22:32
  • Due to the way the script ran previously. The variable was set by the predefined default. Which also doesn't function properly with the main script. Thanks for helping me to realize the additional flaw. – Terus Jun 16 '15 at 23:24