需要XMP对象的setProperty语法 [英] need setProperty syntax for XMP object
问题描述
我正在随机生成 DocumentID
和 InstanceID
,但是在设置属性 DocumentID时遇到问题
和 InstanceID
到xmp对象。
I am randomly generating DocumentID
and InstanceID
, but facing problem in setting property DocumentID
and InstanceID
to the xmp object.
如何设置生成的 DocumentID
和 InstanceID
到我的 allXMP
?
How can I set the generated DocumentID
and InstanceID
to my allXMP
?
var xmpFile = new XMPFile(linkFilepath, XMPConst.FILE_INDESIGN, XMPConst.OPEN_FOR_UPDATE);
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);
documentID = randomString(32);
instanceID = randomString(32);
// ???? Here I need to set DocumentID and InstanceID to allXMP
if (xmpFile.canPutXMP(allXMP)) {
xmpFile.putXMP(allXMP);
xmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
}
推荐答案
您可以使用 <$ c $ em> AdobeXMPScript 库中的$ c> setProperty() 方法来创建和设置 DocumentID
的值和 InstanceID
You can utilize the setProperty()
method in the AdobeXMPScript library to create and set the value for DocumentID
and InstanceID
下面是几个帮助函数,用于添加 DocumentID
和 InstanceID
。
Below are a couple of helper functions for adding a DocumentID
and InstanceID
.
// Note: This function works on macOS only
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.
function addXmpPropertyAndValue(filePath, xmpProperty, xmpValue) {
var xmpFile = new XMPFile(filePath, XMPConst.FILE_UNKNOWN, XMPConst.OPEN_FOR_UPDATE);
var allXMP = xmpFile.getXMP();
allXMP.setProperty(XMPConst.NS_XMP_MM, xmpProperty, xmpValue);
if (xmpFile.canPutXMP(allXMP)) {
xmpFile.putXMP(allXMP);
}
xmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
// Useful for testing purposes....
alert('Added: ' + xmpProperty + '\n' +
'value: ' + xmpValue + '\n\n' +
'Path: ' + filePath, 'Updated XMP', false);
}
要添加 instanceID
如下调用 addXmpPropertyAndValue
函数:
// The `linkFilepath` argument should be the filepath to the Link you want to update
addXmpPropertyAndValue(linkFilepath, 'InstanceID', 'xmp.iid:' + generateUUID());
要添加 DocumentID
,请调用 addXmpPropertyAndValue
函数如下:
To add an DocumentID
invoke the addXmpPropertyAndValue
function as follows:
// The `linkFilepath` argument should be the filepath to the Link you want to update
addXmpPropertyAndValue(linkFilepath, 'DocumentID', 'xmp.did:' + generateUUID());
附加说明:
生成 DocumentID
和 InstanceID $ c $的值时c>准则指出:
应确保ID是全局唯一的(实际上,这意味着概率碰撞非常遥远以至于实际上是不可能的)。通常使用128位或144位数字,编码为十六进制字符串
摘录(以上)可以在
The excerpt (above) can be found on page 19 of Partner's guide to XMP for Dynamic Media (PDF)
很遗憾, ExtendScript 没有提供内置功能来生成全局唯一标识符(GUID)。但是macOS确实包含 uuidgen
Unfortunately, ExtendScript does not provide a built-in feature to generate a globally unique identifier (GUID). However macOS does include uuidgen
which is a command-line utility/library for
generating unique identifiers (UUID/GUID).
helper函数(以上):
The helper function (above):
function generateUUID() {
var cmd = 'do shell script "uuidgen | tr -d " & quoted form of "-"';
return app.doScript(cmd, ScriptLanguage.applescriptLanguage);
}
仅在macOS上运行。它利用AppleScript运行 uuidgen
命令。
runs on macOS only. It utilizes AppleScript to run the uuidgen
command.
您可能想用这种方式生成标识符您当前 randomString(32)
函数调用中的值。
You may want to generate the identifier this way instead of your current randomString(32)
function call.
这篇关于需要XMP对象的setProperty语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!