Copy link to clipboard
Copied
With help of some great information, Prometheus-like, we have been given the access to the syntax which makes pageItem.applyEffect(); work
Re: PageItem.applyEffect(LiveEffectXML)
This is great to start out with when the components which make up the 'Dict data="' string are in a straight-forward syntax where there is a data type, a name key and a value to form each component. They just need to be strung together like so:
I am able to almost accomplish my goal of applying an Inner Glow, but I can't figure out the syntax needed to supply the glow color to go along with it. It always defaults to white.
Here is the code so far which applies a glow only with white default:
#target illustrator
function test(){
var effectStr =
'<LiveEffect name="Adobe Inner Glow">' +
'<Dict data="' +
'I gtyp 0 ' +
'R blur 14.4 ' +
'I blnd 3 ' +
'R opac 1 ' +
'" ' +
'/>' +
'</LiveEffect>';
var doc = app.activeDocument;
var s = doc.selection[0];
s.applyEffect(effectStr);
};
test();
Here is the string inside the .AI file I saved without compression and opened it as text:
/BasicFilter :
(Adobe Inner Glow) 1 0 /Filter ,
1 /Visible ,
(Adobe Illustrator.app) /PluginFileName ,
(Inner Glow) /Title ,
/Dictionary : /NotRecorded ,
0 /Int (gtyp) ,
/FillStyle : 0 O
0.03 0 0.29 0 k
0 1 0 0 0 Xy
0 J 0 j 1 w 10 M []0 d
0 XR
0 1 Xd
/Def ;
(gclr) ,
14.4 /Real (blur) ,
1 /Real (opac) ,
3 /Int (blnd) ,
; /Dict ;
The color information is located here:
/FillStyle : 0 O
0.03 0 0.29 0 k
0 1 0 0 0 Xy
0 J 0 j 1 w 10 M []0 d
0 XR
0 1 Xd
/Def ;
(gclr) ,
While the rest of the 4 properties are working in my attempt above, I can't get the right syntax for putting in that color.
By the way, when applying this effect with experimentation strings added, the result could be an error-less application of the effect with default white or a MRAP, depending on whether you crossed some line of what the acceptable syntax is. I have tried adding new attributes and tags, and it still worked in the default way. Then I tried to add a nested tag inside the Dict tag, and got a MRAP. Whoever is able to solve this puzzle shall be rewarded with several emojis.
sorry I meant the different blending modes didn't seem to make a noticeable difference in my testings.
this works for me
xmlstring14 = '<LiveEffect name="Adobe Inner Glow"><Dict data="R opac 0.75 R blur 9 I blnd 10 I gtyp 0 "><Entry name="gclr" valueType="F"><Fill color="5 0 1 0.818 0"/></Entry></Dict></LiveEffect>';
Copy link to clipboard
Copied
you're using Overlay Blending Mode, I couldn't get that to work even manually. Use Normal or Difference for proof of concept, those work fine.
Copy link to clipboard
Copied
The blending mode seems to work (at least to the point of setting the correct item in the dropdown), but it is the color which eludes me.
Copy link to clipboard
Copied
sorry I meant the different blending modes didn't seem to make a noticeable difference in my testings.
this works for me
xmlstring14 = '<LiveEffect name="Adobe Inner Glow"><Dict data="R opac 0.75 R blur 9 I blnd 10 I gtyp 0 "><Entry name="gclr" valueType="F"><Fill color="5 0 1 0.818 0"/></Entry></Dict></LiveEffect>';
Copy link to clipboard
Copied
Oh cool, so the "Def" thing becomes an <Entry name=""> and the FillStyle becomes <Fill color=""> ?
So then, in your color="" string, there's 6 numbers - are you able to elaborate a little more on how this string transfers to this format:
0 O
0.03 0 0.29 0 k
0 1 0 0 0 Xy
0 J 0 j 1 w 10 M []0 d
0 XR
0 1 Xd
I am going to assume this:
color="0 O 0.03 0 0.29 0 k 0 1 0 0 0 Xy 0 J 0 j 1 w 10 M []0 d 0 XR 0 1 Xd"
Is that right? I'll test soon too.
-----------------------------------------------
Yea that long number string of mine did not work. But it looks like all of those letters and numbers are not really necessary. Now I wonder which of those correspond with your 6 numbers and as a bonus, what the other ones do.
Copy link to clipboard
Copied
for color info only this is relevant, those are your cmyk values in percentages of 1
0.03 0 0.29 0 k
I have no idea about the other numbers.
Copy link to clipboard
Copied
So for yours, what do the other 2 numbers mean?
<Fill color="5 0 1 0.818 0"/>
Copy link to clipboard
Copied
it's only 5 numbers, not sure what the first number means, the next 4 are your cmyk values.
this should yield the cmyk values exactly as you'll see them in the UI (c:25, m:100, y:50, k:0)
<Fill color="1 0.25 1 0.5 0"/>
Copy link to clipboard
Copied
Okay, I don't know the oracles you speak with to get this information, but thank you once again for the great revelation!
By the way, for me Overlay works just fine. It may be that you are just not visually noticing the effect? The shape I used the effect on, I made to have the basic black-to-white gradient and the blending mode's appearance was evident.
Copy link to clipboard
Copied
hahaha no oracles, just looking at the fxg file.
where are my emojis? several of them
Copy link to clipboard
Copied
What? How could I forget!
So, it appears the FXG file has better description of the live effect XML string because the one from a non-compressed .ai file is more cryptic when it comes to the nested elements.
Copy link to clipboard
Copied
Is there any way to get FXG out in CC2018? It always saves me a .ai file even though I used FXGSaveOptions...
Copy link to clipboard
Copied
Update: these free functions make applying Live Effects easier: AI Live Effect Functions.
- Mark
Copy link to clipboard
Copied
This is a very interesting thread (although it looks like I am a little late to the party) and has made me delve a little deeper to try to assign a stoke or fill through the same principle. I have managed to extract the data for the stroke of an object from the uncompressed .ai file (see below). I have tried to follow the thread and feed this into a script but I am not sure how to apply the values from the line '0 J 0 j 1.234 w 4 M []0 d' as this appears to be the join, cap, corner, mitre, stroke width and dashed line information required.
Regarding the colours, I have been playing around with the extra number at the start and it seems like '0' has relevance to greyscale whilst '1' has relevance to CMYK values, but from the extrated data below I appear to have a '0' (in the line '/StrokeStyle : 0 R') on a CMYK colour of 100 Cyan and 100 Yellow (in the line '1 0 1 0 K'), or am I pulling the additional extra number from the wrong place?
/BasicFilter :
(Stroke Style Filter) 0 0 /Filter ,
1 /Visible ,
2 /FillOrStroke ,
/Dictionary : /NotRecorded ,
/StrokeStyle : 0 R
1 0 1 0 K
0 1 0 0 0 Xy
0 J 0 j 1.234 w 4 M []0 d
0 XR
1 0 Xd
/Def ;
(StrokeStyle) ,
; /Dict ;
/Part ,
Copy link to clipboard
Copied
Good question! I also wondered if we could sneak in some stroke or fill effects via the applyEffect method but I haven't been able to get it to work. As far as I know, no-one has yet, but it seems like it might be just a matter of getting the right XML structure.
The extra number at the start of the color specification denotes the color type:
0 = GrayColor, 1 = CMYKColor, 5 = RGBColor
(There's an internal convenience function called 'LE.formatColor' in LE.js in my LE_Functions repo I mentioned above.)
Please let us know if you achieve anything on this!
Copy link to clipboard
Copied
So, if '0' refers to greyscale and my uncompressed .ai file had a stroke with 100 Cyan and 100 Yellow but the line '/StrokeStyle : 0 R' uses a '0', am I getting my colour space number from the wrong place? Surely it should be '1', if so, which line of the code is this coming from?
Copy link to clipboard
Copied
what's the filter name you're trying to apply?
Copy link to clipboard
Copied
I am just looking at adding a stroke at the moment and the data I have extracted gives the following info '(Stroke Style Filter) 0 0 /Filter ,', so I presume the filter name is 'Stroke Style Filter', see below for what I have in my script so far, but this is not working:
<LiveEffect name="Stroke Style Filter"><Stroke color="1 1 0 1 0"/><StrokeStyle = 0 J 0 j 1 w 4 M []0 d></Entry></Dict></LiveEffect>'
Copy link to clipboard
Copied
I meant I wanted to know the name of the effect in the Effects Menu you were trying to apply to try to get the right data.
But I just realized you're not doing that. You're trying to do something else.
Copy link to clipboard
Copied
Sorry, yes, I am trying to apply a stroke via the 'Appearance' panel.
 
Copy link to clipboard
Copied
yeah I'm not sure if we can hack the ApplyEffect() described in this post to make it work with Appearance colors/strokes
why don't you start a new post describing what you're trying to accomplish with the Appearance panel in more detail?
Copy link to clipboard
Copied
Will do, thanks.
Copy link to clipboard
Copied
It's a tantalizing idea, and by no means crazy. Good luck!