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

Best way to store document-specific script preferences?

Community Expert ,
May 09, 2020 May 09, 2020

Copy link to clipboard

Copied

Hello all, I was wondering if there was a best-practice way of storing data in an Illustrator document.

 

My quick attempt was to simply create a "Settings" layer (locked and hidden) with a PageItem named after the script, and store JSON in the "note" property. This works mostly ok, but has problems:

  • it is intrusive, being so visible in the layers palette
  • it can be inadvertently destroyed by using Undo after creating or updating it.

 

Any ideas would be much appreciated!

TOPICS
Scripting

Views

790

Translate

Translate

Report

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

correct answers 1 Correct answer

Participant , May 09, 2020 May 09, 2020

Hi, you can save your datas in your doc's metadatas 🙂

You have to check documentation about XML and XMP metadatas.

Votes

Translate

Translate
Adobe
Participant ,
May 09, 2020 May 09, 2020

Copy link to clipboard

Copied

Hi, you can save your datas in your doc's metadatas 🙂

You have to check documentation about XML and XMP metadatas.

Votes

Translate

Translate

Report

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 09, 2020 May 09, 2020

Copy link to clipboard

Copied

Have a look at the following for detailed description on XMP scripting API as mentioned by Steven

https://estk.aenhancers.com/10%20-%20Scripting%20Access%20to%20XMP%20Metadata/accessing-the-xmp-scri...

 

-Manan

Votes

Translate

Translate

Report

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 09, 2020 May 09, 2020

Copy link to clipboard

Copied

Thank you both, that is perfectly what I needed!

 

It did take me most of the morning to get it working though, so if it helps anyone, here's what I ended up with.

 

I used tenA's XMPtool.jsx. Thank you, tenA, if you're listening!

 

Here's tenA's code, with trivial modifications for my needs:

 

 XMPtool = {
    ns: "http://ns.adobe.com/xap/1.0/",
    prefix: "xmp:",
    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());
        var val;
        try {
            val = xmp.getProperty(this.ns, prop).toString();
        } catch (error) {}
        return val;
    },
    write: function (prop, val) {
        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);
    }
}

// set file reference to the active document
XMPtool.f = new File(app.activeDocument.fullName);

// example write
XMPtool.write('TestProperty1', 'TestValue1');

// example read
alert( XMPtool.read("TestProperty1") );

 

Votes

Translate

Translate

Report

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 09, 2020 May 09, 2020

Copy link to clipboard

Copied

You can add tag to an object on the document. Tags can be used to store key/value data in them. Tags can be stored on pageitems and not document object, so you will have to identify an object that you will use to save your data in. See the following for examples and more description

https://illustrator-scripting-guide.readthedocs.io/jsobjref/Tag/#jsobjref-tag

https://illustrator-scripting-guide.readthedocs.io/jsobjref/Tags/

 

-Manan

Votes

Translate

Translate

Report

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 09, 2020 May 09, 2020

Copy link to clipboard

Copied

LATEST

That's great too, Manan. I can think of a few uses for those! 😃

Votes

Translate

Translate

Report

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