Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to set auto sizing text frame on object style [AS]

Explorer ,
Jul 03, 2019 Jul 03, 2019

HI,

I'n trying to find every text frame with an overset text and apply an object style so it I can set the auto sizing on those. I found how to do pretty much everything except actually changing any values in the Text Frame auto size options part of the object style. There is only the option to set it to true.

Here's what I have so far.

tell application "Adobe InDesign CC 2019"

  set myDoc to active document

  tell myDoc

  set myTextFrame to every text frame of every story of myDoc whose overflows = true

  try

  set myObjectStyle to object style "myObjectStyle" of myDoc

  on error

  --The style did not exist, so create it.

  set myObjectStyle to make object style with properties {name:"myObjectStyle", enable text frame auto sizing options:true}

  end try

  repeat with i from 1 to (count of myTextFrame)

  set thisFrame to item i of myTextFrame

  set applied object style of thisFrame to myObjectStyle

  end repeat

  end tell

end tell

I have also thought I could resize every text frame with overset to some width and height and loop with different size, but I can't figure it out either and I think the object style is a better way to handle this anyway. I know I can just edit the Object style once it's applied but I want to know how to do it from the script if possible.

TIA!

TOPICS
Scripting
2.5K
Translate
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
Engaged ,
Jul 03, 2019 Jul 03, 2019

Hi Jeff,

I don't know much about Applescript. But in Javascript below code may helps to you.

var myDoc= app.activeDocument; 

var myPageItems = myDoc.allPageItems; 

var oStyle = myDoc.objectStyles.add({ 

    name: "myObjectStyle", 

    enableTextFrameAutoSizingOptions: true,

    textFramePreferences: { 

      autoSizingType: AutoSizingTypeEnum.HEIGHT_AND_WIDTH_PROPORTIONALLY, 

      autoSizingReferencePoint: AutoSizingReferenceEnum.LEFT_CENTER_POINT, 

    } 

  }); 

for (var i =0; i<myPageItems.length; i++){ 

if(myPageItems.constructor.name == "TextFrame"){ 

     var myOverFlowFrame = myPageItems

     if(myOverFlowFrame.overflows==true){

  myPageItems.appliedObjectStyle = myDoc.objectStyles.item("myObjectStyle");  

   

}

}

}

Thanks,

Prabu G

Thanks,
Prabu
Design smarter, faster, and bolder with InDesign scripting.
Translate
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 Expert ,
Jul 03, 2019 Jul 03, 2019

Hi Jeff,

Replace the line where you are creating the object style with the following line

set myObjectStyle to make object style with properties {name:"myObjectStyle", enable text frame auto sizing options:true, text frame preferences:{auto sizing type:height and width}}

-Manan

Translate
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
Valorous Hero ,
Jul 04, 2019 Jul 04, 2019

I found a few mistakes in your code:

tell application "Adobe InDesign CC 2019"

    set myDoc to active document

    tell myDoc

        set myTextFrame to every text frame whose overflows is true

        try

            set myObjectStyle to object style "myObjectStyle"

        on error

            set myObjectStyle to make object style with properties {name:"myObjectStyle", enable text frame auto sizing options:true, text frame preferences:{auto sizing type:height and width proportionally, auto sizing reference point:left center point}}

        end try

       

        repeat with i from 1 to (count of myTextFrame)

            set thisFrame to item i of myTextFrame

            set applied object style of thisFrame to myObjectStyle

        end repeat

    end tell

end tell

Translate
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
Explorer ,
Jul 04, 2019 Jul 04, 2019
LATEST

Thanks to all who replied to my question!

I took a bit of every answer to make my own version. Kasyan Servetsky​ the reason I was using every text frame of every story is because my overset frames where inline graphics, which are not caught if using only every text frame.

I was also having issues with the text frame keeping there previous setting even if applied the object style so I had to change the code to be able to clear the overrides.

Here's what I ended up with.

tell application "Adobe InDesign CC 2019"

  set myDoc to active document

  tell myDoc

  set myTextFrame to every text frame of every story of myDoc whose overflows is true

  try

  set myObjectStyle to object style "myObjectStyle" of myDoc

  on error

  set myObjectStyle to make object style with properties {name:"myObjectStyle"}

  end try

  set properties of myObjectStyle to {stroke weight:0, enable text frame auto sizing options:true, text frame preferences:{auto sizing type:height and width, auto sizing reference point:center point, use minimum height for auto sizing:true, minimum height for auto sizing:"1p", use minimum width for auto sizing:true, minimum width for auto sizing:"2p", use no line breaks for auto sizing:true}}

  repeat with i from 1 to (count of myTextFrame)

  set thisFrame to item i of myTextFrame

  tell thisFrame to apply object style using myObjectStyle clearing overrides yes

  end repeat

  end tell

end tell

Thanks again for all your help!

Translate
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