Need help for rewriting script FreehandToAI.jsx that it works also with subfolders...


hello,

 

i have convert lot of freehand files illustrator files. therefore find script. see below. works fine not subfolders.

can rewrite it??? have no idea of scripting. nice! :-)

 

 

 

 

**********************************************************

 

freehandtoai.jsx

 

 

description

 

 

open freehand files specified in user selected folder , save them ai files

 

 

**********************************************************/

 

 

// main code [execution of script begins here]

 

 

try

{

          // folder read files from

          var inputfolderpath = null;

    var totalfilesconverted = 0;

          inputfolderpath = folder.selectdialog( 'select freehand files location.', '~' );

   

    if (inputfolderpath != null) {

        // parse folder name folder name prefix

        var inputfolderstr = inputfolderpath.fullname;

        //var selectedfoldername = inputfolderpath.displayname;

        var selectedfoldername = inputfolderpath.name;

        while (selectedfoldername.indexof ("%20") > 0)

        {

            selectedfoldername = selectedfoldername.replace ("%20", " ")

         }  

        var inputfolderarray = inputfolderstr.split (selectedfoldername);

        var inputfolderprefix = inputfolderarray[0];

 

 

        // folder save files into

        var destfolder = null;

        destfolder = folder.selectdialog( 'select output ai location.', '~' );

 

 

        if (destfolder != null) {

            app.userinteractionlevel = userinteractionlevel.dontdisplayalerts;

 

 

            // set freehand options

            var freehandoptions = app.preferences.freehandfileoptions;

            freehandoptions.converttexttooutlines = false;

            freehandoptions.importsinglepage = false;

   

            // recursively read freehand files , convert ai

            convertfhtoai(inputfolderpath);

        }

    }

        alert( totalfilesconverted + ' freehand files converted ai' );

}

catch (err)

{

   rs = ("error: " + (err.number & 0xffff) + ", " + err.description);

   alert(rs);

}

 

 

 

 

/**  function recursively read freehand files input folder , save them ai file in destination folder

          @param inputfolderpath input folder path freehand files read

*/

function convertfhtoai(inputfolderpath)

{

 

          var testfiles = new array();

          var index = 0;

   

          // create output folder path created

          pathtoappend = inputfolderpath.fullname.split(inputfolderprefix);

          var savefolder = destfolder + "/" + pathtoappend[1];

 

 

          // create folder

   

          fldr = new folder(savefolder);

          fldr.create();

   

    if (!(fldr.exists))

    {

        throw new error('access denied');

    }   

   

          // list of files/folders in current working folder

          testfiles = inputfolderpath.getfiles("*.fh*");

 

 

          for (index = 0; index < testfiles.length;index++)

          {

        // check if current item file or folder

        if (testfiles[index] instanceof folder)

        {

            convertfhtoai(testfiles[index]);

        }

        else

        {

            // selected item file

            filename = testfiles[index].displayname;

           

            var fileextensionarray = filename.split(".", 2);

            var fileextension = fileextensionarray[1].touppercase();

           

            // check file freehand file

            if (fileextension == "fh11" || fileextension == "fh10" || fileextension == "fh9" || fileextension == "fh8" || fileextension == "fh7" )

            {

                // open freehand file

                var docref =app.open(testfiles[index]);

                obj_doc=app.activedocument;

                   

                // create output file path

                var fileprename = testfiles[index].displayname.split(".",1);              

                sdocumentpath = savefolder +"/"+ fileprename + "_unbearbeitet" + ".ai" ;

 

                // save file ai

                saveasai(sdocumentpath);

               

                // increment counter of total number of files converted

                totalfilesconverted = totalfilesconverted + 1;

                   

                // close document

                app.activedocument.close( saveoptions.donotsavechanges );

            }

        }  

    }  

}

 

 

/** save current opened document ai file

          @param sdocumentpath name of output path file needs saved

*/

function saveasai(sdocumentpath)

{

    thefile = new file(sdocumentpath);

                   

    // create ai save options

    var aioptions  = new illustratorsaveoptions();

   

    // changes save options please refer illustratorsaveoptions in javascript reference available options

 

 

          // example, save file ai cs4 file use

          aioptions.compatibility = compatibility.illustrator14;

   

    aioptions.compressed = true;

    aioptions.embediccprofile = false;

    aioptions.embedlinkedfiles = false;

    aioptions.flattenoutput = outputflattening.preserveappearance;

    aioptions.fontsubsetthreshold = 100;

    aioptions.pdfcompatible = true;

   

     

    // uncomment code below if want save each artboard seperate file

/*   obj_doc=app.activedocument;

    var artboardlength = obj_doc.artboards.length;

  if (artboardlength > 1)

    {

        aioptions.savemultipleartboards = true;

        aioptions.artboardrange = "";

    }  

    */

    // save ai file   

    obj_doc.saveas (thefile, aioptions);

}

when run script new .ai file ends in cmyk color mode.  how can script changed have file saved in rgb color mode?



More discussions in Illustrator


adobe

Comments

Popular posts from this blog

How to change text Component easybook reloaded *newbee* - Joomla! Forum - community, help and support

After Effect warning: A problem occurred when processing OpenGL commands

Preconditions Failed. - Joomla! Forum - community, help and support