Copy link to clipboard
Copied
Is there a way to dynamically retrieve all the possible variants of a globally defined object, such as Justification, from a script?
In other words, I want to enumerate all the values under Justification—such as Justification.LEFT, Justification.CENTER, Justification.RIGHT, etc.—into an array dynamically, instead of hardcoding all the variations myself.
I tried code like the example below, but it seems that each value does not actually exist in Illustrator until it is explicitly referenced in the source code.
var justificationArray = [] ;
for(var propName in Justification) {
justificationArray.push(propName) ;
}
alert(justificationArray) ;
Use case:
Addressing an issue where specified text attributes are ignored when their values match the default values of the character/paragraph styles applied to that text. For types of Object, plan to dynamically retrieve values, convert them to an Array, and generate different values by shifting the index.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
how about getting them right out of the omv.xml file?
<classdef name="Justification" enumeration="true">
<shortdesc>The paragraph alignment.</shortdesc>
<elements type="class">
<property name="LEFT" rwaccess="readonly">
<datatype>
<type>int</type>
<value>0</value>
</datatype>
</property>
<property name="RIGHT" rwaccess="readonly">
<datatype>
<type>int</type>
<value>1</value>
</datatype>
</property>
<property name="CENTER" rwaccess="readonly">
<datatype>
<type>int</type>
<value>2</value>
</datatype>
</property>
<property name="FULLJUSTIFYLASTLINELEFT" rwaccess="readonly">
<datatype>
<type>int</type>
<value>3</value>
</datatype>
</property>
<property name="FULLJUSTIFYLASTLINERIGHT" rwaccess="readonly">
<datatype>
<type>int</type>
<value>4</value>
</datatype>
</property>
<property name="FULLJUSTIFYLASTLINECENTER" rwaccess="readonly">
<datatype>
<type>int</type>
<value>5</value>
</datatype>
</property>
<property name="FULLJUSTIFY" rwaccess="readonly">
<datatype>
<type>int</type>
<value>6</value>
</datatype>
</property>
</elements>
</classdef>
Copy link to clipboard
Copied
Thank you for your response. Scripts that can be written straightforwardly, I can complete without asking, so the questions I ask tend to be the more difficult ones.
ExtendScript isn't particularly fast, and I have doubts about whether omv.xml is being properly maintained, so I'd prefer to avoid parsing it if possible. Even if I were to parse it, my impression is that it would be sufficient to run it once during development and then hard-code the necessary parts into the script.
Hope to hear other ideas as well.
Copy link to clipboard
Copied
I agree with you, omv.xml is not up to date but it can still be useful.
so do you need to get the Enums just once to built a list of them? to avoid typing them manually?
if so, I uploaded the omv to NotebookLM and asked it to get the Justification enum for me and it did a pretty good job
this is what it returned
[ Justification.LEFT, Justification.RIGHT, Justification.CENTER, Justification.FULLJUSTIFYLASTLINELEFT, Justification.FULLJUSTIFYLASTLINERIGHT, Justification.FULLJUSTIFYLASTLINECENTER, Justification.FULLJUSTIFY ]
Copy link to clipboard
Copied
That's very modern and nice.
Copy link to clipboard
Copied
Hi @sttk3 and @CarlosCanto, unfortunately I am completely helpless on this question.
I have long noticed that Illustrator's enums often seem like quite broken objects, not supporting even normal Object methods. For example we would do:
Justification.hasOwnProperty('LEFT')
but this fails with error Invalid enumeration value. Not because "LEFT" isn't a property, but because "hasOwnProperty" isn't a method!
Another weirdness—and sttk3 mentioned this—is that in the debugger Justification shows literally nothing except a constructor. No properties or methods. Then I type, in the console:
Justification.LEFT
and then I look at Justification again... what? now it has a single property: LEFT. It seems like the Justification object initializes it's (legal) properties only when they are accessed for the first time?
Anyway none of that is practical. But it doesn't answer the question. I have always avoided these issues by simply coding my own enum, using the correct values, and I access that. I'm sure you both have done the same. Sorry I couldn't help.
- Mark
Copy link to clipboard
Copied
Thank you for your reply. Yes, I see your insight matches mine, and it's clear this is probably not a misunderstanding.
For now, it seems we'll need some kind of dictionary.
Copy link to clipboard
Copied
Regarding this issue, I decided not to use it in the actual use case. Because I realized that it is sufficient for just one value pair to exist, without needing to retrieve all values.
Thank you to everyone who put thought into this issue. Please refer to the link for the resulting code.
However, the issue itself is interesting enough that it will be left open in the hopes that someone will solve it.
Copy link to clipboard
Copied
indeed, the subject was interesting enough to keep me digging.
It turns out it could be done using vbscript, if you're on a mac try to see if you can addapt the code to apple script
' GET JUSTIFICATION ENUMERATION MEMBERS VIA VBS/JAVASCRIPT
' carlos canto - 9/12/25
' METHOD
' apply justification to text frames via vbs since vbs accepts enum index numbers
' inconrrect or non-existing enum indexes will raise errors that can be ignored
' apply 20 or more to try to cover all members, then remove all error text frames
' then have vbs execute a Javascript script to read the remaining text frames justification properties
' embellish and return the enums as string
' apply the returned javascript string to a text frame as proof of concept to further do something with it
' Create Illustrator application object
Set app = CreateObject("Illustrator.Application.29")
On Error Resume Next
' Add a new document
Set doc = app.documents.Add
app.DoJavaScript("alert(activeDocument.name)") ' just to make sure connection has been established
' Define position and size for the area text frame
Dim left, top, width, height
left = 100
top = doc.height - 100
width = 300
height = 100
' Add area text frame
Set rect = doc.PathItems.Rectangle(top, left, width, height)
Set textFrame = doc.TextFrames.AreaText(rect)
str = "placeholder text"
textFrame.Contents = str
msg = "" ' to hold enums back from javascript
' create new text frames and apply justification one at a time starting with 0
' increase if there are objects with more than 20 members
for i = 0 to 20
set itext = doc.textFrames.Add
itext.contents = str & " " & i & " " & top
itext.left = left
itext.top = top
itext.TextRange.ParagraphAttributes.Justification = i
' out of index enum members will raise errors, skip, clear error and continue
if err.number <> 0 then
itext.contents = err.number & ": " & err.description
'msg = "Error " & err.number & ": " & err.description
'msgbox msg
err.clear
end if
top = top - itext.height
next
' remove error text frames
for a=doc.textFrames.count to 0 step -1
set itext = doc.textFrames(a)
if itext.contents = "-2147220278: Enumerated value expected" then
itext.delete
end if
next
' read enum members via Javascript
msg = app.doJavascript("var idoc = app.activeDocument; var enums = []; var tfs = idoc.textFrames; for (var a=tfs.length-2; a>=0; a--) {var tf = tfs[a]; enums.push(tf.textRange.paragraphAttributes.justification); tf.remove()} ; enums.join('\n');")
textFrame.contents = msg
msgbox msg
WScript.quit
Copy link to clipboard
Copied
@CarlosCanto interesting! I suspect that wouldn't work in AppleScript (which goes to silly lengths to try to use "normal language" rather than numbers and symbols). In any case running AppleScript or VBScript *from* ExtendScript seems to be such a complexity that sttk3's solution is much easier.
Of course we can hope that one day the bug itself will disappear... hahaha.
Copy link to clipboard
Copied
@CarlosCanto interesting! I suspect that wouldn't work in AppleScript (which goes to silly lengths to try to use "normal language" rather than numbers and symbols).
By @m1b
oh bummer, why can't we have nice things?
Copy link to clipboard
Copied
This is interesting. It seems like an approach that could be used to create some kind of dictionary from Illustrator's actual working features. It would be more reliable than omv.xml.
Copy link to clipboard
Copied
@sttk3 yes I noticed that in your code—a more elegant approach!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now