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

Find/Change object style via JavaScript in InDesign

Explorer ,
Jan 11, 2023 Jan 11, 2023

Copy link to clipboard

Copied

Hi Community,

 

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

 

Untitled 2.png

 

 

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:

 

Untitled.png

TOPICS
Scripting , UXP Scripting

Views

602

Translate

Translate

Report

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 ,
Jan 11, 2023 Jan 11, 2023

Copy link to clipboard

Copied

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 )

Votes

Translate

Translate

Report

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 ,
Jan 18, 2023 Jan 18, 2023

Copy link to clipboard

Copied

@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:

Shanpub_0-1674036704088.png

 

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

 

app.findChangeObjectOptions.objectType = ObjectTypes.GRAPHIC_FRAMES_TYPE;

 

 

 

Votes

Translate

Translate

Report

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 ,
Jan 18, 2023 Jan 18, 2023

Copy link to clipboard

Copied

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 )

Votes

Translate

Translate

Report

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 ,
Jan 18, 2023 Jan 18, 2023

Copy link to clipboard

Copied

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 )

Votes

Translate

Translate

Report

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 ,
Jan 18, 2023 Jan 18, 2023

Copy link to clipboard

Copied

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();

 

 

Votes

Translate

Translate

Report

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 ,
Jan 18, 2023 Jan 18, 2023

Copy link to clipboard

Copied

LATEST

If that's the case, it would be a bug with InDesign.

 

The workaround would be to allow for all graphic types, run the script with findObject() instead of changeObject() and iterate the resulting array of found frames to check for the graphic type of a found frame individually and if of type graphic frame, apply the object style in question.

 

Please provide a sample InDesign document where you see the issue.

 

Thanks,
Uwe Laubender
( Adobe Community Expert )

 

Votes

Translate

Translate

Report

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