Skip to main content
bduffy323
Inspiring
January 5, 2012
Answered

is there a way to retrieve all labels inserted in an object?

  • January 5, 2012
  • 1 reply
  • 1585 views

I'm looking to create a generic function that will return all labels that are inserted into any object using the fooBar.insertLabel("key","value").

psuedo code:

for each (key in foobar)

{

     alert(key + "-->"+ value)

}

I'm using CS 5.5.

This topic has been closed for replies.
Correct answer Harbs.

Harbs, I just dragged a page element to my desktop and looked at the xml created by the snippet and I see my key value pairs. I want to have a script that will save a temporary snippet file, parse my key value pairs, and then delete the file but I only want to export my selection as a snippet. Is that even possible?


Here's a generic function to extract all value pairs from an object with some code showing how to use it...

var vals = GetValuePairs(app.selection[0]);

for(var x in vals){

          alert(x + " is " + vals);

}

function GetValuePairs(obj){

          var file = File(Folder.temp + "/temp.idms");

          obj.exportFile(ExportFormat.INDESIGN_SNIPPET,file);

          file.open('r');

          var contents = file.read();

          file.close();

          var contXML = XML(contents);

          var vals = {}

          for each(var pair in contXML..KeyValuePair){

                    vals[pair.@Key] = pair.@Value;

          }

          return vals;

}

Harbs

1 reply

Inspiring
January 5, 2012

Not without exporting to idml and parsing that, it seems. See this thread: http://forums.adobe.com/message/3931458#3931458 .

Jeff

bduffy323
bduffy323Author
Inspiring
January 5, 2012

hmmm thats somewhat disappointing but I think you are right. Thanks for the response!