Iam beginning my fun with JS/Adobe CS5 coding, its kinda 'die hard' so far but anyway

My idea is to process +1000 images /coins/ with inserting a title block into each coin image.
Coins can very a bit/size/ so I want to have always equal distamce between title block-coin-upper margin.
/additionally I need to amend each title block with some text related to coin's filename-but this one later../
So far I reworked some known scripts/and combine it with some simple actions: trim, canvas resize/ but cant achieve repeatable results:
Code: Select all
//header if supposed to work as script and not a function
#target photoshop
app.bringToFront();
app.displayDialogs = DialogModes.NO; // Dialog off
var strtRulerUnits = app.preferences.rulerUnits; // Save Users ruler units
var strtTypeUnits = app.preferences.typeUnits; // Save Users Type units
app.preferences.rulerUnits = Units.PIXELS; // work with pixels
app.preferences.typeUnits = TypeUnits.PIXELS; // work with pixels
app.activeDocument.selection.deselect(); //deselect if anything selected
//******************************************
// MOVE LAYER TO
// Author: Max Kielland, modified by Zbigniew Solarewicz / 2018
//Moves one layer depending on the other. Important to point ACTIVE layer ,eg.with some Action
docRef = app.activeDocument;
var myLayers = docRef.artLayers; // get layers
var myLayerRef = docRef.activeLayer;
var myLayerRefPosition = myLayerRef.bounds;
var myX = myLayerRefPosition[0];
var myY = myLayerRefPosition[1];
//alert(myLayers.length); //check layer number
if (myLayers.length < 2) {
myLayerRef.activeLayer = myLayers[0];
docRef.activeLayer = docRef.layers[0];
//UL and LR corner, bounds defined as list: [x0 y0 x1 y1]
myLayerRef.translate( null , -myY);
} else {
myLayerRef.activeLayer = myLayers[0];
docRef.activeLayer = docRef.layers[0];
//UL and LR corner, bounds defined as list: [x0 y0 x1 y1]
//move second-lower layer 300px below
myLayerRef.translate( null , myLayers[1].bounds[1]+myLayers[0].bounds[1]/20);
}
//docRef.trim(TrimType.TOPLEFT, true, true, true, true);
//docRef.resizeCanvas( docRef.width+30, docRef.heigth+30, AnchorPosition.MIDDLECENTER );
if (myLayerRef = myLayers[0]) {
//myLayerRef.translate( null , myLayerRef[0].bounds[1]);
null
} else {
null
}
docRef.selection.deselect();
PS. There is a problem having SELECTED/MARKED proper layer/none selected produces error/.
Maybe somebody could advice right direction to explore the issue?
cheers,