Skip to content

Instantly share code, notes, and snippets.

@jrydberg
Created December 19, 2018 16:08
Show Gist options
  • Save jrydberg/c09212b698bae5adaaf586601eafcbe2 to your computer and use it in GitHub Desktop.
Save jrydberg/c09212b698bae5adaaf586601eafcbe2 to your computer and use it in GitHub Desktop.
/*
File Setup.jsx v3
Copyright (C) 2017, 2018 Johan Rydberg. All Rights Reserved.
A Photoshop Script to automate the file setup described in
"Commercial Retouching Workflow with Sef McCullough" from RGG EDU.
It expects you to have paths set up for your parts. If one of the paths is
called "SILO" then that will be used as group mask for all other masks.
The layer that is active when you invoke the script will be the one
used as base.
How to use:
Install it under Presets/Scripts in your Photoshop CC folder, and then
run it from File>Scripts menu (it should be listed there. don't forget
to restart Photoshop).
Or, you can use File>Scripts>Browse... and pick this file.
Notes:
If you have a path named something like "GUIDE foo", only a guide
will be created for the path.
*/
var doc = app.activeDocument;
doc.suspendHistory("File Setup", "main()");
function createGuides() {
var group;
group = doc.layerSets.add()
group.name = "GUIDES";
group.visible = false;
for (var i = 0; i < doc.pathItems.length; i++) {
var pathItem = doc.pathItems[i];
var layer, newColor;
layer = group.artLayers.add();
layer.name = pathItem.name + '+++';
newColor = new SolidColor();
newColor.hsb.hue = (10 + i * 60) % 360;
newColor.hsb.brightness = 70 + (20 * (i/6));
newColor.hsb.saturation = 100;
doc.selection.deselect();
pathItem.makeSelection();
doc.selection.fill(newColor);
layer = group.artLayers.add();
layer.name = pathItem.name + '---';
doc.selection.invert();
doc.selection.fill(newColor);
}
// Clean up
doc.selection.deselect();
return group;
}
function makePathSelection(pathItem) {
doc.selection.deselect();
pathItem.makeSelection();
makeMaskFromSelection();
}
function createSubject() {
var subject, groups = [];
var base = doc.activeLayer || doc.layers[0];
var siloPathItem;
if (!doc.pathItems.length) {
return null;
}
try {
siloPathItem = doc.pathItems.getByName("SILO");
} catch(e) {
siloPathItem = null;
}
if (siloPathItem !== null) {
// When we have a SILO we put everything within a group.
subject = doc.layerSets.add();
subject.name = "SUBJECT";
makePathSelection(siloPathItem);
} else {
// When we do not have a SILO we're putting things straight into the doc.
subject = doc;
}
var bottom = base.duplicate(subject, ElementPlacement.INSIDE);
bottom.name = 'BASE';
for (var i = doc.pathItems.length - 1; i >= 0; i--) {
var pathItem = doc.pathItems[i];
var group, layer;
if (pathItem.name.substr(0, 6) == "GUIDE ") {
continue;
}
if (siloPathItem !== null && pathItem.name == siloPathItem.name) {
continue;
}
group = subject.layerSets.add();
group.name = pathItem.name;
makePathSelection(pathItem);
layer = base.duplicate(group, ElementPlacement.INSIDE);
layer.name = pathItem.name;
}
return (siloPathItem !== null ? subject : base);
}
function main() {
var subject = createSubject();
var guides = createGuides();
guides.move(subject, ElementPlacement.PLACEBEFORE);
}
// Make a layer mask based on a selection. Straight from internet.
function makeMaskFromSelection()
{
var id42 = charIDToTypeID( "Mk " );
var desc8 = new ActionDescriptor();
var id43 = charIDToTypeID( "Nw " );
var id44 = charIDToTypeID( "Chnl" );
desc8.putClass( id43, id44 );
var id45 = charIDToTypeID( "At " );
var ref10 = new ActionReference();
var id46 = charIDToTypeID( "Chnl" );
var id47 = charIDToTypeID( "Chnl" );
var id48 = charIDToTypeID( "Msk " );
ref10.putEnumerated( id46, id47, id48 );
desc8.putReference( id45, ref10 );
var id49 = charIDToTypeID( "Usng" );
var id50 = charIDToTypeID( "UsrM" );
var id51 = charIDToTypeID( "RvlS" );
desc8.putEnumerated( id49, id50, id51 );
executeAction( id42, desc8, DialogModes.NO );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment