2012-08-07 49 views
0


我有此脚本,其显示所述  View --> Show Structure  窗格:
InDesign CS5脚本:如何在XML结构窗格上自动执行“Alt +单击”?

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

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


但是,根节点保持最小化。我发现持有  Alt  键并点击这个根节点会使展开整个树。

那么有没有办法在此根节点上以编程方式执行“Alt + click”? 我使用Windows和CS5。

回答

1

您可以通过选择节点关闭。例如。在第三级,并扩大对所有级别的方式来选择所有元素上面,你会使用

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

重复为更深层次的指示线。随着下面的代码片段,你也可以选择那些元素的XML属性没有子女:

.xmlAttributes.everyItem() 

最后取消选择要清理的选择亮点。

app.select(null); 

编辑:对于任意深度,您可以使用循环。在请求它们之前,它应该确保XMLElement/XMLAttribute集合中有元素。由此产生的代码:

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); 
+0

这太棒了,谢谢你的帮助@ user1589939!有没有办法确定最大数量的xml图层?我注意到,当你超出XML实际拥有的层数时,它不会执行...... – 2012-08-10 19:25:18

相关问题