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

Script to copy variables into metadata

New Here ,
May 10, 2016 May 10, 2016

I have various text anchors with given as variables. I am able to alert the object information of variables in an illustrator document using the script below. Is there a way of copying the contents of those into the metadata? I don't mind which field of metadata. Thanks.

var idoc = app.activeDocument; 
var vars = idoc.variables; 
for (j=0; j<vars.length; j++) 
    alert(vars.name + ' : ' + vars.pageItems[0].contents); 
TOPICS
Scripting
1.5K
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
Community Expert ,
May 10, 2016 May 10, 2016
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 ,
May 11, 2016 May 11, 2016

To clarify, I would like to write to the metadata form the variable object data in the file, not write the metadata to an exported file.

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
Community Expert ,
May 11, 2016 May 11, 2016

You can use it to write opened document metadata.

To set custom metadata and get opened document path(ex: XMPtool.f = app.activeDocument.fullName).

Call the write function with previouse path.

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 ,
May 12, 2016 May 12, 2016

Thanks for your help, but sorry, I don't follow at all. Why are we talking about previous paths? Could you specify the script which would enable me to write to the keywords metadata? I've tried with the GitHub script and it isn't doing anything.

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
Community Expert ,
May 12, 2016 May 12, 2016
LATEST

Try it:

XMPtool = {

    ns : "http://ns.example.com/metawrite/1.0/", //You shuld rewrite your own Name Space.

    prefix : "Vriable:", //You can set your prefix

    f : new Object(),

    read : function(prop){

        if(xmpLib==undefined) var xmpLib = new ExternalObject('lib:AdobeXMPScript');

        var xmpFile = new XMPFile(this.f.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_READ);

        var xmpPackets = xmpFile.getXMP();

        var xmp = new XMPMeta(xmpPackets.serialize());

        alert(xmp.getProperty(this.ns, prop).toString());

        },

    write : function(prop, val){ //f:fileObject, arg1:String, arg2:String

        if(xmpLib==undefined) var xmpLib = new ExternalObject('lib:AdobeXMPScript');

        var xmpFile = new XMPFile(this.f.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);

        var xmp = xmpFile.getXMP();

        var mt = new XMPMeta(xmp.serialize());

        XMPMeta.registerNamespace(this.ns, this.prefix);

        mt.setProperty(this.ns, prop, val);

        if (xmpFile.canPutXMP(xmp)) xmpFile.putXMP(mt);

        xmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);

        }

    }

//If you want write into activeDocument, Set activeDocuments fullName property like below.

XMPtool.f = app.activeDocument.fullName;

XMPtool.write("key1", "Your value");

XMPtool.read("key1");

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