Skip to main content
brian_p_dts
Community Expert
Community Expert
December 19, 2023
Question

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

  • December 19, 2023
  • 1 reply
  • 215 views

 

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.


This topic has been closed for replies.

1 reply

m1b
Community Expert
Community Expert
December 19, 2023

Hi @brian_p_dts, 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();

 

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

brian_p_dts
Community Expert
Community Expert
December 20, 2023

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.