Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot get artboard background color #377

Open
canoztokmak opened this issue Mar 16, 2017 · 9 comments
Open

Cannot get artboard background color #377

canoztokmak opened this issue Mar 16, 2017 · 9 comments

Comments

@canoztokmak
Copy link
Contributor

By using neither generator nor extend script features, we cannot retrieve the background color for artboards.

Is this intentionally left out or am I missing something ?

@chadrolfs
Copy link
Contributor

Hi @canoztokmak. I wouldn't say it is intentionally left out, but we haven't done the coding to add that since that functionality was introduced relatively recently. The workaround is to add an additional locked shape layer that sits at the bottom of the artboard group. I'll mark this as a feature request. Hopefully it is an option we can easily add.

@canoztokmak
Copy link
Contributor Author

ok, thanks @chadrolfs .. looking forward to it !

@mcilroyc
Copy link
Contributor

@canoztokmak Here is some extendscript I cobbled together from a few sources to show how the artboard background color can be fetched in the current version of photoshop. This sample script assumes an artboard layer is selected in the open document. Let me if you have trouble getting this approach to work, or if it is not sufficient for your needs.

var classLayer = charIDToTypeID('Lyr ');
var idnull = stringIDToTypeID( "null" );

var classProperty = charIDToTypeID('Prpr');
var typeOrdinal = charIDToTypeID('Ordn');
var enumTarget = charIDToTypeID('Trgt'); 

var idred = charIDToTypeID( 'Rd  ' );
var idgreen = charIDToTypeID( 'Grn ' );
var idblue = charIDToTypeID( 'Bl  ' );
var actionGet = charIDToTypeID( "getd" );

var idtop = stringIDToTypeID( "top" );
var idleft = stringIDToTypeID( "left" );
var idright = stringIDToTypeID( "right" );
var idbottom = stringIDToTypeID( "bottom" );

var idartboard = stringIDToTypeID( "artboard" );
var idartboardRect = stringIDToTypeID( "artboardRect" );
var idartboardColor = stringIDToTypeID( "color" );

function TargetLayerRef(inProp) {
	var theRef = new ActionReference();
	theRef.putProperty(classProperty, inProp);
	theRef.putEnumerated(classLayer, typeOrdinal, enumTarget);

	return theRef;
}

function RefArtboardRect(theRef) {
	var getDescriptor = new ActionDescriptor();
	getDescriptor.putReference(idnull,theRef);
	var artboardRect = executeAction( actionGet, getDescriptor, DialogModes.NO )
						.getObjectValue(idartboard).getObjectValue(idartboardRect);

	return {
		top: artboardRect.getInteger(idtop), 
		left: artboardRect.getInteger(idleft),
		bottom: artboardRect.getInteger(idbottom),
		right: artboardRect.getInteger(idright)
	};
}

function TargetArtboardRect() {
	return RefArtboardRect(TargetLayerRef(idartboard));
}

function RefArtboardColor(theRef) {
	var getDescriptor = new ActionDescriptor();
	getDescriptor.putReference(idnull,theRef);

	var artboardColor = executeAction( actionGet, getDescriptor, DialogModes.NO )
			.getObjectValue(idartboard).getObjectValue(idartboardColor);

	return {
		red:artboardColor.getInteger(idred),
		green:artboardColor.getInteger(idgreen),
		blue:artboardColor.getInteger(idblue)
	};
}

function TargetArtboardColor() {
	return RefArtboardColor(TargetLayerRef(idartboard));
}

// =======================================================

var propArtboardEnabled = stringIDToTypeID( "artboardEnabled" );

function TargetIsArtboard() {
	var getDescriptor = new ActionDescriptor();
	getDescriptor.putReference(idnull,TargetLayerRef(propArtboardEnabled));
	return executeAction( actionGet, getDescriptor, DialogModes.NO ).getBoolean(propArtboardEnabled);
}

function RectToString(inRect) {
	return "" + inRect.top + ","  + inRect.left + ","  + inRect.bottom + "," + inRect.right;
	}

// =======================================================

function RGBToString(inRGB) {
	return "" + inRGB.red + ","  + inRGB.green + ","  + inRGB.blue;
	}


// =======================================================
// Display artboard rectangle of selected artboard.

function DisplayTargetArtboard() {
	if (TargetIsArtboard()) {
		var artboardRect = TargetArtboardRect(),
			artboardColor = TargetArtboardColor();
		alert("Artboard Rect: " + RectToString(artboardRect) + "\nBackground Color: " + RGBToString(artboardColor) );
	}
}

// =======================================================

DisplayTargetArtboard();

@canoztokmak
Copy link
Contributor Author

hey @mcilroyc ! thanks for the workaround.. it works like a charm, much appreciated !

@GDreyV
Copy link

GDreyV commented Jun 5, 2017

It seems that the script works only for custom backgrounds. It returns unpredictable results for preset values like "White", "Black" or "Transparent" (

@canoztokmak
Copy link
Contributor Author

@GDreyV you can distinguish those different types of background colors by retrieving it from artboard object. See below snippet:

var idartboard = stringIDToTypeID( "artboard" );
var idartboardBgType = stringIDToTypeID( "artboardBackgroundType" );
var artboard = executeAction( actionGet, getDescriptor, DialogModes.NO).getObjectValue(idartboard);
var bgType = artboard.getInteger(idartboardBgType);

@GDreyV
Copy link

GDreyV commented Jun 6, 2017

Great! Thanks a lot!

@mcilroyc mcilroyc removed their assignment Jul 24, 2017
@antonisaantoniou
Copy link

hey @mcilroyc. Can I take the alpha of the background too?

@mcilroyc
Copy link
Contributor

mcilroyc commented Dec 7, 2017

I'm not sure what you mean @antonisaantoniou. see previous comment about determining if the artboard background is "Transparent" using artboardBackgroundType

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants