在为链接生成丢失的documentId和InstanceIds之后,需要为.indd元信息添加documentId和instanceId标签

时间:2019-06-18 14:46:04

标签: adobe adobe-indesign extendscript xmp

使用ExtendScript,我正在使用{{3}上的参考代码来更新Indesign(DocumentId)文件的链接中缺少的InstanceId.indd }。这样可以正常工作,并且可以正确更新缺少DoumentIdInstanceId的每个链接。但是,现在我面临的问题是,.indd文件本身具有元信息,在这些特定链接中缺少这些新生成的DocumentIdInstanceId

请参考以下.indd文件的元信息,其中包含四个资源,以便更好地理解。在这里,它具有四个资源,两个.psd文件和两个.ai文件。 .indd文件的元信息包含两个<stRef:instanceID>资源的<stRef:documentID>.ai,缺少这些标签(<stRef:instanceID><stRef:documentID>)其他两个.psd资源。即使在为.psd文件生成丢失的DocumentIdInstanceId之后,在这两个资源的.indd文件元信息中,这两个标签<stRef:instanceID><stRef:documentID>仍然丢失。即使在.indd文件元信息中,如何更新这些丢失链接的DocumentId和InstanceId?

<xmpMM:Manifest>
  <rdf:Bag>
    <rdf:li rdf:parseType="Resource">
      <stMfs:linkForm>ReferenceStream</stMfs:linkForm>
      <xmpMM:placedXResolution>300.00</xmpMM:placedXResolution>
      <xmpMM:placedYResolution>300.00</xmpMM:placedYResolution>
      <xmpMM:placedResolutionUnit>Inches</xmpMM:placedResolutionUnit>
      <stMfs:reference rdf:parseType="Resource">
        <stRef:lastURL>file:///Users/superadmin/Downloads/266x165mm_VPA_WS_SP_M-1F/Links/6604_RGB.psd</stRef:lastURL>
      </stMfs:reference>
    </rdf:li>
    <rdf:li rdf:parseType="Resource">
      <stMfs:linkForm>ReferenceStream</stMfs:linkForm>
      <xmpMM:placedXResolution>72.00</xmpMM:placedXResolution>
      <xmpMM:placedYResolution>72.00</xmpMM:placedYResolution>
      <xmpMM:placedResolutionUnit>Inches</xmpMM:placedResolutionUnit>
      <stMfs:reference rdf:parseType="Resource">
        <stRef:lastURL>file:///Users/superadmin/Downloads/266x165mm_VPA_WS_SP_M-1F/Links/Silver_001_RGB.psd</stRef:lastURL>
      </stMfs:reference>
    </rdf:li>
    <rdf:li rdf:parseType="Resource">
      <stMfs:linkForm>ReferenceStream</stMfs:linkForm>
      <xmpMM:placedXResolution>72.00</xmpMM:placedXResolution>
      <xmpMM:placedYResolution>72.00</xmpMM:placedYResolution>
      <xmpMM:placedResolutionUnit>Inches</xmpMM:placedResolutionUnit>
      <stMfs:reference rdf:parseType="Resource">
        <stRef:instanceID>uuid:d34cbf16-4c87-4344-a0db-6cf67ffe6f84</stRef:instanceID>
        <stRef:documentID>xmp.did:fd9d95eb-fe2d-4fca-92a2-1906d98a10f4</stRef:documentID>
        <stRef:lastURL>file:///Users/superadmin/Downloads/266x165mm_VPA_WS_SP_M-1F/Links/bkgd_rgb_en.ai</stRef:lastURL>
    </stMfs:reference>
    </rdf:li>
    <rdf:li rdf:parseType="Resource">
      <stMfs:linkForm>ReferenceStream</stMfs:linkForm>
      <xmpMM:placedXResolution>72.00</xmpMM:placedXResolution>
      <xmpMM:placedYResolution>72.00</xmpMM:placedYResolution>
      <xmpMM:placedResolutionUnit>Inches</xmpMM:placedResolutionUnit>
      <stMfs:reference rdf:parseType="Resource">
        <stRef:instanceID>uuid:afd031b3-018a-434a-989f-c0e35ff0cebb</stRef:instanceID>
        <stRef:documentID>xmp.did:f4cbc476-258f-4807-8734-d8afc200fbfb</stRef:documentID>
        <stRef:lastURL>file:///Users/superadmin/Downloads/266x165mm_VPA_WS_SP_M-1F/Links/bax_logo_whitebox_cmyk.ai</stRef:lastURL>
      </stMfs:reference>
    </rdf:li>
  </rdf:Bag>
</xmpMM:Manifest>

1 个答案:

答案 0 :(得分:1)

在以下任何一种情况下,都会遇到:的{​​{1}}中的<stRef:instanceID><stRef:documentID>未被反映在<xmpMM:Manifest>文件元中的问题:< / p>

  • 通过在InDesign的“链接”面板中单击“ “更新链接” ”来手动更新链接。
  • 或者根本不更新链接状态。

在将丢失的<rdf:Bag>indd添加到链接资源之后,您需要通过脚本以编程方式更新InDesign链接状态。您可以利用以下功能来做到这一点:

DocumentID

script.jsx

下面是一个完整的工作版本,它将所有缺少的InstanceID和/或/** * Update all document links whose state is outdated. * @param {Object} doc - A reference to the .indd to update. */ function updateOutdatedLinks(doc) { for (var i = 0, len = doc.links.length; i < len; i++) { var link = doc.links[i]; if (link.status === LinkStatus.LINK_OUT_OF_DATE) { link.update(); } } } 添加到相关链接,然后在DocumentID

中更新其状态。
InstanceID

注释:

  1. 请注意,在检查并更新所有丢失的.indd#target indesign $.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; /** * Loads the AdobeXMPScript library. * @returns {Boolean} True if the library loaded successfully, otherwise false. */ 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; } /** * Checks the status of all Indesign links, and exits if the state is not OK. * @param {Object} doc - A reference to the .indd to check. * @returns {Boolean} True if the state of all links are OK, otherwise false. */ 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; } /** * Generate a unique identifier (UUID/GUID). Note this runs on macOS only. * @returns {String} - The generated unique identifier. */ function generateUUID() { var cmd = 'do shell script "uuidgen | tr -d " & quoted form of "-"'; return app.doScript(cmd, ScriptLanguage.applescriptLanguage); } /** * Add an XMP property and value to a given file. * @param {String} filePath - Path to the file/asset to add the XMP metadata. * @param {String} xmpProperty - Name of the XMP property. * @param {String} xmpValue - Value to assign to the XMP property. */ function addXmpPropertyAndValue(filePath, xmpProperty, xmpValue) { var xmpFile = new XMPFile(filePath, XMPConst.FILE_UNKNOWN, XMPConst.OPEN_FOR_UPDATE); var xmp = xmpFile.getXMP(); xmp.setProperty(XMPConst.NS_XMP_MM, xmpProperty, xmpValue); if (xmpFile.canPutXMP(xmp)) { xmpFile.putXMP(xmp); } xmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY); } /** * Add an `instanceID` to the XMP packet of a file/asset. * @param {String} filePath - Path to the file/asset to add the XMP metadata. * @param {String} uuid - The unique identifier (UUID/GUID) value to add. */ function addInstanceID(filePath, uuid) { addXmpPropertyAndValue(filePath, 'InstanceID', 'xmp.iid:' + uuid); } /** * Add an `documentID` to the XMP packet of a file/asset. * @param {String} filePath - Path to the file/asset to add the XMP metadata. * @param {String} uuid - The unique identifier (UUID/GUID) value to add. */ function addDocumentID(filePath, uuid) { addXmpPropertyAndValue(filePath, 'DocumentID', 'xmp.did:' + uuid); addXmpPropertyAndValue(filePath, 'OriginalDocumentID', 'xmp.did:' + uuid); } /** * Adds both `instanceID` and `documentID` to the XMP packet of a file/asset. * Note: Both properties share the same unique identifier (UUID/GUID). * @param {String} filePath - Path to the file/asset to add the XMP metadata. * @param {String} uuid - The unique identifier (UUID/GUID) value to add. */ function addDocumentIDAndInstanceID(filePath) { var uuid = generateUUID(); addInstanceID(filePath, uuid); addDocumentID(filePath, uuid); } /** * Checks both XMP properties, `DocumentID` and `instanceID`, exist in each * linked file associated with an InDesign document (.indd). When a link does * not contain the aforementioned properties a new one is added. * @param {Object} doc - A reference to the .indd to check. */ function checkLinksXMP(doc) { for (var i = 0, len = doc.links.length; i < len; i++) { var link = doc.links[i]; var linkFilepath = File(link.filePath).fsName; var linkFileName = link.name; var xmpFile = new XMPFile(linkFilepath, XMPConst.FILE_INDESIGN, XMPConst.OPEN_FOR_READ); var xmp = xmpFile.getXMP(); // Retrieve values from external links XMP. var documentID = xmp.getProperty(XMPConst.NS_XMP_MM, 'DocumentID', XMPConst.STRING); var instanceID = xmp.getProperty(XMPConst.NS_XMP_MM, 'InstanceID', XMPConst.STRING); // Add missing XMP property/values... if (!documentID && !instanceID) { addDocumentIDAndInstanceID(linkFilepath); } else if (!documentID) { addDocumentID(linkFilepath, generateUUID()); } else if (!instanceID) { addInstanceID(linkFilepath, generateUUID()); } } } /** * Update all document links whose state is outdated. * @param {Object} doc - A reference to the .indd to update. */ function updateOutdatedLinks(doc) { for (var i = 0, len = doc.links.length; i < len; i++) { var link = doc.links[i]; if (link.status === LinkStatus.LINK_OUT_OF_DATE) { link.update(); } } } if (loadXMPLibrary() && linksStatusCheck(doc)) { checkLinksXMP(doc); updateOutdatedLinks(doc); // <-- Update status after. } 之后,我们如何调用DocumentID函数,即在脚本中查看此部分:

    InstanceID
  2. (另请注意),您可以看到,在updateOutdatedLinks函数中,我们包含以下条件逻辑,即下面的这一部分:

    // ...
    
    if (loadXMPLibrary() && linksStatusCheck(doc)) {
      checkLinksXMP(doc);
      updateOutdatedLinks(doc); // <-- Update status after.
    }
    

    请注意,如果两个checkLinksXMP和&// Add missing XMP property/values... if (!documentID && !instanceID) { addDocumentIDAndInstanceID(linkFilepath); } else if (!documentID) { addDocumentID(linkFilepath, generateUUID()); } else if (!instanceID) { addInstanceID(linkFilepath, generateUUID()); } 都丢失了(即上面的第一个条件),我们将两个值都使用相同的UUID / GUID。参照documentID函数中的逻辑,您可以看到两个属性共享相同的UUID / GUID。

  3. 除了上述脚本外,您还需要添加其他功能,以保存调用instanceID函数后对addDocumentIDAndInstanceID所做的更改。例如

    .indd
  4. updateOutdatedLinks函数替换为works cross-platform