0


I have this script, which is displaying the  View --> Show Structure  pane:

with(obj.doc.xmlViewPreferences)
{
    // this opens the View --> Show Structure pane
    showStructure = true;

    showTagMarkers = true;
    showTaggedFrames = true;
    showTextSnippets = true;
}


However, the root node remains minimized. I found that holding the  Alt  key and clicking on this root node will expand the entire tree though.

So is there a way to programmatically execute "Alt + click" on this root node? I am using Windows, and CS5.

Ian Campbell
  • 2,678
  • 10
  • 56
  • 104

1 Answers1

1

You can get close by selecting nodes. E.g. to select all elements at the 3rd level and on the way expanding all on the levels above you would use

app.select(
    app.activeDocument.xmlElements.item(0) // the root element
    .xmlElements.everyItem() // repeat this line for each nesting level
    .xmlElements.everyItem() // and so forth
    .getElements() // provide an array with the actual selectable items
);

Repeat for the indicated line for deeper levels. With the following snippet you could also select XML attributes of those elements without children:

.xmlAttributes.everyItem()

Finally deselect to clean up the selection highlights.

app.select(null);

Edit: For an arbitrary depth you can use a loop. It just should ensure there are elements in the XMLElement / XMLAttribute collections before asking for them. The resulting code:

var items = app.activeDocument.xmlElements.everyItem();
while( items.xmlElements.length ) {
    items = items.xmlElements.everyItem();
    app.select(items.getElements());
    if( items.xmlAttributes.length )
        app.select(items.xmlAttributes.everyItem().getElements());
}
app.select(null);
Dirk
  • 666
  • 3
  • 6
  • This is awesome, thanks for the help @user1589939! Is there a way to determine the max number of xml layers? I noticed it does not execute when you go beyond the number of layers that the XML actually has... – Ian Campbell Aug 10 '12 at 19:25