and what opportunities do you have in the Plugin's API other than just duplicate the code for AM.
The last sentence.
Try this script. It processes all layers. It is desirable that there are no empty layers or layers with a mask.
Good luck.
var pcnt = 17.7;
var use_even = false;
app.preferences.rulerUnits = Units.PIXELS;
var ok = true;
app.activeDocument.suspendHistory("Transform", "scan_layers(transform_layers, activeDocument.artLayers, activeDocument.layerSets); transform_canvas(pcnt);");
///////////////////////////////////////////////////////////////////////////////
if (!ok) alert("Some layers are not accurately resized")
else alert("All layers are successfully resized to " + pcnt + " %" + (use_even?" with even sizes":""))
/////////////////////////////////////////////////////////////////////////////////////////////////
function scan_layers(func, layers, sets)
{
function scan_func(func, layers, sets)
{
func (layers);
var length = sets.length;
for (var i = 0; i < length; i++)
{
var set = sets;
scan_func(func, set.artLayers, set.layerSets);
}
}
scan_func(func, layers, sets);
}
///////////////////////////////////////////////////////////////////////////////
function transform_layers(layers)
{
for (var i = 0; i < layers.length; i++)
{
activeDocument.activeLayer = layers;
if (!transform_layer(pcnt)) ok = false;
}
}
///////////////////////////////////////////////////////////////////////////////
function transform_layer(pcnt)
{
try {
switch (activeDocument.activeLayer.kind)
{
case LayerKind.SMARTOBJECT:
case LayerKind.NORMAL:
break;
default:
return true;
}
executeAction(stringIDToTypeID("newPlacedLayer"), undefined, DialogModes.NO);
var w = Number(activeDocument.activeLayer.bounds[2].value - activeDocument.activeLayer.bounds[0].value);
var h = Number(activeDocument.activeLayer.bounds[3].value - activeDocument.activeLayer.bounds[1].value);
var w_calc = Math.round(w*pcnt/100);
var h_calc = Math.round(h*pcnt/100);
if (use_even)
{
w_calc = Math.round(w_calc/2)*2;
h_calc = Math.round(h_calc/2)*2;
}
if (!transform(pcnt, pcnt, true)) return false;
var ok = false;
for (var i = 0 ; i < 5; i++)
{
w = Number(activeDocument.activeLayer.bounds[2].value - activeDocument.activeLayer.bounds[0].value);
h = Number(activeDocument.activeLayer.bounds[3].value - activeDocument.activeLayer.bounds[1].value);
if (w != w_calc || h != h_calc)
transform(w_calc/w*100, h_calc/h*100, false);
else
{
ok = true;
break;
}
}
if (!ok) for (var i = 0 ; i < 5; i++)
{
w = Number(activeDocument.activeLayer.bounds[2].value - activeDocument.activeLayer.bounds[0].value);
h = Number(activeDocument.activeLayer.bounds[3].value - activeDocument.activeLayer.bounds[1].value);
if (w != w_calc || h != h_calc)
transform((100+w_calc/w*100)/2, (100+h_calc/h*100)/2, false);
else
{
ok = true;
break;
}
}
if (!ok) for (var i = 0 ; i < 5; i++)
{
w = Number(activeDocument.activeLayer.bounds[2].value - activeDocument.activeLayer.bounds[0].value);
h = Number(activeDocument.activeLayer.bounds[3].value - activeDocument.activeLayer.bounds[1].value);
if (w != w_calc || h != h_calc)
transform((200+w_calc/w*100)/3, (200+h_calc/h*100)/3, false);
else
{
ok = true;
break;
}
}
var d = new ActionDescriptor();
var r = new ActionReference();
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
d.putReference(stringIDToTypeID("null"), r);
executeAction(stringIDToTypeID("rasterizeLayer"), d, DialogModes.NO);
w = Number(activeDocument.activeLayer.bounds[2].value - activeDocument.activeLayer.bounds[0].value);
h = Number(activeDocument.activeLayer.bounds[3].value - activeDocument.activeLayer.bounds[1].value);
if (w != w_calc || h != h_calc)
{
alert(w + " x " + h + "\n\n" + w_calc + " x " + h_calc);
return false;
}
return true;
}
catch (e) { throw(e); }
}
///////////////////////////////////////////////////////////////////////////////
function transform(w, h, pos)
{
try {
var d = new ActionDescriptor();
var r = new ActionReference();
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
d.putReference(stringIDToTypeID("null"), r);
d.putEnumerated(stringIDToTypeID("freeTransformCenterState"), stringIDToTypeID("quadCenterState"), stringIDToTypeID(pos?"QCSIndependent":"QCSAverage"));
var d1 = new ActionDescriptor();
if (pos)
{
d1.putUnitDouble(stringIDToTypeID("horizontal"), stringIDToTypeID("pixelsUnit"), 0);
d1.putUnitDouble(stringIDToTypeID("vertical"), stringIDToTypeID("pixelsUnit"), 0);
d.putObject(stringIDToTypeID("position"), stringIDToTypeID("point"), d1);
var d2 = new ActionDescriptor();
}
d.putUnitDouble(stringIDToTypeID("width"), stringIDToTypeID("percentUnit"), w);
d.putUnitDouble(stringIDToTypeID("height"), stringIDToTypeID("percentUnit"), h);
d.putBoolean(stringIDToTypeID("linked"), false);
d.putEnumerated(charIDToTypeID("Intr"), stringIDToTypeID("interpolationType"), stringIDToTypeID("bicubic"));
executeAction(stringIDToTypeID("transform"), d, DialogModes.NO);
return true;
}
catch (e) { return false; }
}
///////////////////////////////////////////////////////////////////////////////
function transform_canvas(pcnt)
{
try {
var d = new ActionDescriptor();
d.putUnitDouble(stringIDToTypeID("width"), stringIDToTypeID("percentUnit"), pcnt);
d.putUnitDouble(stringIDToTypeID("height"), stringIDToTypeID("percentUnit"), pcnt);
d.putEnumerated(stringIDToTypeID("horizontal"), stringIDToTypeID("horizontalLocation"), stringIDToTypeID("left"));
d.putEnumerated(stringIDToTypeID("vertical"), stringIDToTypeID("verticalLocation"), stringIDToTypeID("top"));
executeAction(stringIDToTypeID("canvasSize"), d, DialogModes.NO);
}
catch (e) { throw(e); }
}