Highlighted

How to add .fm files to existing book using ExtendScript ToolKit

New Here ,
Sep 24, 2018

Copy link to clipboard

Copied

I am writing an ExtendScript Toolkit script to open a ditamap, save it as a book, and then add some boilerplate .fm files in a specific order between the title page and TOC.

So far I've got everything except adding the boiler plate .fm files.  Anyone know how to do that?

var sourceDoc = openXmlFile("Ditamap file path goes here");

var path = "Output file path goes here";

saveToFm(sourceDoc, path);

function openXmlFile(filePath) { 

    var file = File(filePath);

    var fileName = file.fsName;

    var openParams = GetOpenDefaultParams(); 

    var retParams = new PropVals();

    var doc = Open(fileName, openParams, retParams);

    return doc; 

function saveToFm(fileObject, savePath) { 

    var saveParams = GetSaveDefaultParams(); 

   

    var i = GetPropIndex(saveParams, Constants.FS_FileType); 

    saveParams.propVal.ival = Constants.FV_SaveFmtBookWithFm;

   

    var i = GetPropIndex(saveParams, Constants.FS_DitavalFile); 

    saveParams.propVal.sval = "Dit Val file path goes here"

   

    var saveAsName = savePath; 

    var returnParamsp = new PropVals(); 

    fileObject.Save(saveAsName, saveParams, returnParamsp); 

Adobe Community Professional
Correct answer by frameexpert | Adobe Community Professional

Assuming the book is your book object, you can do something like this:

bookComp = book.NewSeriesBookComponent (0);

// Move it to the end.

if (bookComp.NextComponentInBook.ObjectValid()) {

    bookComp.NextComponentInBook = 0;

} // Set its path.

bookComp.Name = "Absolute path to the component.";

TOPICS
Scripting

Views

632

Likes

Translate

Translate

Report

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

How to add .fm files to existing book using ExtendScript ToolKit

New Here ,
Sep 24, 2018

Copy link to clipboard

Copied

I am writing an ExtendScript Toolkit script to open a ditamap, save it as a book, and then add some boilerplate .fm files in a specific order between the title page and TOC.

So far I've got everything except adding the boiler plate .fm files.  Anyone know how to do that?

var sourceDoc = openXmlFile("Ditamap file path goes here");

var path = "Output file path goes here";

saveToFm(sourceDoc, path);

function openXmlFile(filePath) { 

    var file = File(filePath);

    var fileName = file.fsName;

    var openParams = GetOpenDefaultParams(); 

    var retParams = new PropVals();

    var doc = Open(fileName, openParams, retParams);

    return doc; 

function saveToFm(fileObject, savePath) { 

    var saveParams = GetSaveDefaultParams(); 

   

    var i = GetPropIndex(saveParams, Constants.FS_FileType); 

    saveParams.propVal.ival = Constants.FV_SaveFmtBookWithFm;

   

    var i = GetPropIndex(saveParams, Constants.FS_DitavalFile); 

    saveParams.propVal.sval = "Dit Val file path goes here"

   

    var saveAsName = savePath; 

    var returnParamsp = new PropVals(); 

    fileObject.Save(saveAsName, saveParams, returnParamsp); 

Adobe Community Professional
Correct answer by frameexpert | Adobe Community Professional

Assuming the book is your book object, you can do something like this:

bookComp = book.NewSeriesBookComponent (0);

// Move it to the end.

if (bookComp.NextComponentInBook.ObjectValid()) {

    bookComp.NextComponentInBook = 0;

} // Set its path.

bookComp.Name = "Absolute path to the component.";

TOPICS
Scripting

Views

633

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Sep 24, 2018 0
Adobe Community Professional ,
Sep 24, 2018

Copy link to clipboard

Copied

Assuming the book is your book object, you can do something like this:

bookComp = book.NewSeriesBookComponent (0);

// Move it to the end.

if (bookComp.NextComponentInBook.ObjectValid()) {

    bookComp.NextComponentInBook = 0;

} // Set its path.

bookComp.Name = "Absolute path to the component.";

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 24, 2018 0
New Here ,
Sep 24, 2018

Copy link to clipboard

Copied

I've updated my code with a

var book = app.ActiveBook;

And your function to add book components

function addBoilerPlate(book, componentPath) {

   

bookComp = book.NewSeriesBookComponent (0);  

// Move it to the end.  

if (bookComp.NextComponentInBook.ObjectValid()) {  

    bookComp.NextComponentInBook = 0;  

} // Set its path.  

bookComp.Name = componentPath;

bookComp.MoveComponent(1);

}

By itself your function adds the boilerPlate.fm to the end of the book.  However, I want it between the title and TOC.  Once it is added I can move it up with bookComp.MoveComponent(1); but the final version of this script will deal with books with different numbers of chapters so that wont work.  Is there a way for me to add boilerPlate.fm between 2 specific pages or after or before a specific page?  I tried modifying the 0s in your function, but no matter what I did it always added boilerPlate.fm to the end of the book.

Full code:

var sourceDoc = openXmlFile("Absolute path to ditamap");

var path = "Absolute path to output";

var componentPath = "Absolute path to boilerPlate.fm"

saveToFm(sourceDoc, path);

var book = app.ActiveBook;

addBoilerPlate(book, componentPath);

function openXmlFile(filePath) { 

    var file = File(filePath);

    var fileName = file.fsName;

    var openParams = GetOpenDefaultParams(); 

    var retParams = new PropVals();

    var doc = Open(fileName, openParams, retParams);

    return doc; 

function saveToFm(fileObject, savePath) { 

    var saveParams = GetSaveDefaultParams(); 

   

    var i = GetPropIndex(saveParams, Constants.FS_FileType); 

    saveParams.propVal.ival = Constants.FV_SaveFmtBookWithFm;

   

    var i = GetPropIndex(saveParams, Constants.FS_DitavalFile); 

    saveParams.propVal.sval = "Absolute path to Dita Val File"

   

    var saveAsName = savePath; 

    var returnParamsp = new PropVals(); 

    fileObject.Save(saveAsName, saveParams, returnParamsp); 

function addBoilerPlate(book, componentPath) {

   

bookComp = book.NewSeriesBookComponent (0);  

// Move it to the end.  

if (bookComp.NextComponentInBook.ObjectValid()) {  

    bookComp.NextComponentInBook = 0;  

} // Set its path.  

bookComp.Name = componentPath;

bookComp.MoveComponent(1);

}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 24, 2018 0
Adobe Community Professional ,
Sep 24, 2018

Copy link to clipboard

Copied

Find the toc component; let's assume that the variable is tocComp. Then you can do this.

bookComp.NextComponentInBook = tocComp;

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 24, 2018 0
New Here ,
Sep 25, 2018

Copy link to clipboard

Copied

Thank you!  I got it working:

var sourceDoc = openXmlFile("Absolute file path to ditamap");

var path = "Absolute file path to output file";

var boilerPlate_1 = "Absolute file path to BP1"

var boilerPlate_2 = "Absolute file path to BP2"

saveToFm(sourceDoc, path);

var book = app.ActiveBook;

var tableOfContents = book.FirstComponentInBook

tableOfContents = tableOfContents.NextComponentInBook

addBoilerPlate(book, boilerPlate_1, tableOfContents);

addBoilerPlate(book, boilerPlate_2, tableOfContents);

function openXmlFile(filePath) {

    var file = File(filePath);

    var fileName = file.fsName;

    var openParams = GetOpenDefaultParams();

    var retParams = new PropVals();

    var doc = Open(fileName, openParams, retParams);

    return doc;

}

function saveToFm(fileObject, savePath) {

    var saveParams = GetSaveDefaultParams();

  

    var i = GetPropIndex(saveParams, Constants.FS_FileType);

    saveParams.propVal.ival = Constants.FV_SaveFmtBookWithFm;

  

    var i = GetPropIndex(saveParams, Constants.FS_DitavalFile);

    saveParams.propVal.sval = "Absolute file path to Dita Val File"

  

    var saveAsName = savePath;

    var returnParamsp = new PropVals();

    fileObject.Save(saveAsName, saveParams, returnParamsp);

}

function addBoilerPlate(book, componentPath, tableOfContents) {

var bookComp = book.NewSeriesBookComponent (0);  

// Move it to the end.  

if (bookComp.NextComponentInBook.ObjectValid()) {  

    bookComp.NextComponentInBook = tableOfContents;  

} // Set its path.  

bookComp.Name = componentPath;

}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 25, 2018 0