Can't align inline object in script

Community Beginner ,
Feb 10, 2022 Feb 10, 2022

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.

 

Screen Shot 2022-02-10 at 10.50.58.png

 

I want to align text and image at top like this.

Screen Shot 2022-02-10 at 11.02.23.png

 

 

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
}

 

TOPICS
Scripting

Views

123

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Feb 10, 2022 Feb 10, 2022

Copy link to clipboard

Copied

Why do you use a script and not the object style?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 10, 2022 Feb 10, 2022

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?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Feb 10, 2022 Feb 10, 2022

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Feb 10, 2022 Feb 10, 2022

Copy link to clipboard

Copied

LATEST

See this article on using Object Styles to position an item.

- Mark

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Feb 10, 2022 Feb 10, 2022

Copy link to clipboard

Copied

Another solution could be the use of tables.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Feb 10, 2022 Feb 10, 2022

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 )

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 10, 2022 Feb 10, 2022

Copy link to clipboard

Copied

Hi Laubender,

 

Thanks for both of your answers. I'm using Indesign CC 2021 16.4 version.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Feb 10, 2022 Feb 10, 2022

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines