How to detect new units if RulerUnits.Unknown

The script didn’t detect the feet units
  • stDim:h — height,
  • stDim:unit — ruler units.
<xmpTPg:NPages>1</xmpTPg:NPages>
<xmpTPg:HasVisibleTransparency>False</xmpTPg:HasVisibleTransparency>
<xmpTPg:HasVisibleOverprint>False</xmpTPg:HasVisibleOverprint>
<xmpTPg:MaxPageSize rdf:parseType="Resource">
<stDim:w>1366.000000</stDim:w>
<stDim:h>768.000000</stDim:h>
<stDim:unit>Pixels</stDim:unit>
</xmpTPg:MaxPageSize>
  • get data from activeDocument.XMPString,
  • find the field stDim:unit,
  • retrieve the name of the units, e.g. by searching for matches of the exec() string.
var doc = activeDocument;
if (doc.rulerUnits == RulerUnits.Unknown) {
var xmp = doc.XMPString;
var units = '';
if (/stDim:unit/i.test(xmp)) {
units = /<stDim:unit>(.*?)<\/stDim:unit>/g.exec(xmp)[1];
}
alert('Current units: ' + units);
}
After saving the document the units are read from XMP

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
AiScripts

AiScripts

Sergey Osokin. I’m a illustrator & Script Developer (Ai, Ps). Writing about bugs and tricks.