Copy link to clipboard
Copied
Hello everyone,
I have a problem with the new illustrator version when using a script to convert AI files to SVG files.
Suddenly the measurement in the SVG files is missing, there is no "width" or "heigt" parameter.
Here is the script I am using:
/**********************************************************
ADOBE SYSTEMS INCORPORATED
Copyright 2005-2010 Adobe Systems Incorporated
All Rights Reserved
NOTICE: Adobe permits you to use, modify, and
distribute this file in accordance with the terms
of the Adobe license agreement accompanying it.
If you have received this file from a source
other than Adobe, then your use, modification,
or distribution of it requires the prior
written permission of Adobe.
*********************************************************/
/**********************************************************
Save as SVGs.jsx
DESCRIPTION
This sample gets files specified by the user from the
selected folder and batch processes them and saves them
as SVGs in the user desired destination with the same
file name.
Based on Adobe's "Save as PDFs" sample script, intended for Illustrator CS6
**********************************************************/
// Main Code [Execution of script begins here]
// uncomment to suppress Illustrator warning dialogs
// app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
var destFolder, sourceFolder, files, fileType, sourceDoc, targetFile, svgSaveOpts;
// Select the source folder.
sourceFolder = Folder.selectDialog( 'Quell-Verzeichnis mit AI-Dateien auswählen', '~' );
// If a valid folder is selected
if ( sourceFolder != null )
{
files = new Array();
fileType = prompt( 'Select type of Illustrator files to you want to process. Eg: *.ai', ' ' );
// Get all files matching the pattern
files = sourceFolder.getFiles( fileType );
if ( files.length > 0 )
{
// Get the destination to save the files
destFolder = Folder.selectDialog( 'Ziel-Verzeichnis für die SVGs auswählen.', '~' );
for ( i = 0; i < files.length; i++ )
{
sourceDoc = app.open(files[i]); // returns the document object
// Call function getNewName to get the name and file to save the SVG
targetFile = getNewName();
// Call function getSVGOptions get the SVGSaveOptions for the files
svgSaveOpts = getSVGOptions( );
// Save as svg
sourceDoc.exportFile(targetFile, ExportType.SVG, svgSaveOpts );
sourceDoc.close();
}
alert( 'Files are saved as SVG in ' + destFolder );
}
else
{
alert( 'No matching files found' );
}
}
/*********************************************************
getNewName: Function to get the new file name. The primary
name is the same as the source file.
**********************************************************/
function getNewName()
{
var ext, docName, newName, saveInFile, docName;
var docName = sourceDoc.name;
var ext = '.svg'; // new extension for svg file
var newName = docName.replace(/\.[a-z]+$/, ext);
// Create a file object to save the svg
saveInFile = new File( destFolder + '/' + newName );
return saveInFile;
}
function getSVGOptions()
{
var svgSaveOpts = new ExportOptionsSVG();
svgSaveOpts.DTD = SVGDTDVersion.SVG1_1;
svgSaveOpts.embedRasterImages = false;
svgSaveOpts.cssProperties = SVGCSSPropertyLocation.STYLEATTRIBUTES;
svgSaveOpts.coordinatePrecision = 3;
svgSaveOpts.fontType = SVGFontType.SVGFONT;
svgSaveOpts.documentEncoding = SVGDocumentEncoding.UTF8;
svgSaveOpts.fontSubsetting = SVGFontSubsetting.None;
svgSaveOpts.response = false;
svgSaveOpts.sVGTextOnPath = true;
svgSaveOpts.slices = false;
svgSaveOpts.preserveEditability = false;
svgSaveOpts.sVGAutoKerning = false;
return svgSaveOpts; }
Here is an example of a SVG file that was correct converted:
And here now a converted SVG with the new illustrator version, no width or height anymore.
Do anyone have a clue what could be the reason? Must the script be updated?
Thank you very much!
Copy link to clipboard
Copied
Hmm, the .response property does not appear to exist.
According to this: https://stackoverflow.com/questions/24789225/exportoptionssvg-class-in-illustrator-extendscript-has-...
The short answer - there is no way to programatically disable responsiveness in Illustrator ExtendScript unfortunately. My main reason for needing it disabled is that responsiveness prevents the width and height attributes from being included in the tag, and I needed those for my script.
However, as a hack I used the viewBox dimensions which are still retained in the element as widths and heights. After talking to someone on the design team, they said this is a fine thing to do as the viewBox is representative of what the widths and heights would be.
So maybe you could work around this by opening the svg after export and using string-replacement to add the width and height right next to the viewBox.