Photoshop scripting: suspendHistory and resizeBoundary conflict

  • 1
  • Problem
  • Updated 4 years ago
  • (Edited)
//create or open any document
//run the script below

//error presents in PS CS3 - CC (win x86)
//also try to comment the line: doc.selection.fill(c);

try { app.activeDocument.suspendHistory("Test", "main()") } catch(e) { alert(e); }

//try { main(); } catch(e) { alert(e); }

function main()
{
var doc = app.activeDocument;

app.preferences.rulerUnits = Units.PIXELS;

var x0 = 10;
var y0 = 10;

var x1 = 21
var y1 = 21;

doc.selection.select(
Array(
Array(x0, y0),
Array(x1, y0),
Array(x1, y1),
Array(x0, y1),
Array(x0, y0)),
SelectionType.REPLACE);

var c = new SolidColor; with (c.rgb) { red = green = blue = 128; }

///////////////////////////////////////////////////////////////////////////////////////
doc.selection.fill(c); // try to comment this line !!!!

doc.selection.resizeBoundary(150, 150, AnchorPosition.MIDDLECENTER);
}
Photo of r-bin

r-bin

  • 24 Posts
  • 1 Reply Like

Posted 4 years ago

  • 1
Photo of Tom Ruark

Tom Ruark, Official Rep

  • 26 Posts
  • 11 Reply Likes
Interesting. I see the same results with or without the fill line. Document with Background layer only and if I use main() directly without the suspendHistory it works with or without.

If i use a document with one layer it doesn't fail with suspendHistory but it doesn't do anything.

I'll have to investigate further. As a workaround you will have to remove your suspendHistory usage for now.
Photo of r-bin

r-bin

  • 24 Posts
  • 1 Reply Like
Thank you fo reply!
But i don`t need a workaround.This is the bug. And developers must know about it.

"resizeBoundary" function somehow wants to go back in histoty when we use suspendHistory.

Example.
Create a new doc. Then in history pallete click to startup snapshot, so to clean history.Then execute the script below.

///////////////////////////////////////////////////////////////////////////
try { app.activeDocument.suspendHistory("Test", "main()") } catch(e) { alert(e); }

function main()
{
var doc = app.activeDocument;

app.preferences.rulerUnits = Units.PIXELS;

var x0 = 10;
var y0 = 10;

var x1 = 21
var y1 = 21;

var n = 0;

doc.selection.select(Array(Array(x0, y0),Array(x1, y0),Array(x1, y1),Array(x0, y1),Array(x0, y0)),
SelectionType.REPLACE);

alert(n++)

app.activeDocument.artLayers.add();

alert(n++)

app.activeDocument.artLayers.add();

alert(n++)

doc.selection.resizeBoundary(150, 150, AnchorPosition.MIDDLECENTER);
}
///////////////////////////////////////////////////////////////////////////

After each alert watch what happens in layers pallete. When script will try to execute resizeBoundary there wil be an error: "The object "previous history state" is not currently available".

–°ool?! :)
Photo of Tom Ruark

Tom Ruark, Official Rep

  • 26 Posts
  • 11 Reply Likes
I would cross post here as well as there are more script writers in that forum.

http://forums.adobe.com/community/pho...

Thanks for the bug report.