Skip to main content
February 14, 2013
Answered

[FM10] Some support needed with book save as XML

  • February 14, 2013
  • 2 replies
  • 2531 views

Hi there,

I'm in a process to convert loads of old non structured FM manuals into structured formats, and though it all works fine there is a lot of repetition involved I'd like to get rid off. I'm having a bit of experience with extendscript for indesign, but the documentation for FM is rather poor. So if someone can get me started or provide some codesnippets to make my job a bit more pleasant it would be highly appreciated 🙂

My processes :

First I open a book, and for each file I run the 'Generate conversion Table' command. The missing paragraph tags need to be added to an existing Conversion table called 'conversion_table'.

Question 1 : Can I use some code to do this automatically ? So all fm files in the book get opened (silent or not does not really matter) , missing tags are added to the existing table, and fm file is closed again.

Second : I clean up the conversion table so output is a bit streamlined. That's a manual process anyway so no issues

Third : I structure the book using the table. Pretty straight forward also so no problem here

Last step : I save all fm files as docbook 2.1 format, but again this requires me to open all fm files one by one, select 'save as XML', select docbook as format and save the file itself.

Question 2 : Can I also here use some code so all fm files in the book are opened, saved as XML using docbook format , and closed again with me leaning back and looking at my PC doing the dirty job for me. To push my luck it would be great if I could also integrate step 3

I guess all of this would be rather simple for a seasoned programmer, but I'm cracking my teeth on it. Therefore anybody that can point me in the right direction or provide some code that could get me running would make my day for sure

Thanks in advance!

K.

This topic has been closed for replies.
Correct answer frameexpert

I agree with Russ; you have a lot going on. I would suggest splitting your question into multiple posts, one for each step in the process. Most of us like to help, but I do this for a living so I can't spend too much time posting complete solutions for free. But here is some code that will automate your third step:

CallClient ("Structure Generator",  "InputDocId " + inputId);

CallClient ("Structure Generator",  "RuleDocId " + convId);

CallClient ("Structure Generator",  "StructureDoc");

The inputId and convId variables are the id properties of the input document and the conversion table document, respectively. For example, if you are structuring the active document, you would do this to get the inputId:

var inputId = app.ActiveDoc.id;

There are also commands to add new entries to an existing conversion table. The best place to get this information is in the FDK manuals. You will have to "translate" the information from C to ExtendScript, but at least you have something to start with. I don't think any of the Structure Generator information is in the ExtendScript documentation.

Rick

2 replies

frameexpert
Community Expert
frameexpertCommunity ExpertCorrect answer
Community Expert
February 18, 2013

I agree with Russ; you have a lot going on. I would suggest splitting your question into multiple posts, one for each step in the process. Most of us like to help, but I do this for a living so I can't spend too much time posting complete solutions for free. But here is some code that will automate your third step:

CallClient ("Structure Generator",  "InputDocId " + inputId);

CallClient ("Structure Generator",  "RuleDocId " + convId);

CallClient ("Structure Generator",  "StructureDoc");

The inputId and convId variables are the id properties of the input document and the conversion table document, respectively. For example, if you are structuring the active document, you would do this to get the inputId:

var inputId = app.ActiveDoc.id;

There are also commands to add new entries to an existing conversion table. The best place to get this information is in the FDK manuals. You will have to "translate" the information from C to ExtendScript, but at least you have something to start with. I don't think any of the Structure Generator information is in the ExtendScript documentation.

Rick

www.frameexpert.com
February 19, 2013

Thanks Rick, this helped me quite a lot.

I was able to figure out how to add the missing entries to my conversion table using below mentioned booktraverser in combination with following :

function UpdateConvTable(doc,name,ConvTableID ){

// get current doc id

var docId = doc.id;

// add missing tags to conversion table

CallClient("Structure Generator", "SourceDocId " + docId);

CallClient("Structure Generator", "UpdateTable " + ConvTableID );

// and save the documents so it's up to date with latest version

var params = GetSaveDefaultParams();

var returnParamsp =new PropVals();

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

params.propVal.ival =Constants.FV_SaveFmtBinary;

doc.Save(name, params, returnParamsp)

return

}

It does nicely what I want, it opens all the bookcomponents, adds the missing ones to my conversion table, saves the component and does all of this without nagging me with errors etc.

But..

I got the id of my conversion table by opening it, giving it the scope, and then retrieving the app.ActiveDoc.id. But this is a bit of unreliable method, for starters I'm not even sure if this id is unique and fixed, or can just be changed over time. What would therefore be a better to get the id of the conversion table, rather than having it hardcoded as I did now ?

Scenario I am thinking of is as follows

Book is selected, and script starts

-> if page with name "conversion_table" is not opened (using IsOnScreen ?), open the page (located at "C:\\conversion_table.fm)

-> if opened get the id , and run all code magic on all the book components (above function)

seems like fairly simple, but i can't find back any examples on how to use IsOnScreen, or opening a single document (my conversion table) without losing focus on selected book. Any advice / support would be welcome.

frameexpert
Community Expert
Community Expert
February 19, 2013

Thanks again Rick, it looks like a good alternative, but I'm not familiar with the /conversion/.test syntax.

I've tried a few things with above code, but it didn't give me results. Playing with the script I can get the name of the open docs etc, but the test thing puzzles me.

What would I need to change in (/Conversion/.test(doc.Name) === true) to make it work ? Assume I would have a document called conversion_table.fm, located at C:/folder/conversion_table.fm


This is where you get into core JavaScript versus FrameMaker ExtendScript. /Conversion/ is a JavaScript regular expression that matches the literal string "Conversion" somewhere in the file path or name. You can use /Conversion/i.test to give you a case-insensitive search; this is probably why it is failing for you. JavaScript has other ways of matching strings that you may find more convenient. I like the test method because it returns true or false.

Rick

www.frameexpert.com
Legend
February 18, 2013

Hi K,

Since nobody has responded, I thought I would add a little something, although probably not what you are asking for. Your requirements are well-suited for ExtendScript automation; however, they represent a fairly advanced usage of it. It could take some time to develop these scripts, more time than somebody can likely give you on a simple user-to-user forum post. So, I think that might be why you are having trouble getting responses.

This is a good place to ask specific questions about ES code, but yours is quite broad. I'm almost sure you would need to pay someone to write all that code. My suggestion is to back up a bit and start learning about ES at a lower level, then maybe  the way forward will eventually start to make more sense to you.

Russ