Copy link to clipboard
Copied
Hi,
I am looking for a way to get the artboard reference of a currently active layer nested into it. I was browsing around, but I am still quite confused about how to proceed.
Any help very appreciated!
Thank you
I'm not sure, but maybe it will help you...
var doc = activeDocument,
currentArtboard = getActiveArtboard();
/* ======================== */
alert(currentArtboard);
/* ======================== */
function getActiveArtboard() {
while(true) {
if (isArtboardLayer()) {
return doc.activeLayer
}
selectForwardLayer();
}
}
function isArtboardLayer() {
var ref = new ActionReference();
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
var isArtboar
...
Copy link to clipboard
Copied
I'm not sure, but maybe it will help you...
var doc = activeDocument,
currentArtboard = getActiveArtboard();
/* ======================== */
alert(currentArtboard);
/* ======================== */
function getActiveArtboard() {
while(true) {
if (isArtboardLayer()) {
return doc.activeLayer
}
selectForwardLayer();
}
}
function isArtboardLayer() {
var ref = new ActionReference();
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
var isArtboardLayer = executeActionGet(ref).getBoolean(stringIDToTypeID("artboardEnabled"));
return isArtboardLayer
}
function selectForwardLayer() {
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated(charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Frwr'));
desc.putReference(charIDToTypeID('null'), ref);
desc.putBoolean(charIDToTypeID('MkVs'), false);
executeAction(charIDToTypeID('slct'), desc, DialogModes.NO);
}
Copy link to clipboard
Copied
Exactly what I was looking for. Thank you nvkzNemo‌ !
Copy link to clipboard
Copied
Or this... better a little
var doc = activeDocument,
l = doc.activeLayer,
p = l.parent,
key = false,
currentArtboard = getActiveArtboard();
/* ========================= */
alert(currentArtboard);
doc.activeLayer = l;
/* ========================= */
function getActiveArtboard() {
try{
while(!key) {
doc.activeLayer = p;
var ref = new ActionReference();
ref.putEnumerated(charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt'));
key = executeActionGet(ref).getBoolean(stringIDToTypeID("artboardEnabled"));
if (key) {
return p
}
p = p.parent;
}
}catch (e) {
alert('That layer without artboard');
return undefined
}
}