Skip to main content
Participant
July 25, 2022
解決済み

script to change aspects of Paragraph and Object styles

  • July 25, 2022
  • 返信数 1.
  • 674 ビュー

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.

このトピックへの返信は締め切られました。
解決に役立った回答 brian_p_dts

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;

 

返信数 1

Community Expert
July 25, 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

-Manan
mgthomas82作成者
Participant
July 25, 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.

mgthomas82作成者
Participant
July 25, 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;

 


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!