Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Bridge CS2: Scripting metadata w/o XMPScript?

New Here ,
Jul 09, 2007 Jul 09, 2007
Hi,
I need to get at strcutured data types (bag and alt) and I can't figure out how to do this in CS2, or if it's even possible. I've looked at the sample code in the scripting guide, but it doesn't seem to be of use. Here's what I've tried so far to get the first element in the alt structure xmpRights:UsageTerms field (labeled x-default):

var tn = new Thumbnail(fileName);
var md = tn.synchronousMetadata;
md.namespace = "http://ns.adobe.com/xap/1.0/rights/";
var rights = md.UsageTerms;
Window.alert(rights["UsageTerms/xmpRights:x-default"]);

Any suggestions?
TOPICS
Scripting
604
Translate
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 Employee ,
Jul 11, 2007 Jul 11, 2007
John,

I think you are misunderstanding two things about the Bridge Metadata object and XMP.

First, the Metadata object will return only Strings, not objects that represent nodes in the XMP data model.

Second, the xpath syntax you are trying to use to access the x-default member of the array is incorrect.

Try a script like the following:

#target bridge

var thumb = app.document.selections[0];
var md = thumb.synchronousMetadata;

try {
md.namespace = "http://ns.adobe.com/xap/1.0/rights/";
var usageTerms = md["UsageTerms[@xml:lang='x-default']"];
$.writeln( usageTerms );
md["UsageTerms[@xml:lang='x-default']"] = "Changed";
} catch( e ) {
$.writeln( e );
}

This may be a usable workaround for you if you need to deploy scripts that run on CS2 and cannot use XMPScript.

If you can I recommend using CS3 to develop the scripts for CS2 because it has some tools that may make your job easier. First, you can use utiltiy functions in XMPScript like XMPUtils.composeLanguageSelector() to create well-formed xpaths to use in your CS2 scripts. Second in Bridge CS3 exceptions thrown by the XMP toolkit when the Metadata object tries to get a property (ex: when a script calls var foo = md["bogus/xpath"]) will be reflected as JavaScript exceptions with the error message from the internal C++ exception. If, for example, the property name or namespace URI are bad, it's now much easier for the script writer to determine what is wrong than it was in CS2. This is one of my favorite, unsung new features in CS3.

-David
Translate
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
New Here ,
Jul 11, 2007 Jul 11, 2007
Thanks for the response David. I was actually playing around with it some more and got it working with this (way simpler than what i had been doing) code:

var tn = app.document.selections[0];
var md = tn.synchronousMetadata;
md.namespace = "http://ns.adobe.com/xap/1.0/rights/";
var rightsArray = md.UsageTerms;
var rights = rightsArray[0];

Sometimes less is more, I guess
But now I'm having another problem. I want to read data from a CSV file to get data which then gets input into image metadata.
I can handle the parsing and storing of the data, the only problem is that I don't know how to read a file! Any help would be appreciated.

-John
Translate
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
New Here ,
Jul 12, 2007 Jul 12, 2007
Hi,

To read a file use:

var f = new File("c:/myFile.txt");
f.open("r");
while(!f.eof)
{
$.writeln(f.readln());
}
f.close();

Hope it helps.
Translate
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
New Here ,
Jul 13, 2007 Jul 13, 2007
LATEST
Thanks a lot, it works like a charm
Translate
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