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

Adding metadata from another (raster) file to an AI file

Community Expert ,
Feb 03, 2016 Feb 03, 2016

Copy link to clipboard

Copied

Hi all. I've been using the below script to select a folder of JPEGs, place them on an existing AI template file, and save AI files elsewhere. It was cribbed from here originally and messed about with by me until it worked for what I wanted, which it does very nicely.

What I'm coming up against now is I need a way of applying a set of metadata -- specifically keywords -- quickly to the AI files at the time they're created, hopefully minimizing any manual entry the users will have to do. The JPEGs have (or can have) metadata applied to them via an action when they're saved in PS. But it seems you can't do this in Illustrator. So what I want to know is: can the keywords from the JPEG files be applied to the AI files as they're being saved, and how would one go about this?

Assume I'm a beginner here. Profuse thanks in advance for any assistance.

/**********************************************************

 

Place_JPG_to_AI.jsx

DESCRIPTION

This script gets files specified by the user from the 

selected folder and batch processes them and saves them 

as AIs in the user desired destination with the same 

file name.

Modified from Adobe supplied scripts and

scripts by Carlos Canto on Illustrator Scripting

by Larry G. Schneider 072911

Note to Thatcham users: Modified from the above by Douglas Roberts

 

**********************************************************/ 

 

// uncomment to suppress Illustrator warning dialogs 

function jpegMET(){

app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS; 

 

var destFolder, sourceFolder, files, fileType; 

 

// Select the source folder. 

sourceFolder = Folder.selectDialog( 'Select the folder containing M.E.T. JPEG files, you beauty', '~' ); 

 

// If a valid folder is selected 

if ( sourceFolder != null ) 

     files = new Array(); 

      

     // Get all files with JPEG extension

     files = sourceFolder.getFiles("*.jpg"); 

      

     if ( files.length > 0 ) 

     { 

          // Get the destination to save the files 

          destFolder = Folder.selectDialog( ' Hey buster. Select the folder where you want to save the AI files.', '~' ); 

           

          for ( i = 0; i < files.length; i++ ) 

          { 

               var idoc = app.open(File("/G/Design & Publishing/Elements/Master Templates/Re-Engineering Templates/Illustrator/MET Template 106.82x60.ai"));  // open template document. Change the file path for different templates

              

               var ilayer = idoc.layers["Image"];

 

               var iplaced = ilayer.placedItems.add();  // add image place holder 

              

               iplaced.file = (files);  // place file 

                

                var PosXY=new Array(2);  // ensure position is 0,0

                PosXY[0]=0; 

                PosXY[1]=0;

                iplaced.position = PosXY;

                iplaced.embed();

                

               ilayer.dimPlacedImages = false;   // do not dim images       

               ilayer.locked = true;  // lock layer 

               ilayer.printable = true;

                

               var docName = decodeURI(files.name.replace('.jpg', '.ai'));   // take the first part of the placed file name for the new document 

              

               var test = destFolder.getFiles(docName);

               if(test != 0){

                   var overWrite = confirm("A file with this name already exists. Continue and overwrite?");

                   if (overWrite){

                        var destFile = new File(destFolder + "/" +  docName);   // make a new file in the dest folder 

                        }else{

                   return;

                   }

               }else{

                   var destFile = new File(destFolder + "/" +  docName);   // make a new file in the dest folder 

                   }

               var options = new IllustratorSaveOptions();   // new save options 

               options.compatibility = Compatibility.ILLUSTRATOR15;   // save as AICS5. May want to update if we go to CC

               options.pdfCompatible = true; // needs to be set to view links in InDesign

                

               // Export as AI 

               idoc.saveAs(destFile,  options);  // save the file in the dest folder 

             

           

          } 

          alert( 'Way to go champ! Files are saved as AI in ' + destFolder ); 

          // Remove JPEGs from source folder

          var removeFiles = sourceFolder.getFiles(); 

                for(var a=0;a<removeFiles.length;a++){ 

            removeFiles.remove();

            }

     } 

     else 

     { 

          alert( 'No matching files found.' ); 

     } 

}

 

app.userInteractionLevel = UserInteractionLevel.DISPLAYALERTS 

}

jpegMET ()

TOPICS
Scripting

Views

1.5K

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
Adobe
Community Expert ,
Feb 04, 2016 Feb 04, 2016

Copy link to clipboard

Copied

To simplify this request somewhat: I don't know how to approach metadata in Illustrator scripting at all, and any pointers or a starting point would be useful. I'm having trouble finding such things in the object reference.

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 ,
Feb 04, 2016 Feb 04, 2016

Copy link to clipboard

Copied

Here is a sample solution of manipurate XMP metadata.

XMPtool = {

  ns : "http://ns.chuwa.sytes.net/idcomment/1.0/",

  prefix : "ID_meta:",

  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, val1:String, val2: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);

  }

  }

XMPtool.f = File.openDialog ();

XMPtool.write("memo1", "てすとの文字列ですね?");

XMPtool.read("memo1");

Probably, It helps your work.

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 ,
Feb 05, 2016 Feb 05, 2016

Copy link to clipboard

Copied

Thank you, but I think I need to start nearer the beginning here... what is this script doing?

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 ,
Feb 05, 2016 Feb 05, 2016

Copy link to clipboard

Copied

Previous script can get and set custom metadata like below.

スクリーンショット 2016-02-05 18.28.57.png

The Metamemo panel can R/W custom informations in XMP Meta Data field. Previous Code in it.

And We can read it in XMP Row data...

スクリーンショット 2016-02-05 18.31.24.png

Sample file that you can check XMP Meta data:

https://drive.google.com/file/d/0B8WPQj-WNG_TQ1hpUnA0Nm56WkE/view?usp=sharing

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 ,
Feb 08, 2016 Feb 08, 2016

Copy link to clipboard

Copied

Thanks Ten A, I am very interested in exploring this method!

EDIT: Does not appear to work in CS6?

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 ,
Feb 08, 2016 Feb 08, 2016

Copy link to clipboard

Copied

You can read more Inforrmation in "Javascript Tools Guide CC.pdf", 10 Scripting Access to XMP Metadata.

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 ,
Feb 08, 2016 Feb 08, 2016

Copy link to clipboard

Copied

Thanks Ten A, a forum search kicked this up:

Adobe Illustrator Tags

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 ,
Feb 08, 2016 Feb 08, 2016

Copy link to clipboard

Copied

dougofakkad, I would suggest using Bridge and metadata templates after creation of the Ai files, however I don’t know if the info you wish to include is variable or static. Can you describe in more detail what you require?

How exactly do you automate saving keywords in Photoshop, via the script events manager via a save or close event and the “Update File Info.jsx” script? If so is this manual entry or metadata template?

In CS6, when I place a JPEG that has keyword metadata into Illustrator as a linked image, then use the links panel “link file info” there are NO keywords displayed, which leads me to suspect that Illustrator does not pull through this metadata (however it may be accessible via scripting, this is just the GUI). When I view the linked JPEG in Bridge or Photoshop and use file info, the keywords are listed… So I am guessing that you may need to look outside of Illustrator to obtain the linked file metadata, which is presuming that no images are embedded, just linked.

I imagine that a script would need to open up each linked JPEG in Photoshop or Bridge, extract the keywords and then store them in memory and repeat for each placed image, before adding them as metadata to the Illustrator file (or add the keywords one at a time from each linked image rather than storing them in a list. I don’t know how duplicate keywords would be handled).

Sorry I can’t help with scripting.

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 ,
Feb 09, 2016 Feb 09, 2016

Copy link to clipboard

Copied

Hi Stephen,

Yeah I was going to use an action on save & close to add keywords in Photoshop. I have been reading around but I think this task might be beyond be, for now at least. I just can't seem to find a way in that I can get a handle on understanding.

Basically our IT dept. wants us to use a flat file system for storing our AI files in the future (so they can be easily accessible via XML that someone else is writing...), so I was trying to think of ways of differentiating between different projects that wouldn't be a headache for our illustrators. I think I've come up with a way we could use smart collections in Bridge though.

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 ,
Feb 09, 2016 Feb 09, 2016

Copy link to clipboard

Copied

LATEST

Hi dougofakkad, if you have a solution with Bridge and Smart Collections then that is great.

A solution may be possible using ExifTool to add keywords or other metadata to the Illustrator file based on the keywords used in the various JPEG files, however there are too many unknowns as things stand.

Good luck with your project.

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