Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

[ExtendScript] How to dynamically retrieve all possible values of a globally defined object

Community Expert ,
Sep 08, 2025 Sep 08, 2025

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.

 

TOPICS
Scripting
178
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Sep 08, 2025 Sep 08, 2025

you always ask the hardest questions 😂😂😂

 

@m1b ?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 08, 2025 Sep 08, 2025

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>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 08, 2025 Sep 08, 2025

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 09, 2025 Sep 09, 2025

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 ]

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 09, 2025 Sep 09, 2025

That's very modern and nice.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 09, 2025 Sep 09, 2025

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 valueNot 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 09, 2025 Sep 09, 2025

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 11, 2025 Sep 11, 2025

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 12, 2025 Sep 12, 2025

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

CarlosCanto_0-1757716794303.png

' 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

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 12, 2025 Sep 12, 2025

@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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 12, 2025 Sep 12, 2025
quote

@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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
15 hours ago 15 hours ago
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 12, 2025 Sep 12, 2025

@sttk3 yes I noticed that in your code—a more elegant approach!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines