Javascript enumerated objects
Copy link to clipboard
Copied
Hi everyone, this is a question which has to do with the enumerated objects in the javascript model such as "ElementPlacement.INSIDE" or, "Justification.CENTER".
Here is the thing, we have plenty of these objects available to us, and alerting the value of a textFrame.paragraphs[0].paragraphAttributes.justification will yield something like "Justification.CENTER".
In the OMV, the Justification object contains plenty of enumerated values such as CENTER:int, Value:2 and FULLJUSTIFY:int, Value 6.
Now, when I write something like this,
var Colors = {
BLUE: 1,
GREEN: 2,
ORANGE: 3
};
var item = {};
item.color = Colors.ORANGE;
alert(item.color);
Of course, my alert does not say "Colors.ORANGE", it says "3". But, when you alert a justification of a paragraph, it will not say a number, but an object.
Can anyone explain to me what their special objects have that mine don't?
Explore related tutorials & articles
Copy link to clipboard
Copied
Oh thank goodness my ESTK still works on my CS5, with the breakpoints and data-browser.
From this data-browser exploration, I can tell that the Justification object contains a bunch of objects itself, but still not sure about the whole thing, either - like how you can alert the integer value from alert(Justification.CENTER).
Copy link to clipboard
Copied
it may not be possible to get the enumerated values out of a native enumeration object, what are you trying to achieve?
Copy link to clipboard
Copied
Just some semantic help when writing code, and it seems to be a practice in ES which everyone must be familiar with, to do things such as set justification or element placement, so in my custom scripts I'd like to set this behavior the same way.
It isn't really needed, but also I wanted to get clarification on these objects because the OMV seems to show what I wrote with my Colors object above, but it does not, so I must be misunderstanding it. Then, when looking at the data browser, it's an answer which just asks more questions.
Copy link to clipboard
Copied
I don't know why Enums are set up one way or another in a given DOM, for instance in vbs, Justification.CENTER is not allowed, we must use the index value 2. (also what we see in the OMV may not correct)
in javascript whenever I need to use the enum values dynamically, I build my own array to set up my values numerically.
var refpoint = [Transformation.DOCUMENTORIGIN, Transformation.TOPLEFT, Transformation.TOP, Transformation.TOPRIGHT, Transformation.LEFT, Transformation.CENTER, Transformation.RIGHT, Transformation.BOTTOMLEFT, Transformation.BOTTOM, Transformation.BOTTOMRIGHT];
Copy link to clipboard
Copied
check this thread for a possible solution to finding out Enum values and indexes.
Copy link to clipboard
Copied
Thank you CarlosCanto‌ .
Copy link to clipboard
Copied
Not sure if this helps but I found this while looking for something else,
C:\Program Files\Common Files\Adobe\Scripting Dictionaries CC\illustrator 2015\omv.xml
excerpt about justification
<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
Ahh, it is in the common files! I was wondering where that xml file lived. Thanks Qwertyfly...‌ ! Well, that's how the OMV gets its definitions.
For my purposes, next time I have a chance to use my own enumerated objects, I will see about using Carlos' approach.

