Answered
Photoshop Scripting Artboard Size Values
Is it possible to get the width and height values of an artboard's size with Photoshop scripting? And is it possible to change the size of an artboard with scripting?
Is it possible to get the width and height values of an artboard's size with Photoshop scripting? And is it possible to change the size of an artboard with scripting?
ScriptingListener changing artboard size via Properties panel resizes from the fixed upper left... Resizing using the artboard tool (v) is "interactive"...
Combining the code from @Chuck Uebele with some further code:
#target photoshop
var doc = activeDocument;
var aLayer = doc.activeLayer;
var ab = artboard_rectangle(aLayer);
var aW = ab[2]-ab[0];
var aH = ab[3] - ab[1];
//////////
// Add 100px to current artboard width & height
var aWresize = aW + 100;
var aHresize = aH + 100;
//////////
resizeArtboard(0, 0, aHresize, aWresize, "", 255, 255, 255, 1);
//////////
function artboard_rectangle(layer)
{
try {
var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("artboard"));
if (layer) r.putIdentifier(stringIDToTypeID("layer"), layer.id);
else r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
var d = executeActionGet(r).getObjectValue(stringIDToTypeID("artboard")).getObjectValue(stringIDToTypeID("artboardRect"));
var bounds = new Array();
bounds[0] = d.getUnitDoubleValue(stringIDToTypeID("left"));
bounds[1] = d.getUnitDoubleValue(stringIDToTypeID("top"));
bounds[2] = d.getUnitDoubleValue(stringIDToTypeID("right"));
bounds[3] = d.getUnitDoubleValue(stringIDToTypeID("bottom"));
return bounds;
}
catch(e) { alert(e); }
}
//////////
function resizeArtboard(top, left, bottom, right, artboardPresetName, red, grain, blue, artboardBackgroundType) {
var s2t = function (s) {
return app.stringIDToTypeID(s);
};
var descriptor = new ActionDescriptor();
var descriptor2 = new ActionDescriptor();
var descriptor3 = new ActionDescriptor();
var descriptor4 = new ActionDescriptor();
var list = new ActionList();
var reference = new ActionReference();
reference.putEnumerated( s2t( "layer" ), s2t( "ordinal" ), s2t( "targetEnum" ));
descriptor.putReference( s2t( "null" ), reference );
descriptor3.putDouble( s2t( "top" ), top );
descriptor3.putDouble( s2t( "left" ), left );
descriptor3.putDouble( s2t( "bottom" ), bottom );
descriptor3.putDouble( s2t( "right" ), right );
descriptor2.putObject( s2t( "artboardRect" ), s2t( "classFloatRect" ), descriptor3 );
descriptor2.putList( s2t( "guideIDs" ), list );
descriptor2.putString( s2t( "artboardPresetName" ), artboardPresetName );
descriptor4.putDouble( s2t( "red" ), red );
descriptor4.putDouble( s2t( "grain" ), grain );
descriptor4.putDouble( s2t( "blue" ), blue );
descriptor2.putObject( s2t( "color" ), s2t( "RGBColor" ), descriptor4 );
descriptor2.putInteger( s2t( "artboardBackgroundType" ), artboardBackgroundType );
descriptor.putObject( s2t( "artboard" ), s2t( "artboard" ), descriptor2 );
executeAction( s2t( "editArtboardEvent" ), descriptor, 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.