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

script to change aspects of Paragraph and Object styles

Community Beginner ,
Jul 24, 2022 Jul 24, 2022

I realize these actions can be done manually, but I am trying to make one big script to run that makes multiple changes.  I have found various scripts (mostly the included FindChangeByList) but have not been able to find/figure out scripts that will make the following two things happen:

 

1) find all instances in the document of ParagraphStyle "ParagraphStyleName" and change the justtification (for example, to Center or to Left).

 

2) find all instances in the document of Object Style "ObjectStyleName" and turn on the Text Box Auto-Size feature, specify anchor point of TopCenter, and turn on No Line Breaks.

 

Any ideas?  Is this possible with scripting?  I have tried having the FindChangeByList find one paragraph style and change it to another, but it either doesn't work or I'm doing something wrong.  And from what I can tell FindChangeByList does not to objects.

TOPICS
How to , Scripting
738
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

correct answers 1 Correct answer

Community Expert , Jul 24, 2022 Jul 24, 2022

The API is your friend: https://www.indesignjs.de/extendscriptAPI/indesign-latest/#ObjectStyle.html

Code based on your spec: 

try { var doc = app.activeDocument; } catch(e) { exit(); }
var os = doc.objectStyles.itemByName("ObjectStyleName");
os.enableTextFrameAutoSizingOptions = true;
os.textFramePreferences.autoSizingType = AutoSizingTypeEnum.HEIGHT_AND_WIDTH;
os.textFramePreferences.autoSizingReferencePoint = AutoSizingReferenceEnum.TOP_CENTER_POINT;
os.textFramePreferences.useNoLineBreaksForA
...
Translate
Community Expert ,
Jul 24, 2022 Jul 24, 2022

Hi @mgthomas82,

Do you want to change the paragraphstyle/objectstyle itself or you want to add those properties to the text/frame that has these styles applied? Both the cases seem to be doable using script, the first case should be fine with FindChangeByList, so please clarify what you need. A sample of what is needed in the form of sample document or annotated screenshot would also help.

-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
Community Beginner ,
Jul 24, 2022 Jul 24, 2022

Thanks for the reply @Manan Joshi.

 

I have figured out the Paragraph Style part using the FindChangeByList.  The only thing I havn't figured out yet is changing the object style.  What I currently have is below.  The last two will not be commented out in the final version.  The blank line is where the Object Style change needs to go.  If FindChangeByList worked for Objects, it would look something like this:

 

object {appliedObjectStyle:"TextFrame1"} {appliedObjectStyle:"TextFrame2"} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false} Fix funky alignment issues.

 

I've tried about a dozen other "change object style" scripts I've found online and tried to alter them to fit my needs, but I can't get anything to work.

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 24, 2022 Jul 24, 2022

The API is your friend: https://www.indesignjs.de/extendscriptAPI/indesign-latest/#ObjectStyle.html

Code based on your spec: 

try { var doc = app.activeDocument; } catch(e) { exit(); }
var os = doc.objectStyles.itemByName("ObjectStyleName");
os.enableTextFrameAutoSizingOptions = true;
os.textFramePreferences.autoSizingType = AutoSizingTypeEnum.HEIGHT_AND_WIDTH;
os.textFramePreferences.autoSizingReferencePoint = AutoSizingReferenceEnum.TOP_CENTER_POINT;
os.textFramePreferences.useNoLineBreaksForAutoSizing = true;

 

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 Beginner ,
Jul 24, 2022 Jul 24, 2022

Works perfect!  Thank you for your insight.  This is my third day of delving into scripts for InDesign, and I've clearly got a lot to learn.  That link appears to be an invaluable resource.  Thank you!

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 24, 2022 Jul 24, 2022
LATEST

It's a wild ride, but yes, the API link is invaluable. Lots of fun stuff to do. Enjoy the journey! 

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