Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Retrieve Artboard reference of active nested layer

New Here ,
Sep 06, 2015 Sep 06, 2015

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

TOPICS
Actions and scripting
751
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Participant , Sep 07, 2015 Sep 07, 2015

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
...
Translate
Adobe
Participant ,
Sep 07, 2015 Sep 07, 2015

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);
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 07, 2015 Sep 07, 2015

Exactly what I was looking for. Thank you nvkzNemo‌ !

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Sep 07, 2015 Sep 07, 2015
LATEST

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
	}
} 
		
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines