Skip to main content
Participant
April 11, 2024
Answered

How to script anchor allignments with objects?

  • April 11, 2024
  • 4 replies
  • 735 views

Hi,

 

I have to left allign hundreds of symbols - Are these below settings achievable in a script?

Using chatgpt I cant get the code to work in java and wasn't sure if this was possible.

 

This topic has been closed for replies.
Correct answer Robert at ID-Tasker

@Niko32511349sm76 

 

This should do the trick:

 

Before:

 

After:

 

Then you can set properties for the ObjectStyle.

 

4 replies

m1b
Community Expert
Community Expert
April 12, 2024

Hi @Niko32511349sm76,  this script tries to do what you want. You need to set up the object style first, and put the correct name for the object style into the script (replace 'My Object Style Here').

- Mark

 

/**
 * Apply Object Style To All Anchored Objects
 * @author m1b
 * @discussion https://community.adobe.com/t5/indesign-discussions/how-to-script-anchor-allignments-with-objects/m-p/14549295
 */
function main() {

    var anchoredObjectStyleName = 'My Object Style Here';

    var doc = app.activeDocument,
        objectStyle = doc.objectStyles.itemByName(anchoredObjectStyleName);

    if (!objectStyle.isValid)
        return alert('Could not find object style "' + anchoredObjectStyleName + '".');

    doc.stories.everyItem().pageItems.everyItem().appliedObjectStyle = objectStyle;

};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Apply Object Style To Anchored Objects');

 

brian_p_dts
Community Expert
Community Expert
April 11, 2024

Try a find for [Basic Graphics Frame] instead of [None]

brian_p_dts
Community Expert
Community Expert
April 11, 2024

Or, click on one of the objects and see what Object Style is applied. 

brian_p_dts
Community Expert
Community Expert
April 11, 2024

How can we target the anchored objects? Are they the only anchored objects in the doc? Do they have unique extensions (ie png or psd) from other images in the doc? Do they have Object Styles applied? Are other Object Styles in use in thr doc?

Participant
April 11, 2024

The object is a library element that I just tend to copy and paste into the text box and then anchor accordingly. These symbols are the only anchored object in the doc and have no object styles apploed.

Robert at ID-Tasker
Robert at ID-TaskerCorrect answer
Legend
April 11, 2024

@Niko32511349sm76 

 

This should do the trick:

 

Before:

 

After:

 

Then you can set properties for the ObjectStyle.

 

Robert at ID-Tasker
Legend
April 11, 2024

Yes, everything you can do manually in UI - can be scripted:

 

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#AnchoredObjectSetting.html

 

Participant
April 11, 2024

Thank you!