Per-layer metadata
I've searching around the web quite a lot regarding this but haven't been able to find any kind of official information about it:
Does this functionality exists in PS CC, and if so: where can I find code examples?
I've searching around the web quite a lot regarding this but haven't been able to find any kind of official information about it:
Does this functionality exists in PS CC, and if so: where can I find code examples?
Here is a script written by Paul Riggott, "Per Layer Guides"
#target photoshop
//Written by Paul Riggott
main();
function main(){
if(Number(app.version.match(/\d+/)) <12) return;
if(!documents.length) return;
var doc =activeDocument;
if(doc.activeLayer.isBackgroundLayer) return;
if(doc.activeLayer.kind != LayerKind.NORMAL) return;
if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
var startRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
if(ScriptUI.environment.keyboardState.shiftKey ){
setGuides();
}else{
displayGuides();
}
app.preferences.rulerUnits = startRulerUnits;
function setGuides(){
try{
xmp = doc.activeLayer.xmpMetadata.rawData;
xmpObject = new XMPMeta(xmp);
} catch(e){
xmpObject = new XMPMeta();
}
var psNamespace = "http://ns.layerguides/1.0/";
var psPrefix = "pmrGuides:";
XMPMeta.registerNamespace(psNamespace, psPrefix);
var guides = app.activeDocument.guides;
if(guides.length == 0){
alert("No guides exist");
return;
}
var gH = '';
var gV = '';
for( var g = 0; g < guides.length; g++ ){
if(guides
.direction.toString() == 'Direction.HORIZONTAL'){ gH+=(parseInt(guides
.coordinate.value)); gH+=',';
}else{
gV+=(parseInt(guides
.coordinate.value)); gV+=','
}
}
gH=gH.replace(/,$/,'');
gV=gV.replace(/,$/,'');
currentGuides = 'Layer Guides' + "¬" + gH + "¬" + gV;
xmpObject.deleteProperty(psNamespace, "LayerGuides");
xmpObject.setProperty(psNamespace, "LayerGuides",currentGuides);
app.activeDocument.activeLayer.xmpMetadata.rawData = xmpObject.serialize();
}
function displayGuides(){
try{
xmp = doc.activeLayer.xmpMetadata.rawData;
xmpObject = new XMPMeta(xmp);
} catch(e){
return;
}
var psNamespace = "http://ns.layerguides/1.0/";
var psPrefix = "pmrGuides:";
var layerGuides = xmpObject.getProperty(psNamespace, "LayerGuides");
clearGuides();
var ar1 = layerGuides.toString().split('¬');
var Hor = ar1[1].toString().split(',');
var Ver = ar1[2].toString().split(',');
for(var H in Hor){
activeDocument.guides.add(Direction.HORIZONTAL,new UnitValue(Number(Hor
),'px')); }
for(var V in Ver){
activeDocument.guides.add(Direction.VERTICAL,new UnitValue(Number(Ver
),'px')); }
}
}
function clearGuides() {
var id556 = charIDToTypeID( "Dlt " );
var desc102 = new ActionDescriptor();
var id557 = charIDToTypeID( "null" );
var ref70 = new ActionReference();
var id558 = charIDToTypeID( "Gd " );
var id559 = charIDToTypeID( "Ordn" );
var id560 = charIDToTypeID( "Al " );
ref70.putEnumerated( id558, id559, id560 );
desc102.putReference( id557, ref70 );
executeAction( id556, desc102, DialogModes.NO );
};
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.