JScript LayeredImage

Log-in or register.

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

  • unit Layers (get) - returns number of layers.
  • object GetLayer(uint index) - returns the layer at given index as document.
  • void MoveLayer(uint index, int under) - moves layer at given index under the given layer (or to the top if under is set to -1).
  • void DeleteLayer(uint index) - deletes layer at given index.
  • void CreateLayer(int under, object configuration, string builder (optional)) - uses a configuration object created by the CreateWizard method of the Application global object. The wizard used to create the new layer is selected when creating the configuration object. (This method was updated in version 2010.1; older syntax is not supported anymore.)
  • void ImportLayer(int under, string path) - loads a document from file and creates a new layer from the document.
  • void CopyToLayer(int under, object document, bool convertToRaster) - creates a new layer from a copy of the given document. The convertToRaster parameter is optional and defaults to false. If set to true, the source document will be converted to a plain raster layer. This means that if document was a layered image, it will be merged to a single layer and then inserted, the source remains untouched (convertToRaster is supported since version 2010.1).
  • uint sizeX (get) - width of the image.
  • uint sizeY (get) - height of the image.
  • uint sizeZ (get) - depth of the image.
  • uint sizeW (get) - size of the 4-th dimension of the image.

New in version 2010.1:

  • string GetLayerName(uint index);
  • void SetLayerName(uint index, string name);
  • object GetIndicesFromState(object context, string state) - returns array of indices of selected layers.
  • void PutIndicesToState(object context, string state, object selectedItems) - selectedItems may be a single index or an array.

Recent comments

user icon PAEz contributing user on October 20th 2013

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 icon Vlasta site administrator on October 20th 2013

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 icon PAEz contributing user on October 20th 2013

That worked a treat!
Thanks heaps for sharing that!

user icon PAEz contributing user on November 16th 2013

How to create a Layer
Check out this post in the Scripts section....

user icon Anonymous
What about ICL files?
I wish there were...