解決済み
Need help with InDesign script error (Object undefined)
- October 12, 2023
- 返信数 2.
- 2536 ビュー
Hi! I am trying to use a script from a past thread (https://community.adobe.com/t5/indesign-discussions/indesign-script-to-change-the-x-and-y-coordinates-of-page-items/m-p/8583897) and it seemed to work for the posters participating in that thread. This script is supposed to take text frames at a certain x, y coordinate and move them using to new x, y coordinates. However, I keep receiving an error that says Error string: undefined is not an object whenever I enter the coordinates.
I'm using Adobe Indesign 2024 (v19.0 latest version). I am by no means acquainted with JavaScript at all so I have no idea where it is going wrong. Thank you!
This is the script:
var myDoc = app.activeDocument;
var w = new Window ('dialog {alignChildren: "top"}', 'Move TF (x,y) To (newx, newy)!');
w.alignChildren = "right";
var group1 = w.add ('group');
group1.add ('statictext {text: "Type the old x:"}');
var UIx = group1.add ("edittext", undefined, 0);
UIx.characters = 5;
UIx.minimumSize.width = 60;
UIx.maximumSize.width = 60;
UIx.active = true;
var group2 = w.add ('group');
group2.add ('statictext {text: "… and the old y:"}');
var UIy = group2.add ("edittext", undefined, 0);
UIy.characters = 5;
UIy.minimumSize.width = 60;
UIy.maximumSize.width = 60;
var group3 = w.add ('group');
group3.add ('statictext {text: "Type the new x:"}');
var UInewx = group3.add ("edittext", undefined, 0);
UInewx.characters = 5;
UInewx.minimumSize.width = 60;
UInewx.maximumSize.width = 60;
var group4 = w.add ('group');
group4.add ('statictext {text: "… and the new y:"}');
var UInewy = group4.add ("edittext", undefined, 0);
UInewy.characters = 5;
UInewy.minimumSize.width = 60;
UInewy.maximumSize.width = 60;
var buttons = w.add ('group {alignment: "center"}');
buttons.add ('button {text: "OK"}');
buttons.add ('button {text: "Cancel"}');
if (w.show () == 1) {
var x = Number (UIx.text);
x = x.toFixed(2);
var y = Number (UIy.text);
y = y.toFixed(2);
var newx = UInewx.text;
var newy = UInewy.text;
}
else
exit ();
app.doScript("main()", ScriptLanguage.javascript, undefined, UndoModes.FAST_ENTIRE_SCRIPT, "Move TF (x,y) To (newx, newy)!");
function main()
{
var myTF = myDoc.textFrames.everyItem().getElements();
for ( i = 0; i < myTF.length; i++)
{
var gB = myTF.geometricBounds;
var y1 = gB[0].toFixed(2);
var x1 = gB[1].toFixed(2);
if ( y1 == y && x1 == x ) myTF.move([newx, newy]);
}
}
