[javascript] SVG
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
- /**********************************************************
- 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.
- **********************************************************/
- // Main Code [Execution of script begins here]
- // uncomment to suppress Illustrator warning dialogs
- // app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
- var destFolder, sourceFolder, files, fileType, sourceDoc, targetFile, pngExportOpts;
- // Select the source folder.
- sourceFolder = Folder.selectDialog( 'Select the folder with Illustrator files you want to convert to SVG', '~' );
- // 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', ' ' );
- fileType = '*.eps';
- // Get all files matching the pattern
- files = sourceFolder.getFiles( fileType );
- if ( files.length > 0 )
- {
- // Get the destination to save the files
- destFolder = Folder.selectDialog( 'Select the folder where you want to save the converted PNG files.', '~' );
- for (var 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();
- // Create SVG Options Object
- var options = new ExportOptionsSVG();
- // Export as SVG
- sourceDoc.exportFile( targetFile, ExportType.SVG, options );
- sourceDoc.close(SaveOptions.DONOTSAVECHANGES);
- }
- alert( 'Files are saved as UNCOMPRESSED 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;
- docName = sourceDoc.name;
- ext = '.svg'; // new extension for svg file
- newName = "";
- for ( var i = 0 ; docName != "." ; i++ )
- {
- newName += docName;
- }
- newName += ext; // full svg name of the file
- // Create a file object to save the svg
- saveInFile = new File( destFolder + '/' + newName );
- return saveInFile;
- }
Editor
You can edit this paste and save as new:
File Description
- SVG
- Paste Code
- 02 Jun-2023
- 2.86 Kb
You can Share it: