-
Notifications
You must be signed in to change notification settings - Fork 0
/
exportSelectedLayer.jsx
57 lines (44 loc) · 1.16 KB
/
exportSelectedLayer.jsx
1
/*<javascriptresource><name>Export Selected Layer</name><about></about><category>PsScripts</category><enableinfo>true</enableinfo></javascriptresource>*/main();function layerDuplicate(layer) { switch (layer.typename) { case 'ArtLayer': return artLayerDuplicate(layer); break; case 'LayerSet': return layerSetDuplicate(layer); break; default: alert(layer.typename); }}function main() { var doc = activeDocument; var layer = doc.activeLayer; var targetLayer = layerDuplicate(layer); var bounds = targetLayer.bounds; targetLayer.translate(-bounds[0], -bounds[1]); targetLayer.copy(); var newDocRef = app.documents.add(bounds[2], bounds[3], doc.resolution, name, NewDocumentMode.RGB, DocumentFill.TRANSPARENT); newDocRef.paste(); newDocRef.trim(TrimType.TRANSPARENT, true, true, true, true); activeDocument = doc; targetLayer.remove(); activeDocument = newDocRef;}function layerSetDuplicate(layer) { var duppedLayer = layer.duplicate(); return duppedLayer.merge();}function artLayerDuplicate(layer) { var layerset = activeDocument.layerSets.add(); var duppedLayer = layer.duplicate(layerset); return layerset.merge();}