Reply To: auto center object inline with height

Home Page / Forums / General InDesign Topics (CLOSED) / auto center object inline with height / Reply To: auto center object inline with height

#84914
Ari Singer
Member

Here you go! i created this script, please let me know if it works.
To make it work you have to select a range of text (or a text frame) before running the script, and the script will adjust all the inline graphics in the selected text (or text frame).
If you don’t know how to use save and run this script, look here:https://creativepro.com/how-to-install-a-script-in-indesign-that-you-found-in-a-forum-or-blog-post.php

Folowing is the script:

//created by Ari S. designerjoe@outlook.com
// Automatically vertically center inline graphics
app.scriptPreferences.enableRedraw = false;
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Adjust Inline Graphics Baseline");
function main() {
var myDoc = app.activeDocument;
with (myDoc.viewPreferences){
var myOldXUnits = horizontalMeasurementUnits;
var myOldYUnits = verticalMeasurementUnits;
horizontalMeasurementUnits = MeasurementUnits.points;
verticalMeasurementUnits = MeasurementUnits.points;
}
var mySelection = app.selection[0];
if (app.selection.length == 1){
//Evaluate the selection based on its type.
switch (app.selection[0].constructor.name){
case "InsertionPoint":
case "Character":
case "Word":
case "TextStyleRange":
case "Line":
case "Paragraph":
case "TextColumn":
case "Text":
case "Story":
//The object is a text object; pass it on to a function.
myAdjustBaseline(app.selection[0]);
break;
case "TextFrame":
myAdjustBaseline(app.selection[0].texts.item(0));
break;
default:
alert("The selected object is not a text object. Select some text and try again.");
break;
}
}
function myAdjustBaseline(text){
app.findChangeGrepOptions.includeLockedLayersForFind = false;
app.findChangeGrepOptions.includeLockedStoriesForFind = false;
app.findChangeGrepOptions.includeHiddenLayers = false;
app.findChangeGrepOptions.includeMasterPages = false;
app.findChangeGrepOptions.includeFootnotes = true;
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "~a";
var myFound = text.findGrep(true);
for (i=0; i < myFound.length; i++){
var myGraphicPosition = myFound[i];
var myPointSize = myGraphicPosition.pointSize;
var myBounds = myGraphicPosition.texts[0].pageItems[0].geometricBounds;
var myHeight = myBounds[2] - myBounds[0];
if (myHeight >= myPointSize)
myGraphicPosition.baselineShift = -(myHeight/3);
else if (myHeight >= (0.75 * myPointSize))
myGraphicPosition.baselineShift = -(myHeight/4);
else if (myHeight >= (.6 * myPointSize))
myGraphicPosition.baselineShift = -(myHeight/5)
else if (myHeight <= (0.25 * myPointSize))
myGraphicPosition.baselineShift = (myHeight/4);
}
app.findGrepPreferences = app.changeGrepPreferences = null;
}
with (myDoc.viewPreferences){
try{
horizontalMeasurementUnits = myOldXUnits;
verticalMeasurementUnits = myOldYUnits;
}
catch(myError){
alert("Could not reset custom measurement units.");
}
}
}

This article was last modified on May 15, 2016

Comments (0)

Loading comments...