Scripting Issue that only occurs on Windows
So I've been using a hand made script for years and years now, it's actually a set of 2 scripts.
Script 1 "#LogAllDimensions-Alt.js" does what it says on the tin, it logs the Tranformation data like this:
"X_POS_0;Y_POS_0;WIDTH_0;HEIGHT_0$X_POS_1;Y_POS_1;WIDTH_1;HEIGHT_1$", it then shows a prompt containing the string however long it may be.
Then I can start selecting different objects and run Script 2: "#PositionObjectsBasedOnLog.js"
This does the opposite and splits the string at every "$" since those are dividers for each set of transformation data, then it splits each of those at ";" so that I get the raw X, Y, WIDTH, HEIGHT properties,
which are then used to reposition and resize my current selection accordingly.
I used to work at a printing company and I had to make efficient layouts when printing things so we don't waste more material than needed, but whenever we had to deal with extremely heavy images this got time consuming.
I made these scripts as a work around, I'd first use rectangles with the exact size as the images we'd need to print, I'd then puzzle together the layout and once that was figured out I only needed to place the actual images, make enough copies, select them and paste in the coordinates to set their new transformation data.
However at that company I worked on Macs, but now that I work elsewhere on a windows PC, some issues have arisen with "#PositionObjectsBasedOnLog.js"
When I paste in the transformation string it processes a couple of them only to then stop and spit out an error partway through.
No changes were made to this script between using it on Mac and Windows.
The weird thing is that if I edit the script and paste my string directly into it, then it works just fine, but if done through entering it into the prompt, this issue occurs.
Script 1 "#LogAllDimensions.js":
app.preferences.setBooleanPreference("ShowExternalJSXWarning", false);
var myDocument = app.activeDocument;
var convUnit = 2.834645;
var mySelection = new Object;
selections = myDocument.selection;
var stringToAlert = "";
for(i=0;i<selections.length;i++){
mySelection = myDocument.selection[i];
stringToAlert = (stringToAlert + (mySelection.left / convUnit) + ";" + (mySelection.top / convUnit) + ";" + (mySelection.width / convUnit) + ";" + (mySelection.height / convUnit) + "$");
if(i==(selections.length - 1)){
alertUser();
}
}
function alertUser(){
prompt("Transformation Data for " + selections.length + " Objects:", stringToAlert);
}
Script 2 "#PositionObjectsBasedOnLog.js":
app.preferences.setBooleanPreference("ShowExternalJSXWarning", false);
var myDocument = app.activeDocument;
var convUnit = 2.834645;
var mySelection = new Object;
selections = myDocument.selection;
var stringValue = (prompt("Input Log Text Here:", ""));
var livePreviewEnabled = true;
var resizingEnabled = true;
var scaleMultiplier = 1;
for(i=0;i<selections.length;i++){
mySelection = myDocument.selection[i];
var splitString = stringValue.split("$");
var splitStringValues = splitString[i].split(";");
var leftPos = (parseFloat(splitStringValues[0]) * convUnit);
var topPos = (parseFloat(splitStringValues[1]) * convUnit);
var objWidth = (parseFloat(splitStringValues[2]) * convUnit);
var objHeight = (parseFloat(splitStringValues[3]) * convUnit);
//Disabled section for automatically rotating objects if it considers the width and height to be swapped.
//This does work, but is extremely senstive to a difference of even 0.0000000001, so I had to disable it for now.
/*
if(objHeight > objWidth && mySelection.height < mySelection.width){
mySelection.rotate(90);
}
if(objWidth > objHeight && mySelection.width < mySelection.height){
mySelection.rotate(90);
}
*/
mySelection.left = (leftPos * scaleMultiplier);
mySelection.top = (topPos * scaleMultiplier);
if(resizingEnabled==true){
mySelection.width = (objWidth * scaleMultiplier);
mySelection.height = (objHeight * scaleMultiplier);
}
if(livePreviewEnabled==true){
app.redraw();
}
}
Note: I'm no JS Expert, so excuse me if I'm handling things a bit inefficient.
Though do tell me because I'm curious to know how it could be done better.
