mirror of
https://github.com/sbrow/ps.git
synced 2026-02-27 02:51:44 -05:00
Fixed
- close() / quit() Added functionality - setlayervisibility() Made SaveOptions into an enum for better readibility
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
set App = CreateObject("Photoshop.Application")
|
||||
set Doc = App.activeDocument
|
||||
Doc.Close
|
||||
Doc.Close(CInt(wScript.Arguments(0)))
|
||||
@@ -1,32 +1,18 @@
|
||||
//arguments = [ 'F:\\TEMP\\js_out.txt\r\narg\r\nargs\r\n', 'Areas/TitleBackground']
|
||||
var saveFile = File(arguments[0])
|
||||
if(saveFile.exists)
|
||||
saveFile.remove()
|
||||
saveFile.encoding = "UTF8"
|
||||
saveFile.open("e", "TEXT", "????")
|
||||
try {
|
||||
var doc = app.activeDocument
|
||||
var splitPath = arguments[1].split('/')
|
||||
var bottomLayerSet = doc.layerSets.getByName(splitPath[0])
|
||||
for (var i = 1; i < splitPath.length; i++) {
|
||||
try {bottomLayerSet = bottomLayerSet.layerSets.getByName(splitPath[i])}
|
||||
catch (e) {bottomLayerSet = { layers: [bottomLayerSet.layers.getByName(splitPath[i])] }}
|
||||
}
|
||||
saveFile.writeln('[');
|
||||
for (var l = 0; l < bottomLayerSet.layers.length; l++) {
|
||||
var lyr = bottomLayerSet.layers[l]
|
||||
saveFile.write('{"Name":"' + lyr.name + '", "Bounds": [["' + lyr.bounds[0] + '","' +
|
||||
lyr.bounds[1] + '","' + lyr.bounds[2] + '"],["' + lyr.bounds[3] + '"]]}');
|
||||
if (l != bottomLayerSet.layers.length - 1)
|
||||
saveFile.write(',');
|
||||
saveFile.writeln();
|
||||
#include lib.js
|
||||
var stdout = newFile(arguments[0])
|
||||
var set = getLayers(arguments[1])
|
||||
|
||||
stdout.writeln('[');
|
||||
for (var l = 0; l < set.layers.length; l++) {
|
||||
var lyr = set.layers[l]
|
||||
var lyrset = arguments[1].replace(lyr.name, "")
|
||||
stdout.write(('{"Name":"' + lyr.name + '", "Bounds": [[' + lyr.bounds[0] + ',' +
|
||||
lyr.bounds[1] + '],[' + lyr.bounds[2] + ',' +
|
||||
lyr.bounds[3] + ']], "LayerSet": "' + lyrset + '"}').replace(/ px/g, ""));
|
||||
if (l != set.layers.length - 1)
|
||||
stdout.write(',');
|
||||
stdout.writeln();
|
||||
|
||||
}
|
||||
saveFile.writeln(']');
|
||||
} catch (e) {
|
||||
if (e.message.indexOf('User') == -1)
|
||||
alert('ERROR: ' + e.message + ' at ' + e.fileName + ':' + e.line);
|
||||
else
|
||||
throw new Exception('User cancelled the operation');
|
||||
}
|
||||
saveFile.close();
|
||||
stdout.writeln(']');
|
||||
stdout.close()
|
||||
34
scripts/lib.js
Normal file
34
scripts/lib.js
Normal file
@@ -0,0 +1,34 @@
|
||||
// Opens and returns a file, overwriting new data.
|
||||
function newFile(path) {
|
||||
var f = File(path)
|
||||
if(f.exists)
|
||||
f.remove()
|
||||
f.encoding = "UTF8"
|
||||
f.open("e", "TEXT", "????")
|
||||
return f
|
||||
}
|
||||
|
||||
// Returns an array of ArtLayers from a layerSet or an ArtLayer.
|
||||
function getLayers(path) {
|
||||
try {
|
||||
var doc = app.activeDocument
|
||||
var path = path.split('/')
|
||||
var lyrs = doc.layerSets.getByName(path[0])
|
||||
for (var i = 1; i < path.length; i++) {
|
||||
try {
|
||||
lyrs = lyrs.layerSets.getByName(path[i])
|
||||
} catch (e) {
|
||||
lyrs = { layers: [lyrs.layers.getByName(path[i])] } }
|
||||
}
|
||||
return lyrs
|
||||
} catch (e) {
|
||||
if (e.message.indexOf('User') == -1)
|
||||
alert(err(e));
|
||||
else
|
||||
throw new Exception('User cancelled the operation');
|
||||
}
|
||||
}
|
||||
|
||||
function err(e) {
|
||||
return 'ERROR: ' + e.message + ' at ' + e.fileName + ':' + e.line;
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
Set appRef = CreateObject("Photoshop.Application")
|
||||
|
||||
Do While appRef.Documents.Count > 0
|
||||
appRef.ActiveDocument.Close(wScript.Arguments(0))
|
||||
appRef.ActiveDocument.Close(CInt(wScript.Arguments(0)))
|
||||
Loop
|
||||
|
||||
appRef.Quit()
|
||||
11
scripts/setLayerVisibility.jsx
Normal file
11
scripts/setLayerVisibility.jsx
Normal file
@@ -0,0 +1,11 @@
|
||||
#include lib.js
|
||||
var stdout = newFile(arguments[0])
|
||||
var lyrs = getLayers(arguments[1])
|
||||
var vis = arguments[2] == "true"
|
||||
try {
|
||||
for (var i = 0; i < lyrs.layers.length; i++)
|
||||
lyrs.layers[i].visible = vis
|
||||
} catch (e) {
|
||||
stdout.writeln(err(e))
|
||||
}
|
||||
stdout.close()
|
||||
Reference in New Issue
Block a user