Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
1

exportFile() - export selection option via script?

Guest
Aug 09, 2010 Aug 09, 2010

Hello,

From InDesign, I can select a group/textFrame/pictureFrame, and then click File -> Export. From this dialog, after I select my "save location," I can then choose to "Export Selection" by selecting the "Selection" radio button.

I'm wondering if this is possible to do with a script? The reason I ask is because I need to export single picture frames (actually, grouped frames, there will be text frames grouped with picture frames). In the SDK I see exportFile() options where you can select if you wish to export as PDF, IDML, JPG, etc. But nothing on "exporting selection". Does anyone know if this is possible, and if so, how it is done?

I know there is a bool you can set to "true" to display the dialog, but this all needs to be automated. Anyone have any thoughts on this?

Thanks in advance!

-Lloyd

TOPICS
Scripting
22.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advisor , Aug 09, 2010 Aug 09, 2010

Hey!

Maybe you can try this code:

var myFile = File('/c/myTest.jpg');

if(app.selection.length > 1){
    var myObj = app.activeWindow.activePage.groups.add(app.selection);
    myObj.exportFile(ExportFormat.JPG, myFile, false);
    myObj.ungroup();
}else{
    app.selection[0].exportFile(ExportFormat.JPG, myFile, false);
}

I tested it just with JPG.

--

tomaxxi

http://indisnip.wordpress.com/

Translate
Explorer ,
Apr 25, 2018 Apr 25, 2018

Hello laubender,

The file which i am trying to export doesnot contain any forward slash (/).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 26, 2018 Apr 26, 2018

Hi ananth,

are you able to export all the files using InDesign's menu commands?

Regards,
Uwe

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 26, 2018 Apr 26, 2018

Hello Laubender,

i am able to use all the menu commands and also able to convert to export to png using the menu commpand but not by scripting.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 26, 2018 Apr 26, 2018

Hm…
Then we need the sample document and your code to debug the problem.

Could also be a bug with InDesign scripting we have to find a workaround.

Can you upload a sample? A packaged document and your script to a service like Dropbox and post the link?

Regards,
Uwe

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 26, 2018 Apr 26, 2018

Is that fine with screenshot?

I will send you a screenshot of code where export takes place. i don't know using dropbox.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 26, 2018 Apr 26, 2018

Screenshots are not helpful here, I think.

With Dropbox there is a free account and Dropbox is easy to use:

Dropbox

Just takes a few minutes to set up. If you uploaded a file—preferably a zip-file in your case—you could context-click the file and use the menu command to copy the download link to the clipboard.

Regards,
Uwe

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 26, 2018 Apr 26, 2018
LATEST

So sorry and Here is my code Laubender. As my company blocked dropbox site i am unable to login to it.

function(designNumber, exportPath){ 

        //alert('designNumber:'+val);

      

        var num_exported = 0;     

        var options = getThumbnailOptions();

var failed_artboards=[];

        var exportArtboards=[];              

      

        var opts = new ExportOptionsPNG24();

        opts.artBoardClipping = true;

        opts.matte = false;

        opts.horizontalScale = opts.verticalScale = 100;

        opts.transparency = false;

      

        app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;              

                      

        if(app.documents.length==0)

            return JSON.stringify(exportArtboards);

      

        var docRef = app.activeDocument;

      

for (var i = 0; i < docRef.artboards.length; i++ ) {

var artboard = docRef.artboards;

var artboardName = artboard.name.replace(/\s+/g, '-');

            //alert(artboardName);

docRef.artboards.setActiveArtboardIndex(i);

var d = new Date();

            var t = d.getTime();

            if(designNumber)

            //n = designNumber.replace(/\s+/g, '-')+n;

    n = designNumber.replace(/\s+/g, '-');

    //fName is appended in file name

    fName = (app.activeDocument.fullName.fsName.split(/(\\|\/)/g).pop());

            //alert(app.activeDocument.fullName.fsName);

    fName=fName.substring(0, fName.indexOf('.'));

            fName = fName.replace(/ /g,"_");

            // prefix is combibation of exp and design number and filename

            var prefix="exp_"+n+'_'+fName+'_';

            var suffix=".png";

            var base_path= app.path + '/CEP/extensions/com.cgsinc.illustrator.plm.artboards/ai_exports/';

            base_path = exportPath;

var exportArtboard={};

          

if (true){

try{

                    var exportFileName = prefix + artboardName + suffix;

    var base_filename = base_path + exportFileName;

                    //TODO :  if file exist, reame base_filename

                    expFile = File(base_filename);

    expFile = new leader(base_filename);

                    docRef.exportFile(expFile, ExportType.PNG24, opts);

    exportArtboard.artboardName=artboardName;

    exportArtboard.con_exportFileName = prefix + artboardName +'_con'+ suffix;

                    exportArtboard.artboardIndex=i;

                    exportArtboard.selected = false;

                    exportArtboard.designNumber= designNumber;

                    exportArtboard.fkey= 0;

                    exportArtboard.pkey= 0;

                    exportArtboard.imageByte= null;

                    exportArtboard.imageCategory= "";

                    exportArtboard.imageType= "";

                    exportArtboard.imageDescription= "";

                    exportArtboard.imageNote= "";

    exportArtboard.fileName= unescape(base_filename.replace('/c/','/'))+ "?stamp=" +t;

    exportArtboard.exportFileName=exportFileName;

                    var a=app.activeDocument.fullName.fsName;

                    exportArtboard.masterFileName=app.activeDocument.fullName.fsName;

                    exportArtboards.push(exportArtboard);

}catch(e){

failed_artboards.push(e);

                    alert('error:'+e);

}

}

}

even though there is a catch its not raising an exception.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines