Skip to main content
August 9, 2010
Answered

exportFile() - export selection option via script?

  • August 9, 2010
  • 2 replies
  • 23562 views

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

This topic has been closed for replies.
Correct answer tomaxxi

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/

2 replies

Participant
March 23, 2012

Hi,

Have you tried exporting to PDF?

I tried and it exports the page, not just the selection

Jongware
Community Expert
Community Expert
March 23, 2012

Different export formats behave differently. Take RTF export, for example -- that's a Text-only format. I guess PDF could count as a "page only" format.

I never needed any of them but I do recall there are several solutions to this (such as creating a temporary new document the exact size of your export objects). Search the forum.

Community Expert
March 24, 2012

@Jongware – Yeah. Temporary documents might or might not work well, if one consider baseline grid behaviour, tables that exceed text frames or other gimmicks like drop shadows you cannot catch to keep the bounds of your PDF at a minimum.

To do the  bounds right (pdf art box and pdf trim box against pdf media box) you have to cross script with PhotoShop for rendering the whole page to get the bounds of its pixel contents from there. Or (a new idea from Mark, thank you for that!) use an AppleScript to read out the clipboard. Wow. What an idea! I'll give that a try if on a Mac…

Uwe

tomaxxi
tomaxxiCorrect answer
Inspiring
August 9, 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/

August 9, 2010

Awesome! that's exactly what I needed. Thank you so much!

tomaxxi
Inspiring
August 9, 2010

You are welcome!

--

tomaxxi

http://indisnip.wordpress.com/