JScript LayeredImage

LayeredImage is an interface wrapper accessible as a property of the Document object and can be used to access layers in a layered image. The individual layers can be obtained as standalone documents and other interface wrappers (such as the RasterImage interface) can be used to work with them.

The Context global object can be a used to access the layer currently selected in the editor (available since version 2010.1).

Methods and properties

New in version 2010.1:

speech bubble iconRecent comments

user iconPAEz on October 20th 2013 0

Could you please supply a simple example, I dont seem to be able to do this. I thought itd be something like...

var layers=Document.LayeredImage;
Application.MessageBox(layers.Layers(), "", false);

...and it says "layers is not an object or null"

user iconVlasta on October 20th 2013 0

Yes, that is the way, although Layers is a property, so it should be layers.Layers

But it won't work, if you are using the script from one of the predefined locations. That is because before these particular scripts are run, the currently selected layer (and frame if you are working with an animation) is already extracted from the whole document and just that single layer is given to the script as its "Document". Without this approach, the scripts would need to contain the code explicitly extract the current frame and/or layer from the Document. I think that would be too much overhead for people starting with scripts.

If you want have a script that gets access to the whole layered image, you'll have to do a bit of configuration. For example like this:

  • right-click on the middle toolbar (the one with Canvas size, Resample and Watermark) and click on "Configure toolbar" command
  • click on the "plus" icon (Create new command) (it gets selected in the list)
  • switch "Commands" combo (the one next to the list) from "Command list" to "Document operation"
  • switch the "Operation" combo from "No operation" to "JavaScript" (1 step above it) or if you want to display the configuration of the JavaSript before it is run, like the other ops do, set it to "Display configuration", resize the window and then set the internal operation to "JavaScript"

You can give the new button a name and icon of your choice and the Document inside the script will have access to the whole document. That means that typing Document.RasterImage will not work if the document has more than 1 layer - you'll first need to use the GetLayer method to get the layer you want.

user iconPAEz on October 20th 2013 0

That worked a treat!
Thanks heaps for sharing that!

user iconPAEz on November 16th 2013 0

How to create a Layer
Check out this post in the Scripts section....
http://www.rw-designer.com/forum/2709

user icon