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.
I've gone over your script: This might help:
All the changes are in the last couple of lines. To get the value of the edittext (string) you need something like:
I hope this helps.