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

Can't remove subtopics in index via JSX - Invalid request

Community Expert ,
Dec 18, 2023 Dec 18, 2023

Copy link to clipboard

Copied

 

app.activeDocument.indexes.item(0).topics.everyItem().topics.everyItem().remove();

 

Considering the above code, I am attempting to remove subtopics from a multilevel index in InDesign via scripting. I get an Invalid Object for this Request error. I have tried iterating through every top level topic, to the second tier, to the third tier, and removing the items in the third tier (iterating downwars using while(k--)) but I still get an invalid object for every one. There is no fourth level; I can get thirdLevel[k].name and it is a Topic, but it won't let me delete them. 

Anyone have any thoughts? Thanks. Edit: Edited out the error in the everyItem snippet above; still same result.


TOPICS
Scripting

Views

103

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

Copy link to clipboard

Copied

Hi @brianp311, I'm not experienced with these, but I can confirm something strange is happening for me too. See this demonstration:

var doc = app.activeDocument;

// make a top level topic and delete it
var t1 = doc.indexes[0].topics.add({name:'Topic 1 where am I?'});

// this works for me
t1.remove();

// make a top level topic
var t2 = doc.indexes[0].topics.add({name:'Topic 2'});

// add a child topic
var t3 = t2.topics.add({name:'Topic 3 Delete me if you can!'});

// this throws error for me
t3.remove();

 

Screenshot 2023-12-19 at 17.55.21.png

Above script tested on Indesign 19.1,  MacOS 14.2. And by the way I can do this without an error:

// removing t3's parent works for me
// and removes t3 along with it, as expected
t2.remove();

 

So, we cannot delete a child topic of a topic. Seems like a bug to me. It be good to hear from someone with experience in this area though.

- Mark

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 ,
Dec 19, 2023 Dec 19, 2023

Copy link to clipboard

Copied

LATEST

FWIW Mark and others who may come across the same bug, I basically re-created the index by storing pagerefs and ref type for the sublayer I was working on, as well as the top layer, and then deleting all the topics and re-creating using the pageRef's source text and reftype. I essentially had to remove all third-tier elements, leave second-tier elements intact while also copying them to become toplevel markers. It was a bit of an exercise but it works. 

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