Accessibility
Adobe
Sign in Privacy My Adobe

Fireworks Automation

Adobe Exchange: The new way to discover and install plug-ins, extensions and content for the Creative Suite. Get it now

Hierarchical Layer Copy

By MayurMundada February 26, 2009
1,266 Downloads

Rating = 22 votes


Copy heirarchical layers without loosing the layer heirarchy. Usage: 1. Select the layer you want to copy. 2. Select Layer Copy from Commands -> Document menu. 3. Switch to document were you want to copy the layer heirarchy 4. Select Layer Paste from Commands -> Document menu. Known Limitation: - If resolution of both the documents are different then resampling is not done. - Do not close the source document or even change the page in source document. - Do not use this command across pages of same document. - Layer Hierarchy is pasted at center of the document. - Do not use this command for Web Layers.

SUPPORT INFORMATION
Not available

UI Access:
Menu Access : Commands -> Document -> Layer Copy. Commands -> Document -> Layer Paste


Additional extension information

Author: MayurMundada
Author website: Not available
Date published: February 26, 2009
Approval: None
Browsers: Internet Explorer ALL
Required product(s): Fireworks CS3
Compatible product(s): Fireworks CS3, CS4

Reviews

1-3 of 3 reviews | Show all reviews


IngoH 11-Aug-11 Rating = 1

Copy Layers doesn´t work with Fireworks CS 5:
Pasting a Layer causes the "ERROR: -2147216303"

jelaplan 16-Dec-09 Rating = 3

After playing with this a bit, I found it has a few bugs. I left out the src and dest parameters of copyLayer in the recursive call. I also forgot to get the new DOM for the new Page and so it did some funky things. I think this is fixed now.

try{

/**
* Copy a Layer
* @param elems = Array of elements inside a layer which also include sublayers.
*/
function copyLayer(elems, srcDOM, destDOM)
{
alert("copyLayer 1");
fw.selection = null;
srcDOM.makeActive();
fw.selection = elems;
if(fw.selection.length != 0)
{
srcDOM.clipCopy();
destDOM.makeActive();
destDOM.clipPaste("do not resample", "vector");
}

for(var i = 0 ; i < elems.length; i++)
{
if(elems[i].isLayer)
{
var parentLayerNum = destDOM.currentLayerNum;
destDOM.addNewSubLayer(destDOM.currentLayerNum ,null,false);
destDOM.setLayerName(-1,elems[i].name);
var childLayerNum = destDOM.currentLayerNum;
destDOM.reorderLayer(childLayerNum, parentLayerNum, false, i, 2);
copyLayer(elems[i].elems, srcDOM, destDOM);
if(!elems[i].frames[frameNum].visible) destDOM.setLayerVisible(-1, -1, false, false);
if(elems[i].frames[frameNum].locked) destDOM.setLayerLocked(-1, -1, true, false);
destDOM.currentLayerNum = parentLayerNum;
}
}
}

function createNewLayer(srcDOM, destDOM)
{
// Create a layer in destination
destDOM.addNewLayer(srcDOM.layers[layerNumToCopy].name, false);
destDOM.setLayerName(-1, srcDOM.layers[layerNumToCopy].name);
}

function main()
{
// ----------------------------- Copy to New Doc ----------------------------------
if(!origDOM.isValid) throw "Source document not found";

var firstDOM = fw.getDocumentDOM();
var secondDOM = fw.createFireworksDocument({x:firstDOM.width,y:firstDOM.height}, {pixelsPerUnit:72,units:"inch"}, "#ffffff");

createNewLayer(firstDOM, secondDOM);
copyLayer(firstDOM.layers[layerNumToCopy].elems, firstDOM, secondDOM);

// ----------------------------- Copy Back to Orig DOC ----------------------------------
secondDOM.makeActive();
var layerNumToCopy2 = secondDOM.currentLayerNum;
fw.selection = null;

var np = prompt("Enter the Page num. Enter null to cancel:","0"); // Second message box
if (np == null || np == "null")
{
return
}

firstDOM.makeActive();
firstDOM.changeCurrentPage(np);

firstDOM = fw.getDocumentDOM();

createNewLayer(secondDOM, firstDOM);
copyLayer(secondDOM.layers[layerNumToCopy2].elems, secondDOM, firstDOM);
fw.closeDocument(secondDOM, false)
}
main();

}catch(e){alert("ERROR: " + e);}

jelaplan 16-Dec-09 Rating = 3

The limitation about copying to other Pages in a doc is unfortunate. This is really where this would appear to shine because I traditionally have divided my documents into layers but to move into use of Pages, I want to copy layers to other pages.

I found a workaround to do this. I create a new document, copy the layer to that document and then copy it back to the original document and put it on another Page. This solution isn't ideal because I have to prompt for a Page number but it does the job. I'll probably add a feature to delete the original layer because I'm really looking to move layers rather than copy them. My code follows.

try{

/**
* Copy a Layer
* @param elems = Array of elements inside a layer which also include sublayers.
*/
function copyLayer(elems, srcDOM, destDOM)
{
fw.selection = null;
srcDOM.makeActive();
fw.selection = elems;
if(fw.selection.length != 0)
{
srcDOM.clipCopy();
destDOM.makeActive();
destDOM.clipPaste("do not resample", "vector");
}

for(var i = 0 ; i < elems.length; i++)
{
if(elems[i].isLayer)
{
var parentLayerNum = destDOM.currentLayerNum;
destDOM.addNewSubLayer(destDOM.currentLayerNum ,null,false);
destDOM.setLayerName(-1,elems[i].name);
var childLayerNum = destDOM.currentLayerNum;
destDOM.reorderLayer(childLayerNum, parentLayerNum, false, i, 2);
copyLayer(elems[i].elems);
if(!elems[i].frames[frameNum].visible) destDOM.setLayerVisible(-1, -1, false, false);
if(elems[i].frames[frameNum].locked) destDOM.setLayerLocked(-1, -1, true, false);
destDOM.currentLayerNum = parentLayerNum;
}
}
}

function createNewLayer(destDOM)
{
// Create a layer in destination
destDOM.addNewLayer(srcDOM.layers[layerNumToCopy].name, false);
destDOM.setLayerName(-1, srcDOM.layers[layerNumToCopy].name);
}


// ----------------------------- Copy to New Doc ----------------------------------
// Main : index comes from script Layer Copy
// JEL: this relies on running Layer Copy which creates this variable.
if(!origDOM.isValid) throw "Source document not found";

var firstDOM = origDOM;
var secondDOM = fw.createFireworksDocument({x:firstDOM.width,y:firstDOM.height}, {pixelsPerUnit:72,units:"inch"}, "#ffffff");

createNewLayer(secondDOM);
copyLayer(firstDOM.layers[layerNumToCopy].elems, firstDOM, secondDOM);

// ----------------------------- Copy Back to Orig DOC ----------------------------------
secondDOM.makeActive();
var layerNumToCopy2 = secondDOM.currentLayerNum;
fw.selection = null;

var np = prompt("Enter the Page num:","0"); // Second message box
firstDOM.makeActive();
firstDOM.changeCurrentPage(np);

createNewLayer(firstDOM);
copyLayer(secondDOM.layers[layerNumToCopy2].elems, secondDOM, firstDOM);
fw.closeDocument(secondDOM, false)

}catch(e){alert("ERROR: " + e);}


Add a review

(+) Please log in to submit a review