Skip to main content
Known Participant
April 18, 2013
Question

Is it possible to apply a Transform effect from Javascript ?

  • April 18, 2013
  • 1 reply
  • 1477 views

I was wondering if it's possible to do what Effect > Distort & Transform > Transform does from JS.

I had a look at the documentation and found nothing in that direction.

The closest thing I found was PageItem.applyEffect(effectXML) looking at the Object Model Viewer in Extend Script Toolkit,

but couldn't find documentation for it and I suspect it might have something to do with SVG filters perhaps ?

In conclusion:

  1. Is it possible to apply a Transform effect from JS (and if so, how )?
  2. How can applyEffect be used ?

Thanks,

George

This topic has been closed for replies.

1 reply

CarlosCanto
Community Expert
Community Expert
April 19, 2013

up to CS5 you can't, the closest thing is to apply the effect (manually), save it as a Graphic Style (manually), then your script could access this saved Graphic Style and apply it to an object.

orgicusAuthor
Known Participant
April 21, 2013
up to CS5 you can't

So you mean it's possible from CS5 upwards ? If so, how ?

Also, in the meantime I had a look at the graphicStyles reference and thought that I can ease the manual styles creation a bit.

For example if a packed extension needs this functionality, a graphic style preset can be packaged (as far as I can see it's just

an ai document) then opened from JS so it can be applied.

I tried this:

var file = new File("/Applications/Adobe/Adobe\ Illustrator\ CS6/Presets.localized/en_US/Graphic\ Styles/Custom.ai");

var options = new OpenOptions();

options.openAs(LibraryType.ILLUSTRATORARTWORK);

//var stylesDoc = app.open (f, DocumentColorSpace.RGB, OpenOptions.openAs(LibraryType.GRAPHICSTYLES));

but I get an error:

LiveObject() is not a function

which isn't very descriptive to me. How can I open an .ai graphic style from js correctly ?

Thank Carlos!

CarlosCanto
Community Expert
Community Expert
April 21, 2013

you can open an ai file with the graphic styles in it, but it will behave exactly as if you open it manually in the user interface, the graphics styles will load in the Graphic Styles Libraries Palette, but you won't have access to them via scripting, you'll have to click on them (manually) to add them to the active document's Graphic Styles Palette...then you can access them via scripting.

var fileRef = File("/Applications/Adobe/Adobe\ Illustrator\ CS6/Presets.localized/en_US/Graphic\ Styles/Custom.ai");

if (fileRef != null) {

var optRef = new OpenOptions();

optRef.updateLegacyText = true;

optRef.openAs = LibraryType.GRAPHICSTYLES;

var docRef = open(fileRef, DocumentColorSpace.RGB, optRef);

}