Copy link to clipboard
Copied
Can there be a script that makes object A the same size as object B?
Here are two scenarios:
The first, being a graphical object, lets A be equal in size to the target B.
The second, if A is a picture and B is its caption, let B and A have two widths.
The second is the most desirable, because very often the caption needs to be re-widened after the picture size is changed. It's a pain in the ass when you have a lot of them.
If you choose an image and a static caption, you can have the caption quickly aligned to the image, including position and width. It would save a lot of work.
<Tiitle renamed by MOD>
var myGraphicFrame = app.selection[0];
var myTextFrame = app.selection[1];
myTextFrame.geometricBounds = [ myGraphicFrame.geometricBounds[2], myGraphicFrame.geometricBounds[1], myTextFrame.geometricBounds[2], myGraphicFrame.geometricBounds[3] ];
(^/)
myTextFrame.geometricBounds = [ myGraphicFrame.geometricBounds[2], myGraphicFrame.geometricBounds[1], myGraphicFrame.geometricBounds[2]+(myTextFrame.geometricBounds[2] -myTextFrame.geometricBounds[0]), myGraphicFrame.geometricBounds[3] ];
Take this one:
/*
_FRIdNGE-0766_ImageCaptionAlignment.jsx
Script written by FRIdNGE, Michel Allio [02/11/2024]
*/
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.FAST_ENTIRE_SCRIPT, 'Image And Caption Alignment');
function main() {
var myDoc = app.activeDocument;
var myRulerOrigin = myDoc.viewPreferences.rulerOrigin;
if ( app.selection.length != 2 ) {
alert( "Select 2 items!")
exit();
} else {
if ( app.selection[0]
...
Copy link to clipboard
Copied
No need for a script - you can simply group two objects and resize the group.
Or maybe not ... when you resize group - all objects will be resized proprtionally ...
But keeping both objects grouped - will help in resizing and fitting.
Copy link to clipboard
Copied
Totally basically:
// Select first the Graphic Frame then the Text Frame
var myGraphicFrame = app.selection[0];
var myTextFrame = app.selection[1];
myTextFrame.geometricBounds = [ myTextFrame.geometricBounds[0], myTextFrame.geometricBounds[1], myTextFrame.geometricBounds[2], myGraphicFrame.geometricBounds[3] ];
(^/) The Jedi
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Better: if you reduce the width and the height of the Graphic Frame:
var myGraphicFrame = app.selection[0];
var myTextFrame = app.selection[1];
myTextFrame.geometricBounds = [ myGraphicFrame.geometricBounds[2], myTextFrame.geometricBounds[1], myTextFrame.geometricBounds[2], myGraphicFrame.geometricBounds[3] ];
(^/)
Copy link to clipboard
Copied
What do you mean by "better"?
Copy link to clipboard
Copied
Hello, great @FRIdNGE
Thank you very much.
it's just that sometimes the caption is not together with the image.
The title note may have been dragged away from the image by some distance, and after running the script, it should still automatically align with the image.
Also, it's odd that if the caption is misaligned with the figure, it will only be right-aligned.
Copy link to clipboard
Copied
var myGraphicFrame = app.selection[0];
var myTextFrame = app.selection[1];
myTextFrame.geometricBounds = [ myGraphicFrame.geometricBounds[2], myGraphicFrame.geometricBounds[1], myTextFrame.geometricBounds[2], myGraphicFrame.geometricBounds[3] ];
(^/)
Copy link to clipboard
Copied
myTextFrame.geometricBounds = [ myGraphicFrame.geometricBounds[2], myGraphicFrame.geometricBounds[1], myGraphicFrame.geometricBounds[2]+(myTextFrame.geometricBounds[2] -myTextFrame.geometricBounds[0]), myGraphicFrame.geometricBounds[3] ];
Copy link to clipboard
Copied
Robert,
Sure! To catch more situations, your "myTextFrame.geometricBounds[2]" is … Better! 😉
(^/)
Copy link to clipboard
Copied
Hi~
Drag and select seems to have everything OK.
However, when clicking to select, sometimes an error occurs.
There are different cases: the diagram is selected first, or the text box is selected first.
If the diagram is outside the layout, it's a different situation.
If there's a lot of text around, it's easier to select it with a single click in sequence.
Is it possible to set it to always align to the last selected object?
Thank you~
Copy link to clipboard
Copied
Script expects specific selection order - I'm pretty sure that @FRIdNGE can make it more universal.
It's also possible to make script work in sequence, with only one item selected at a time - first run would check if it's image, store ID in a document's unique label, then, when it's run again, check if TextFrame is selected, retrieve ID of the image and align both.
Copy link to clipboard
Copied
Try This:
/*
_FRIdNGE-0766_ImageCaptionAlignment.jsx
Script written by FRIdNGE, Michel Allio [02/11/2024]
*/
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.FAST_ENTIRE_SCRIPT, 'Image And Caption Alignment');
function main() {
var myDoc = app.activeDocument;
var myRulerOrigin = myDoc.viewPreferences.rulerOrigin;
if ( app.selection.length != 2 ) {
alert( "Select 2 items!")
exit();
}
if ( app.selection.length === 2 ) {
myDoc.viewPreferences.rulerOrigin = RulerOrigin.SPREAD_ORIGIN;
if ( app.selection[0] instanceof Rectangle && app.selection[1] instanceof TextFrame ) {
var myGraphicFrame = app.selection[0];
var myTextFrame = app.selection[1];
} else if ( app.selection[1] instanceof Rectangle && app.selection[0] instanceof TextFrame ) {
var myGraphicFrame = app.selection[1];
var myTextFrame = app.selection[0];
} else {
alert( "Bad Selection!")
exit();
}
myTextFrame.geometricBounds = [ myGraphicFrame.geometricBounds[2], myGraphicFrame.geometricBounds[1], myGraphicFrame.geometricBounds[2] + myTextFrame.geometricBounds[2] - myTextFrame.geometricBounds[0], myGraphicFrame.geometricBounds[3] ];
myDoc.viewPreferences.rulerOrigin = myRulerOrigin;
}
}
(^/)
Copy link to clipboard
Copied
Copy link to clipboard
Copied
If you select 3 Frames, it's bad! You need to just select 2 items!
If you select 2 text frames or 2 rectangles (images), it's bad too.
You need to precisely select a text frame (caption) and a rectangle (image).
I love "security", as noted Edward Lewis in "Pretty Woman" movie! =D
(^/)
Copy link to clipboard
Copied
I know that you need to check for TWO items - you are checking type later - but what is the difference between "x!=2" and "x===2" - in this case?
Both have the same "result" - you are checking if "exactly two items are selected".
So why, in the 1st if - you can't just add "else" and contents of the following "if"?
Copy link to clipboard
Copied
I could! …
I've corrected this glitch:
} else {
myDoc.viewPreferences.rulerOrigin = myRulerOrigin;
alert( "Bad Selection!")
exit();
}
(^/)
Copy link to clipboard
Copied
You misunderstood.
In your 1st "if" you're checking if selection count is "not equal to two elements" - and you exit execution.
In the next "if" - you are checking if selection is "exactly two elements" - and you continue execution.
Aren't both comparisons "the same" in the result you are looking for?
if ( app.selection.length != 2 ) {
alert( "Select 2 items!")
exit();
}
else
{
myDoc.viewPreferences.rulerOrigin = RulerOrigin.SPREAD_ORIGIN;
Copy link to clipboard
Copied
I totally understood you. My correction is about something else!
(^/)
Copy link to clipboard
Copied
I totally understood you. My correction is about something else!
By @FRIdNGE
Not sure why you needed it - as you don't change RulerOrigin before the 1st "if"?
You read the value before the 1st "if" but you change it in the 2nd "if".
Copy link to clipboard
Copied
Even if the original code is correct, this other development seems to be more logical:
function main() {
var myDoc = app.activeDocument;
var myRulerOrigin = myDoc.viewPreferences.rulerOrigin;
if ( app.selection.length != 2 ) {
alert( "Select 2 items!")
exit();
}
if ( app.selection.length === 2 ) {
if ( app.selection[0] instanceof Rectangle && app.selection[1] instanceof TextFrame ) {
var myGraphicFrame = app.selection[0];
var myTextFrame = app.selection[1];
} else if ( app.selection[1] instanceof Rectangle && app.selection[0] instanceof TextFrame ) {
var myGraphicFrame = app.selection[1];
var myTextFrame = app.selection[0];
} else {
alert( "Bad Selection!")
exit();
}
myDoc.viewPreferences.rulerOrigin = RulerOrigin.SPREAD_ORIGIN;
myTextFrame.geometricBounds = [ myGraphicFrame.geometricBounds[2], myGraphicFrame.geometricBounds[1], myGraphicFrame.geometricBounds[2] + myTextFrame.geometricBounds[2] - myTextFrame.geometricBounds[0], myGraphicFrame.geometricBounds[3] ];
myDoc.viewPreferences.rulerOrigin = myRulerOrigin;
}
}
(^/)
Copy link to clipboard
Copied
I'm on my phone so not sure what's the difference to your previous version - but it still doesn't answer my question - why do you check the same condition twice?
Unless it's just your way of coding?
Copy link to clipboard
Copied
No response after double clicking on 11.02 scripts.
Nothing happens.
Copy link to clipboard
Copied
Take this one:
/*
_FRIdNGE-0766_ImageCaptionAlignment.jsx
Script written by FRIdNGE, Michel Allio [02/11/2024]
*/
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.FAST_ENTIRE_SCRIPT, 'Image And Caption Alignment');
function main() {
var myDoc = app.activeDocument;
var myRulerOrigin = myDoc.viewPreferences.rulerOrigin;
if ( app.selection.length != 2 ) {
alert( "Select 2 items!")
exit();
} else {
if ( app.selection[0] instanceof Rectangle && app.selection[1] instanceof TextFrame ) {
var myGraphicFrame = app.selection[0];
var myTextFrame = app.selection[1];
} else if ( app.selection[1] instanceof Rectangle && app.selection[0] instanceof TextFrame ) {
var myGraphicFrame = app.selection[1];
var myTextFrame = app.selection[0];
} else {
alert( "Bad Selection!")
exit();
}
myDoc.viewPreferences.rulerOrigin = RulerOrigin.SPREAD_ORIGIN;
myTextFrame.geometricBounds = [ myGraphicFrame.geometricBounds[2], myGraphicFrame.geometricBounds[1], myGraphicFrame.geometricBounds[2] + myTextFrame.geometricBounds[2] - myTextFrame.geometricBounds[0], myGraphicFrame.geometricBounds[3] ];
myDoc.viewPreferences.rulerOrigin = myRulerOrigin;
}
}
(^/)
Copy link to clipboard
Copied
Would it be better :
A case: dragg-select, the text box is aligned to the image.
B case: click-select, align to the last selector.