Skip to main content
Inspiring
January 11, 2023
Question

Find/Change object style via JavaScript in InDesign

  • January 11, 2023
  • 2 replies
  • 1264 views

Hi Community,

 

I'm facing an issue finding and replacing object style through JavaScript 

 

 

 

Using the following code:

var doc = app.activeDocument; 
app.findObjectPreferences = null;
app.findObjectPreferences.appliedObjectStyles = "[None]";
app.changeObjectPreferences.appliedObjectStyles = "Content";

Can someone help me to get the following things in Javascript:

 

This topic has been closed for replies.

2 replies

Community Expert
January 18, 2023

What exactly goes wrong with that?

 

Could you show the line of code where you assign it?

( EDIT: You already did after editing your reply.  So that is clear now. )

 

Look that up in the DOM description of InDesign. Search for ObjectTypes.GRAPHIC_FRAMES_TYPE.

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

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

Scroll down to the bottom where you see the usage. It's with Application.

So:

 

// This should work to set the object type:
app.findChangeObjectOptions.objectType = ObjectTypes.GRAPHIC_FRAMES_TYPE;

 

 

Regards,
Uwe Laubender
( Adobe Community Expert )

Community Expert
January 18, 2023
app.findChangeObjectOptions.objectType = ObjectTypes.GRAPHIC_FRAMES_TYPE;

is working on my German InDesign 2023 version 18.1 on Windows 10.

 

Regards,
Uwe Laubender
( Adobe Community Expert )

ShanpubAuthor
Inspiring
January 18, 2023

Hi, @Laubender I noticed this script is also working in my InDesign too but when I run the script it worked for only 1 image I have 100+ photos in one InDesign file.

For every image, I have to run the script again and again.

 

I use Adobe ExtendScript Toolkit CC to check code step by step in the steps Graphic Frame is not selected
Here is my code:

 

var doc = app.activeDocument; 


app.findObjectPreferences.appliedObjectStyles = "[None]";
app.changeObjectPreferences.appliedObjectStyles = app.documents[0].objectStyles.itemByName("Content");
app.findChangeObjectOptions.objectType = ObjectTypes.GRAPHIC_FRAMES_TYPE;

app.activeDocument.changeObject();

 

 

Community Expert
January 11, 2023

Hi @Shanpub ,

do you like to run ExtendScript code or UXP code?

It's more reliable to work with ExtendScript for now.

 

What do you see in the GUI of Find/Change after running only the following two lines:

app.findObjectPreferences.appliedObjectStyles = "[None]";
app.changeObjectPreferences.appliedObjectStyles = "Content";

Do you get an error on line 2 here?

Then address the object style not with its name, but with an object style object like that:

app.changeObjectPreferences.appliedObjectStyles = app.documents[0].objectStyles.itemByName("Content");

 

Then use the right scope, your active document, all documents and run the change of object styles:

// Scope is active document:
app.documents[0].changeObject();
// Scope is all open documents:
app.changeObject();

 

Regards,
Uwe Laubender
( Adobe Community Expert )

ShanpubAuthor
Inspiring
January 18, 2023

@Laubender, thanks for your reply.

The script works perfectly fine but the problem is how to select Graphic Frame Type



I want to select Type: Graphic Frames from the Find/Change -- Object menu:

 

I'm using the below code for select Graphic Frames from the type 

 

app.findChangeObjectOptions.objectType = ObjectTypes.GRAPHIC_FRAMES_TYPE;