SVG batch: where to add resize artboard code ?
i wish include part of code artboard resized , convert .eps , .ai svg files.
not sure should go ?
any clues, let me know
thanks guys !!
------------------------------
// artboard resize code
for (i=0; < filestoprocess.length; i++) {
app.open(filestoprocess[i]);
var doc = app.activedocument;
var myborder = 10; // set width of border desired, in points
var myvisiblebounds = doc.visiblebounds; // rect, array;
myvisiblebounds[0] -= myborder; // left coordinate (use negative values add artboard)
myvisiblebounds[1] += myborder; // top coordinate
myvisiblebounds[2] += myborder; // right coordinate
myvisiblebounds[3] -= myborder; // bottom coordinate (use negative values add artboard)
doc.artboards[0].artboardrect = myvisiblebounds;
-----------------------
where put in svg batch code ??
----------------------
// main code [execution of script begins here]
var destfolder, sourcefolder, files, filetype, sourcedoc, targetfile, svgsaveopts;
// select source folder.
sourcefolder = folder.selectdialog( 'select folder illustrator files want convert svg', '~' );
// if valid folder selected
if ( sourcefolder != null )
{
files = new array();
filestoprocess = sourcefolder.getfiles("*.ai","*.eps");
// files matching pattern
files = sourcefolder.getfiles( filetype );
if ( files.length > 0 )
{
// destination save files
destfolder = folder.selectdialog( 'select folder want save converted svg files.', '~' );
( = 0; < files.length; i++ )
{
sourcedoc = app.open(files[i]); // returns document object
// call function getnewname name , file save svg
targetfile = getnewname();
// call function getsvgoptions svgsaveoptions files
svgsaveopts = getsvgoptions( );
// save svg
sourcedoc.exportfile(targetfile, exporttype.svg, svgsaveopts );
sourcedoc.close();
}
alert( 'files saved svg in ' + destfolder );
}
else
{
alert( 'no matching files found' );
}
}
/*********************************************************
getnewname: function new file name. primary
name same source file.
**********************************************************/
function getnewname()
{
var ext, docname, newname, saveinfile, docname;
docname = sourcedoc.name;
ext = '.svg'; // new extension svg file
newname = "";
( var = 0 ; docname[i] != "." ; i++ )
{
newname += docname[i];
}
newname += ext; // full svg name of file
// create file object save svg
saveinfile = new file( destfolder + '/' + newname );
return saveinfile;
}
function getsvgoptions()
{
var svgsaveopts = new exportoptionssvg();
l
svgsaveopts.embedrasterimages = true;
return svgsaveopts;
}
if put between lines:
sourcedoc = app.open(files[i]); // returns document object /* here */ // call function getnewname name , file save svg targetfile = getnewname();
that should work. don't forget update resize code use new ref document object 'sourcedoc' instead of 'doc'.
good luck!
More discussions in Illustrator Scripting
adobe
Comments
Post a Comment