1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//--not for batch--
// DistributeToNamedLayers.jsf
// This command will take multiple objects and move them to indivual layers
// Copyright (c) 2000 Macromedia. All rights reserved.

// Save the current frame in the document
var curFrameNum = fw.getDocumentDOM().currentFrameNum;

// get the total layers minus the web layer
var numLayers = fw.getDocumentDOM().layers.length-1;  // skip the web layer.

var curLayerNum;

// loop through the current number of layers
for (curLayerNum = numLayers-1; curLayerNum >= 0; curLayerNum--) {
	// get the current layer
	var curLayer = fw.getDocumentDOM().layers[curLayerNum];
	//if layer is locked cannot distribute so continue to next layer.
	if(fw.getDocumentDOM().isMasterPageLayer(curLayerNum) == true || curLayer.frames[curFrameNum].locked == true)
		continue;
	// get the elements on the current layer
	var elements = curLayer.frames[curFrameNum].elements;
	
	// get the number of elements
	var numElements = elements.length-1;
	var i;

	// loop through the number of elements
	for (i=0; i<numElements; i++) {
		// get the current layer number
		if (i==0) fw.getDocumentDOM().currentLayerNum = curLayerNum;
		// add layers for the number of elements
		fw.getDocumentDOM().addNewLayer(null, false);
	}
	// again loop through the number of elements
	for (i=0; i<numElements; i++) {
		// set the current layer
		curLayer = fw.getDocumentDOM().layers[curLayerNum];
		// get the elements on the current layer
		elements = curLayer.frames[curFrameNum].elements;
		// select none
		fw.getDocumentDOM().selectNone();
		// create a new array that will hold the selection
		var sel = new Array();
		// populate the array
		sel[0] = elements[elements.length-2];

		// rename target layer if element has a name
		fw.getDocumentDOM().setLayerName(curLayerNum+i+1, sel[0].name || "");

		// select all of the elements of the array in Fireworks
		fw.selection = sel;
		// move the selection to its new layer
		fw.getDocumentDOM().moveSelectionToLayer(curLayerNum+i+1, false, "none", -1);
	}
}