检查InDesign链接中是否缺少XMP-DocumentID和InstanceID [英] Check InDesign Links for missing XMP - DocumentID and InstanceID

查看:392
本文介绍了检查InDesign链接中是否缺少XMP-DocumentID和InstanceID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ExtendScript处理InDesignCC 2019中.indd文件的元数据信息.

I am using ExtendScript to work on metadata information of .indd files in InDesignCC 2019.

我的要求是,我需要访问与.indd文件关联的所有单个链接元数据,并查看是否缺少任何链接元数据DocumentIDInstanceID.如果任何链接元数据没有DocumentID和/或InstanceID属性的值,那么我需要显示与该链接关联的文件名,指示该特定文件缺少DocumentID和/或InstanceID.

My requirement is that I need to access all individual links metadata associated with the .indd file and see whether any of the links metadata is missing DocumentID and InstanceID. If any of the links metadata do not have a value for DocumentID and/or InstanceID properties then I need to display the file name associated with that link, indicating that, that particular file is missing a DocumentID and/or InstanceID.

我已使用以下脚本访问.indd文件的元数据.

I have used the below script to access the meta data of .indd file.

$.level=0

// load XMP Library
function loadXMPLibrary() {
    if (!ExternalObject.AdobeXMPScript) {
        try{ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');}
        catch (e){alert('Unable to load the AdobeXMPScript library!'); return false;}
    }
    return true;
}

var myFile= app.activeDocument.fullName;
 var myXmp = null;

// check library and file
if (loadXMPLibrary() && myFile !== null) {
    xmpFile = new XMPFile(myFile.fsName, XMPConst.FILE_INDESIGN, XMPConst.OPEN_FOR_UPDATE);
    myXmp = xmpFile.getXMP();
     $.writeln(xmpFile.getPacketInfo());
}


if (myXmp){
      $.writeln (myXmp);
    $.writeln (XMPFile.getFormatInfo(XMPConst.FILE_INDESIGN));

}

任何人都可以帮助我,如何进一步进行下去?

Can any one help me how can I proceed further in this?

推荐答案

一旦从链接(即xmpFile.getXMP())获得了XMP,您将需要:

Once you've obtained the XMP from the link, i.e. xmpFile.getXMP(), you'll need to:

  1. 使用 getProperty() 方法来检索特定元数据属性的值.

  1. Utilize the getProperty() method to retrieve the value of a specific metadata property.

DocumentIDInstanceID通常将与

Typically the DocumentID and InstanceID will be associated with the NS_XMP_MM schema namespace, which is described as:

NS_XMP_MM XMP数字资产管理架构的XML名称空间.

NS_XMP_MM The XML namespace for the XMP digital asset management schema.

例如,要获取DocumentID,您将执行以下操作:

For instance, to obtain the DocumentID you'll do something like the following:

var documentID = allXMP.getProperty(XMPConst.NS_XMP_MM, 'DocumentID', XMPConst.STRING);


解决方案:

下面的要点( example.jsx )执行以下操作:


Solution:

The gist below (example.jsx) performs the following:

  1. 检查是否打开了.indd文件,如果没有打开,则通知用户.

  1. Checks whether a .indd file is open and notifies the user if there is not one open.

加载AdobeXMPScript XMP库

Loads the AdobeXMPScript XMP Library

检查所有链接的状态是否为确定" ,即检查其是否不是已修改" 缺少" .如果任何链接状态不是"OK" ,则要求用户将其状态更新为"OK" .

Checks that the status of all Links are "OK", i.e. it checks that they are not "Modified", nor "Missing". If any link status is not "OK" the user is asked to update their status to "OK".

检查每个链接的资产是否都有DocumentIDInstanceID,并将它们的值记录到 JavaScript控制台.

Checks whether each linked asset has a DocumentID and InstanceID and logs their values to the JavaScript Console.

对于没有DocumentID和/或InstanceID的任何链接资产,将显示一个警告对话框,指示链接资产的名称和路径.

For any linked asset that does not have a DocumentID and/or InstanceID an alert dialog appears indicating the name and path to the linked asset.

example.jsx

$.level=0;

// Warn if there are no documents open.
if (!app.documents.length) {
  alert('Open a document and try again.', 'Missing Document', false);
  exit();
}

var doc = app.activeDocument;

// load XMP Library
function loadXMPLibrary() {
  if (!ExternalObject.AdobeXMPScript) {
    try {
      ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
    } catch (e) {
      alert('Failed loading AdobeXMPScript library\n' + e.message, 'Error', true);
      return false;
    }
  }
  return true;
}

// Check all link statuses are be ok.
function linksStatusCheck(doc) {
  for (var i = 0, len = doc.links.length; i < len; i++) {
    if (doc.links[i].status !== LinkStatus.NORMAL) {
      alert('The status of all links must be OK \nPlease update link status ' +
          'via the Links panel and try again', 'Link Status', true); 
      exit();
    }
  }
  return true;
}

function checkLinksXMP(doc) {
  for (var i = 0, len = doc.links.length; i < len; i++) {

    var linkFilepath = File(doc.links[i].filePath).fsName;
    var linkFileName = doc.links[i].name;

    var xmpFile = new XMPFile(linkFilepath, XMPConst.FILE_INDESIGN, XMPConst.OPEN_FOR_READ);
    var allXMP = xmpFile.getXMP();

    // Retrieve values from external links XMP.
    var documentID = allXMP.getProperty(XMPConst.NS_XMP_MM, 'DocumentID', XMPConst.STRING);
    var instanceID = allXMP.getProperty(XMPConst.NS_XMP_MM, 'InstanceID', XMPConst.STRING);

    // Useful for testing purposes....
    // Log properties for each link to the console.
    $.writeln('linkName: ' + linkFileName);
    $.writeln('filePath: ' + linkFilepath);
    $.writeln('DocumentID: ' + documentID);
    $.writeln('InstanceID: ' + instanceID);
    $.writeln('-------------------------------------');

    // Notify user when XMP is missing...
    if (!documentID && !instanceID) {
      alert('Link missing DocumentID and InstanceID\n' + 
          'Name: ' + linkFileName + '\n\n' +
          'Path: ' + linkFilepath, 'Missing XMP', true); 
    } else if (!documentID) {
      alert('Link missing DocumentID\n' + 
          'Name: ' + linkFileName + '\n\n' +
          'Path: ' + linkFilepath, 'Missing XMP', true); 
    } else if (!instanceID) {
      alert('Link missing InstanceID\n' + 
          'Name: ' + linkFileName + '\n\n' +
          'Path: ' + linkFilepath, 'Missing XMP', true);
    }
  }
}

if (loadXMPLibrary() && linksStatusCheck(doc)) {
  checkLinksXMP(doc);
}

这篇关于检查InDesign链接中是否缺少XMP-DocumentID和InstanceID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆