CreativePro Forum
Join our community of graphic designers, publishers, and production artists from around the world. Our members-only forum is a great place to discuss challenges and find solutions!
- You must be logged in to reply to this topic.Login
Image Fitting options on Anchored Graphic Frames
- This topic has 8 replies, 3 voices, and was last updated 6 years, 1 month ago by
Qing Youguo.
-
AuthorPosts
-
-
September 30, 2019 at 10:29 am #1189452
Masood Ahmad
ParticipantHi Team,
I have a code that works well on the selected images. Can the below code be tweaked to work on Anchored images in the selected text frame.
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Image Fitting Script");
function main(){
// Capture the current selections in array
var mySelections = app.selection;
for (var i = 0; i < mySelections.length; i++) {
var myObject = mySelections[i];
myObject.fit(FitOptions.contentToFrame);
myObject.fit(FitOptions.proportionally);
myObject.fit(FitOptions.centerContent);
myObject.fit(FitOptions.frameToContent);
};
}
Thanks in advance
-
September 30, 2019 at 11:11 am #14324010
Qing Youguo
ParticipantTry this:
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, “Image Fitting Script”);
function main() {
// Capture the current selections in array
var mySelections = app.selection;
for (var i = 0; i < mySelections.length; i++) {
var myObject = mySelections[i];
if (myObject instanceof TextFrame) {
var allRtg = myObject.rectangles.everyItem().getElements();
for (var j = 0; j < allRtg.length; j++) {
var theRtg = allRtg[j];
try {
theRtg.fit(FitOptions.contentToFrame);
theRtg.fit(FitOptions.proportionally);
theRtg.fit(FitOptions.centerContent);
theRtg.fit(FitOptions.frameToContent);
} catch (e) {}
}
}
}
} -
September 30, 2019 at 11:13 am #14324009
Robert Ploch
MemberHello again :)
try this little work snippet of code. I hope I’ve undersood your idea :)
I’ve changed a little your code in case of potential errors and/or further actions ( e.g. deleting anchored elements )if ( !app.selection[0] || app.selection[0].constructor.name != ‘TextFrame’ ) { alert ( ‘There is no TEXT FRAME selected !Select a textFrame contaning text please :)’); exit() }
var mySelections = app.selection[0].parentStory.splineItems.everyItem().getElements(); // this is an array of anchored items of the story in seleccted textFramealert ( “There are/is ” + mySelections.length + ‘ anchored elements in the frame.’ );
main();
function main(){
var sel = mySelections, i = sel.length;
while ( i– ) {
var myObject = sel[i];
myObject.fit(FitOptions.contentToFrame);
myObject.fit(FitOptions.proportionally);
myObject.fit(FitOptions.centerContent);
myObject.fit(FitOptions.frameToContent);
}
}best
m. -
October 2, 2019 at 10:00 am #14323985
Masood Ahmad
ParticipantThanks Qing and Robert, both the scripts worked well.
I just noticed that some inline graphic frames got reduced in size and they are now left align as per the Paragraph style. I was thinking of a way to center align all the inline objects.
I tried this:
myObject.Justification.CENTER_ALIGN;
and this:
theRtg.fit(Justification.CENTER_ALIGN);Can you help me out on this as well.
In addition, is it doable with little extra code to assign a para style, let’s say “Inline_Images” to all those inline graphic frames.
-
October 3, 2019 at 9:54 am #14323978
Masood Ahmad
ParticipantHi Qing and Robert,
I’m facing an issue while running the script. The text frame containing the text and inline images runs on multiple pages. Every column is a separate text frame, for example, there are 6 text frames for a 6 column layout on every page. So I realized that while selecting only one text frame on the first page, the script make changes only to that particular text frame, whereas the other content remains unchanged. If I select multiple text frame, then it make changes to the contents of all the selected text-frames. As you know we can’t select frames on multiple pages, I’m facing issues. So is there a way, that the script can make changes to the entire story. Or a better way is to select the text using text tool and then run the script.
//DESCRIPTION: Fit Image to Frame for Inline graphics//https://indesignsecrets.com/topic/image-fitting-options-on-anchored-graphic-frames
//Version: 1.0, dated: 2nd October 2019.app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Image Fitting Script");
function main() {
// Capture the current selections in array
var mySelections = app.selection;
for (var i = 0; i < mySelections.length; i++) {
var myObject = mySelections[i];
if (myObject instanceof TextFrame) {
var allRtg = myObject.rectangles.everyItem().getElements();
for (var j = 0; j < allRtg.length; j++) {
var theRtg = allRtg[j];
try {
theRtg.fit(FitOptions.contentToFrame);
theRtg.fit(FitOptions.proportionally);
theRtg.fit(FitOptions.frameToContent);
theRtg.fit(FitOptions.centerContent);
} catch (e) { }
}
}
}
}
Please look into this and help me out. Thanks in advance.
Masood
-
October 4, 2019 at 1:56 am #14323973
Masood Ahmad
ParticipantAny clues…
-
October 4, 2019 at 2:09 pm #14323970
Robert Ploch
MemberHi Masood,
1. I’m affraid, I don’t understend your previous post about centering inline grapgics. Would you eplain it more precise ?
2. try this code to process all the inline graphics in all the texts in active document:if ( app.documents.length > 0 ) {
var mySelections = app.activeDocument.stories.everyItem().texts[0].splineItems.everyItem().getElements(); // this is an array of anchored items of the story in seleccted textFrame
alert ( “There are/is ” + mySelections.length + ‘ anchored elements in the document.’ );
main( mySelections );
}
function main( sel ){
var i = sel.length;
while ( i– ) {
try { var myObject = sel[i];
myObject.fit(FitOptions.contentToFrame);
myObject.fit(FitOptions.proportionally);
myObject.fit(FitOptions.centerContent);
myObject.fit(FitOptions.frameToContent);
} catch ( err ) {}
}
}best regards
r. -
October 5, 2019 at 5:30 pm #14323968
Qing Youguo
ParticipantHi Masood,
Change the following conde line:
var allRtg = myObject.rectangles.everyItem().getElements();
to:
var allRtg = myObject.parentStory.rectangles.everyItem().getElements();
is what you want?
By the way, Inline Images’s parent —— theRtg DOESN’T haved “theRtg.fit(Justification.CENTER_ALIGN)” such a method, and the selected texfframe’s story !== all the stories in the document, maybe one or a few stories in the selected texfframes indeed! So, it’s a better way to do it: loop all the strories in the document, and loop all the Rectangles that containing images in each story.
You must telling the whole details before asking question.
-
October 18, 2019 at 9:42 am #14323906
Masood Ahmad
ParticipantHi Qing, Hi Robert,
First, please accept my sincere apologies for not responding to your replies. I got stuck somewhere and couldn’t got the time to test these additions.
My initial requirement was to fit all the inline images in the story in the selected text frame. I tested both the scripts given by you (Qing and Robert) and they worked well.
Qing’s script was fixing all the inline images of the selected text frame but not in the whole story. I didn’t realized that Robert’s script was in fact fixing all the inline images in the whole story of the selected text frame. Secondly, to center align the inline images was an optional thought, which I fixed by updating the para style for the inline images.
Qing, your changes to the script worked the way I wanted:
var allRtg = myObject.parentStory.rectangles.everyItem().getElements();
This helps me fix all the inline images within the story.Robert, your first script as I said worked well. The new updated code gives me a new thought as the new code was fixing all the inline images within the document. So I have saved this as a separate script for future requirements.
I must say, that now I have three scripts:
1) Fix all inline images within a Document.
2) Fix all inline images within a Story.
3) Fix all inline images within a TextFrame.Thanks a ton to both of you :)
-
-
AuthorPosts
- You must be logged in to reply to this topic.
