Can't align inline object in script
Copy link to clipboard
Copied
I am trying to add choice text and then image but unfortunately I can't vertically align image with text.
I want to align text and image at top like this.
I tried offset option but it pushes last image out of the text frame so it seems not a solution for me. How can I achieve this?
My code for first 2 choices
myLeftTextFrame3.contents = qn + ".\r";
myLeftTextFrame3.paragraphs[-1].appliedParagraphStyle = app.documents[0].paragraphStyles.itemByName("ST1");
myLeftTextFrame3.contents += "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras hendrerit lacinia dapibus. Curabitur sodales sapien risus, eu rhoncus mi rutrum ac. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Praesent placerat erat vel augue sollicitudin bibendum. In lacus dolor, imperdiet vel aliquet non, feugiat quis enim. Aenean vel ligula ligula. Integer magna lectus, commodo in fermentum condimentum, feugiat sit amet leo.\r";
myLeftTextFrame3.paragraphs[-1].appliedParagraphStyle = app.documents[0].paragraphStyles.itemByName("ST1");
var rect3 = myLeftTextFrame3.insertionPoints[-1].rectangles.add( {geometricBounds:[0,0,40,97.5], strokeWeight:0} );
rect3.place ("/Users/pc/Documents/SFTP/3.jpg");
rect3.fit( FitOptions.CONTENT_TO_FRAME );
rect3.fit( FitOptions.PROPORTIONALLY);
myLeftTextFrame3.insertionPoints[-1].contents = "\rLorem ipsum dolor sit amet, consectetur adipiscing elit?\n";
myLeftTextFrame3.paragraphs[-1].appliedParagraphStyle = app.documents[0].paragraphStyles.itemByName("ST2");
myLeftTextFrame3.insertionPoints[-1].contents = "\rA)";
var r1 = myLeftTextFrame3.insertionPoints[-1].rectangles.add( {geometricBounds:[0,0,30,40], strokeWeight:0} );
r1.place ("/Users/pc/Documents/SFTP/2.jpg");
r1.fit( FitOptions.CONTENT_TO_FRAME );
r1.fit( FitOptions.PROPORTIONALLY);
with(r1.anchoredObjectSettings){
anchoredPosition = AnchorPosition.INLINE_POSITION,
anchorPoint = AnchorPoint.CENTER_ANCHOR,
verticalAlignment = VerticalAlignment.CENTER_ALIGN,
verticalReferencePoint = VerticallyRelativeTo.LINE_BASELINE,
horizontalReferencePoint = AnchoredRelativeTo.ANCHOR_LOCATION,
anchorYoffset = 0
}
myLeftTextFrame3.insertionPoints[-1].contents = "\tB)";
var r2 = myLeftTextFrame3.insertionPoints[-1].rectangles.add( {geometricBounds:[0,0,30,40], strokeWeight:0} );
r2.place ("/Users/pc/Documents/SFTP/2.jpg");
r2.fit( FitOptions.CONTENT_TO_FRAME );
r2.fit( FitOptions.PROPORTIONALLY);
with(r2.anchoredObjectSettings){
anchoredPosition = AnchorPosition.INLINE_POSITION,
anchorPoint = AnchorPoint.CENTER_ANCHOR,
verticalAlignment = VerticalAlignment.CENTER_ALIGN,
verticalReferencePoint = VerticallyRelativeTo.LINE_BASELINE,
horizontalReferencePoint = AnchoredRelativeTo.ANCHOR_LOCATION,
anchorYoffset = 0
}
Copy link to clipboard
Copied
Why do you use a script and not the object style?
Copy link to clipboard
Copied
I have to automate these for thousands of question. It has to be script but what do you mean by saying object style?
Copy link to clipboard
Copied
With an object style you can define psition and size and kind of an anchored frame. I hope you use Object Styles, if not, do it.
Copy link to clipboard
Copied
See this article on using Object Styles to position an item.
- Mark
Copy link to clipboard
Copied
Another solution could be the use of tables.
Copy link to clipboard
Copied
Hi Mangokafa,
well, yes, Willi is right. Look into table with graphic cells to get the images and texts aligned precisely.
A table would provide you with a more logical structure as well if it comes to row and column.
Four columns, the second and the fourth column should contain graphic cells with the images.
What's your version of InDesign?
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
Hi Laubender,
Thanks for both of your answers. I'm using Indesign CC 2021 16.4 version.
Copy link to clipboard
Copied
Hi @mangokafa, I'm agreeing with the others. But if you absolutely need to position via script, then something like this:
// for this example I assume you have the anchored graphic box selected
var item = app.activeDocument.selection[0];
item.anchoredObjectSettings.anchoredPosition = AnchorPosition.ANCHORED;
item.anchoredObjectSettings.anchorPoint = AnchorPoint.TOP_RIGHT_ANCHOR;
item.anchoredObjectSettings.horizontalAlignment = HorizontalAlignment.RIGHT_ALIGN;
item.anchoredObjectSettings.horizontalReferencePoint = AnchoredRelativeTo.COLUMN_EDGE;
item.anchoredObjectSettings.verticalReferencePoint = VerticallyRelativeTo.CAPHEIGHT;
Have a look at the API for AnchoredObjectSettings.
Even with scripting, you can apply an object style instead of hard coding it. This is more flexible.
item.appliedObjectStyle = "Answer Graphics";
- Mark

