Skip to main content
jeremy0013
Inspiring
November 15, 2015
Answered

Help with Dataset Save Out

  • November 15, 2015
  • 3 replies
  • 648 views

Hey Guys.  Need some help on this script.  Below is what I have so far but need a little fill in for looping through the save process.  The script should create a master dataset then save out each dataset by name until all have been saved.  Any help is always appreciated.

var docRef = activeDocument;


//Create New Set for master file

var newDataSet = docRef.dataSets.add();


//Display first data set

docRef.dataSets[0].display();

//Save dataset to specific file path using the dataSet name

filepath = "file://Users/Me/Desktop/" + dataSet.name + ".pdf";

saveInFile = new File( filepath );

docRef.saveAs( saveInFile);

//Need to display next dataset then loop the save process until all sets have been saved out.

This topic has been closed for replies.
Correct answer Silly-V

Are you starting out with pre-defined datasets already in the document?

Right now, you're adding a new dataset, and (if there had been no datasets previously), displaying it. So if you already have all the datasets in the document, you don't need to add any, just loop through them and display and save each one.

Here's what I typically do:

var currentDataset;

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

  currentDataset = docRef.dataSets;

  currentDataset.display();

  docRef.saveAs(File("file://Users/Me/Desktop/" + currentDataset.name + ".pdf"));

};

3 replies

jeremy0013
Inspiring
November 17, 2015

Thanks V.  This works perfect.  Maybe if you're up for it you could help me with a couple other parts of what I am working on?  I am not super great at javascript and I am having to put snippets together for the project I am writing.  I have it working but am stuck on a few points.  PM me and let me know if you're interested.  Thanks again.

jeremy0013
Inspiring
November 16, 2015

I'm adding a dataset to save the current state.  I do already have pre defined datasets though.  Your code works great but it saves out as AI instead of pdf.  Is there a setting to save out in PDF?

Silly-V
Legend
November 16, 2015

Okay, so you don't actually have to add any new datasets to save the current state, because they are already in there and each dataset is a state that is saved, so your .display() function is enough.

To save as PDF, you've got to put in some PDFSaveOptions like this:

var myOpts = new PDFSaveOptions();

/*

define your options here, if needed

myOpts.colorBars = true;

myOpts.registrationMarks = true;

*/

docRef.saveAs(File("file://Users/Me/Desktop/" + currentDataset.name + ".pdf"), myOpts); 

Silly-V
Silly-VCorrect answer
Legend
November 16, 2015

Are you starting out with pre-defined datasets already in the document?

Right now, you're adding a new dataset, and (if there had been no datasets previously), displaying it. So if you already have all the datasets in the document, you don't need to add any, just loop through them and display and save each one.

Here's what I typically do:

var currentDataset;

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

  currentDataset = docRef.dataSets;

  currentDataset.display();

  docRef.saveAs(File("file://Users/Me/Desktop/" + currentDataset.name + ".pdf"));

};