Reply To: Auto Size text boxes

#100916
Vinny –
Member

Hi Brenda.
I suppose this could be scripted. Then just apply a keyboard shortcut to the script.
Here’s an example I just wrote (based on Adobe’s CreateCharacterStyle.jsx):
Although I am very unsure how this WP forum handles codes and a bit worried it would remove some characters…

main();
function main(){
//Make certain that user interaction (display of dialogs, etc.) is turned on.
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
if (app.documents.length != 0){
if (app.selection.length == 1){
switch (app.selection[0].constructor.name){
case “TextFrame”:
myDefineObjectStyle();
break;
default:
alert(“The selected object is not a text frame. Select some text and try again.”);
break;
}
}
else{
alert(“Please select a single text frame and try again.”);
}
}
else{
alert(“No documents are open. Please open a document, select some text, and try again.”);
}
}

function myDefineObjectStyle(myCharacterStyleName){
var myDocument = app.activeDocument;
var myObjectStyleName = “Auto-resize text frame height”;

//Create the object style if it does not already exist.
myObjectStyle = myDocument.objectStyles.item(myObjectStyleName);
try{
myObjectStyle.name;
}
catch (myError){
myObjectStyle = myDocument.objectStyles.add({name:myObjectStyleName});
}

//Object Syle settings
myObjectStyle.basedOn = myDocument.objectStyles[0];
myObjectStyle.enableTextFrameAutoSizingOptions = true;
myObjectStyle.textFramePreferences.autoSizingType = AutoSizingTypeEnum.HEIGHT_ONLY; //Change if necessary
myObjectStyle.textFramePreferences.autoSizingReferencePoint = AutoSizingReferenceEnum.TOP_CENTER_POINT; //Change if necessary

myObjectStyle.enableFill = false;
myObjectStyle.enableStroke = false;
myObjectStyle.enableStrokeAndCornerOptions = false;
myObjectStyle.enableParagraphStyle = false;
myObjectStyle.enableTextFrameGeneralOptions = false;
myObjectStyle.enableTextFrameBaselineOptions = false;
myObjectStyle.enableStoryOptions = false;
myObjectStyle.enableTextWrapAndOthers = false;
myObjectStyle.enableAnchoredObjectOptions = false;
myObjectStyle.enableFrameFittingOptions = false;

}
// Apply ObjectStyle to the selection
var myObject = app.selection[0];
myObject.appliedObjectStyle = myObjectStyle;

This article was last modified on January 12, 2018

Comments (0)

Loading comments...