nice idea! I had some very strange results trying to use it. At first I was getting errors like I expected, but then after tweaking some of the options (filenames, ItemToExport, etc), I was able to get it to work for awhile. But after a couple rounds of tests, it inexplicably stopped exporting anything again. Sometimes erroring, sometimes not. Very strange. Anyway, here's the code that worked for me at one point:
opendoc = app.documents.addDocumentNoUI();
var tempfile = File("~/Desktop/test/test.ai")
opendoc.saveNoUI(tempfile);
var options = new ExportForScreensOptionsWebOptimizedSVG();
options.coordinatePrecision = 3;
options.cssProperties = SVGCSSPropertyLocation.ENTITIES;
options.fontType = SVGFontType.OUTLINEFONT;
options.rasterImageLocation = RasterImageLocation.EMBED;
options.svgId = SVGIdType.SVGIDREGULAR;
options.svgMinify = false;
options.svgResponsive = false;
var itemToExport = new ExportForScreensItemToExport();
itemToExport.artboards = '1';
itemToExport.document = false;
var tempfile2 = File("~/Desktop/test2/test2.svg");
opendoc.exportForScreens(tempfile2, ExportForScreensType.SE_SVG,options,itemToExport);
FYI, I've found that if I run .saveNoUI() before .exportForScreens() it will throw an error on .exportForScreens(), but if I don't run .saveNoUI() first, it will fail silently. Which doesn't make a lot of sense either.
Anyway, would you be able to try this code and tell me what results you get? I'm very confused by the results I've seen...
Hi @sam272, I tried your script and here's some things I found (after just a few simple tests—not extensive!). Each test performed after a restart of Illustrator app.
1. The export seems to work okay when there is a normal UI document open.
2. If no normal UI docs are open, the script throws Error: an Illustrator error occurred: 129 ('Å')
3. When I comment out "opendoc.saveNoUI(tempfile);" then export works even if there are no normal documents open.
4. When I wrap the code in this:
var dummyDoc = app.documents.addDocumentWithDialogOption("Art & Illustration");
/* ... the script ... */
dummyDoc.close(SaveOptions.DONOTSAVECHANGES);
to test if it is possible to make it work by having a document open, I got either
(a) an error on dummyDoc.close (disturbing!) but the SVG export worked, or
(b) Illustrator crashed, or
(c) it worked... one time... I think.
Another thing I noticed: the "NoUI" methods are "private". These methods don't appear in the object model viewer for a Document object. Have a look in the debugger panel in VSCode when you have a document in a variable to inspect. Nothing.
Anyway, I got to be honest here—you are braver than me if you plan to use this NoUI stuff. 🙂 Great to explore though.
- Mark