Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


InDesign 13.0 - parsing all DOM objects - won't find some objects in multistate buttons

Community Beginner ,
Jul 29, 2021 Jul 29, 2021

Copy link to clipboard

Copied

Hello to the Community.

 

InDesign and InDesign Server 13.0.

 

For some reason, we want to parse all the DOM objects in a given InDesign document, thanks to some method like "document.allPageItems".

 

Among all these objects in the document, are some Interactive buttons, that were created by the person who designed the document. These interactive buttons have the [Normal] and [Rollover] multistates enabled (they trigger some objects in the document); the [Click] multistate was not enabled in our case.

 

The point is that, our script does not seem to be able to grab the objects in all the buttons' object states: it seems that it is only capable of parsing, those objects that are in the currently selected state (the one, that was lastly selected in InDesign by the InDesign user).

 

Should you try selecting the "other state" from the InDesign user interface ([Normal] or [Rollover], respectively), then should you save the file, close it, open it back, then run our script: only this recently selected state's objects will be grabbed by the document.allPageItems method (on the opposite, those, that were perfectly accessible to the script just beforehand, can no longer).

 

How could we have a real full access to all objects in the document DOM, whether they are related to a button state or another one?

 

Thanks for your advice!

 

Kind regards,

 

GB

TOPICS
How to, Publish online, Scripting

Views

42

Likes

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

correct answers 1 Correct answer

Adobe Community Professional , Jul 29, 2021 Jul 29, 2021
Hi GB, I discovered this about 10 years ago that allPageItems or allGraphics do only cover the active states of objects with states like MSOs, buttons and others. We can use a trick to access all objects of a document by ID and iterating through ID numbers instead of objects stored in the allPageItems array or the allGraphics array. So principally you could first check what's the highest ID number in the document and then loop by ID. Here we go: var doc=app.documents[0]; /* Last object creat...

Likes

Translate

Translate
Adobe Community Professional ,
Jul 29, 2021 Jul 29, 2021

Copy link to clipboard

Copied

Hi GB,

I discovered this about 10 years ago that allPageItems or allGraphics do only cover the active states of objects with states like MSOs, buttons and others. We can use a trick to access all objects of a document by ID and iterating through ID numbers instead of objects stored in the allPageItems array or the allGraphics array.

 

So principally you could first check what's the highest ID number in the document and then loop by ID.

Here we go:

var doc=app.documents[0];

/*
	Last object created has the highest id number.
	So we have to look into a finite known highest number.
*/
var tempObject = doc.rectangles.add();
var minID = 200 ;
var maxID = tempObject.id ;
tempObject.remove() ;

var objectsWithStatesIDs = [] ;

	/*
		for-loop:
		try/catch is necessary, because some objects are not valid or are very "instable":
		and are NOT usual pageItems. Like paragraphStyles or swatches.
	*/

// Get all ids of all objects that have states:

for( var n= minID; n<maxID; n++ )
{
	try{
		if( doc.pageItems.itemByID(n).hasOwnProperty("states") )
		{
			objectsWithStatesIDs[ objectsWithStatesIDs.length++ ] = n ;
		};
	}catch(e){continue};
};

 

That would result in an array of ID numbers of objects with states.

To access the objects directly, wherever they are, how deeply nested they are, you do that with:

doc.pageItems.itemByID( /*ID Number*/ );

 

Regards,
Uwe Laubender

( ACP )

Likes

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 Beginner ,
Jul 29, 2021 Jul 29, 2021

Copy link to clipboard

Copied

Hello Uwe,

 

Thanks for the suggestion.

 

But, according to the tests I made, based on your sample code, it seems that it returns an array of all objects that come with a State (i.e.: 23 buttons, in my case). I was already able to gather these 23 items with my own code, based on document.allPageItems.

 

However, I still miss the list of all "child objects" of these objects, for the states that were not selected by the designer in the InDesign interface. That's those "hidden" objects I need to parse.

 

Have you any idea?

Likes

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
Adobe Community Professional ,
Jul 29, 2021 Jul 29, 2021

Copy link to clipboard

Copied

Hm. I need a sample document to see into the issue then.

Could you provide one?

 

Put it on Dropbox or a similar service and post the link.

Or contact me with a private message and share the download link privately.

Just click my name and use the button "Send a message".

 

Another thought:
My code will gather all objects with states. That's the starting point. Also buttons in states of an MSO that are not active.

To look into every single state of such an object you have to loop the states of that object and access the first page item's allPageItems array.

 

Regards,
Uwe Laubender

( ACP )

Likes

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 Beginner ,
Jul 29, 2021 Jul 29, 2021

Copy link to clipboard

Copied

Meanwhile, I used your sample code, to parse all the 12000+ objects in my DOM, then I managed just now to determine, which of them were "children" of the button states.

 

Sorry for having disturbed uselessly!

Likes

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
Adobe Community Professional ,
Jul 29, 2021 Jul 29, 2021

Copy link to clipboard

Copied

LATEST

I'm glad you have this resolved!

 

Regards,
Uwe Laubender

( ACP )

Likes

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