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

How to Apply Conversion Table to FM file.

New Here ,
May 27, 2016 May 27, 2016

Copy link to clipboard

Copied

I have a conversion table generated for a group of files I am trying to structure. I want to be able to apply the conversion table with Extendscript. The script I have doesn't save any converted file. I am not sure why is it not saving the file. I was under the impression that the "Structure Generator" should create the new file. If this incorrect.

Here is the code I am trying to use.

var myFile = File.openDialog ("Select File to Convert");

var myCT = File.openDialog ("Select ConversionTable");

var CT = openFile (myCT.fsName, 0);

applyConversionTable (myFile.fsName, CT)

closeFile (CT);

function applyConversionTable(fileName, CT){

    var doc= openFile (fileName, 0);

    var name = fileName.replace(/[\w\.]+$/,"test.fm") 

    CallClient("Structure Generator", "InputDocId " + doc.id);

    CallClient("Structure Generator", "RuleDocId " + CT.id);

    CallClient("Structure Generator", "OutputDocName " + name);

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

    closeFile (doc);

}

function openFile( fileName, visible){

    

    var i = 0;

    var doc = 0;

    

    var openParams = GetOpenDefaultParams();

    var retParams = new PropVals();

    

    i = GetPropIndex(openParams, Constants.FS_AlertUserAboutFailure);

    openParams.propVal.ival = false;

    i = GetPropIndex(openParams, Constants.FS_MakeVisible);

    openParams.propVal.ival = visible;

    i = GetPropIndex(openParams, Constants.FS_FileIsOldVersion);

    openParams.propVal.ival = Constants.FV_DoOK;

    i = GetPropIndex(openParams, Constants.FS_FileIsInUse);

    openParams.propVal.ival = Constants.FV_ResetLockAndContinue;

    i = GetPropIndex(openParams, Constants.FS_FontChangedMetric);

    openParams.propVal.ival = Constants.FV_DoOK;

    i = GetPropIndex(openParams, Constants.FS_FontNotFoundInCatalog);

    openParams.propVal.ival = Constants.FV_DoOK;

    i = GetPropIndex(openParams, Constants.FS_FontNotFoundInDoc);

    openParams.propVal.ival = Constants.FV_DoOK;

    i = GetPropIndex(openParams, Constants.FS_RefFileNotFound);

    openParams.propVal.ival = Constants.FV_AllowAllRefFilesUnFindable;

    

    doc = Open(fileName, openParams, retParams);

    

    if (doc.ObjectValid() ===1){

        doc.openedByScript = true;

    }

    else{

        PrintOpenStatus(retParams);

    }

    return doc

}

function closeFile(doc){

    Constants.FF_CLOSE_MODIFIED = 1;

    var res = doc.Close(Constants.FF_CLOSE_MODIFIED);

}

TOPICS
Scripting

Views

422

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
community guidelines

correct answers 1 Correct answer

Mentor , Jun 01, 2016 Jun 01, 2016

Ah, found the problem. I noticed this earlier but didn't think it mattered, apparently it does. The other arguments must be all upper case. Like this:

    CallClient("Structure Generator", "INPUTDOCID " + doc.id);  
    CallClient("Structure Generator", "RULEDOCID " + CT.id);  
    CallClient("Structure Generator", "OUTPUTDOCNAME " + name);  
    CallClient("Structure Generator", "StructureDoc");  

I tested it and it works for me. FWIW, I think this is a shoddy feature of an otherwise very slick

...

Votes

Translate

Translate
Mentor ,
Jun 01, 2016 Jun 01, 2016

Copy link to clipboard

Copied

Hi ethanb10986590, I really apologize for the delay in answering this because I may have the solution. I'm not sure how I missed the thread.

Despite what the documentation says, I think this line is wrong:

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

Try this instead:

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

The manual has been wrong forever and if someone hadn't told me via a forum like this, I would have never known. Who could? Anyway, that should help. Although note that I didn't examine any other part of your code in detail.

Russ

Votes

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
community guidelines
New Here ,
Jun 01, 2016 Jun 01, 2016

Copy link to clipboard

Copied

Russ,

Thanks for the reply. I changed that line, and the script still failed to produce any output. I commented out the CallClient("Structure Generator", "OutputDocName " + name); line as well thinking there was an issue with saving the document, but frame-maker doesn't seem to ever even generate a new document.

Do you have any links to other places where someone has discussed this. The only other one I found was another unresolved post on this forum. Structure documents method

Thank you

Ethan

Votes

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
community guidelines
Mentor ,
Jun 01, 2016 Jun 01, 2016

Copy link to clipboard

Copied

Ah, found the problem. I noticed this earlier but didn't think it mattered, apparently it does. The other arguments must be all upper case. Like this:

    CallClient("Structure Generator", "INPUTDOCID " + doc.id);  
    CallClient("Structure Generator", "RULEDOCID " + CT.id);  
    CallClient("Structure Generator", "OUTPUTDOCNAME " + name);  
    CallClient("Structure Generator", "StructureDoc");  

I tested it and it works for me. FWIW, I think this is a shoddy feature of an otherwise very slick API client.

Russ

Votes

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
community guidelines
Advocate ,
Jun 01, 2016 Jun 01, 2016

Copy link to clipboard

Copied

The commands do not need to be uppercase. I tested the script and it works fine. My guess about why it does not work for Ethan is that the result file name is not a full and valid path name. It might also be that the permissions to write into the folder are not set correctly. Just add an alert with the result name to make sure your regular expression does not mess up the file name.

As Russ mentioned, this piece of code is fine except for the API which always returns the code for SUCCESS, no matter what happens. Russ' implementation in all his plug-ins is much better. I am using those return codes all the time.

Ciao

Votes

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
community guidelines
Mentor ,
Jun 01, 2016 Jun 01, 2016

Copy link to clipboard

Copied

Well, interestingly enough Jang seems to be right. For some reason, the code did not work initially for me. So I changed the case and it did work. Now I change it back and it continues to work. The files open hidden and the new, converted file is written to the same directory as the originals, as test.fm.

If OutputDocName is not there, you should get a new, unsaved file. So this was a proper troubleshooting step.

I'm not sure what else to say, Ethan. I've run this operation many times in the past and your code works for me. Did you replicate the steps manually just to make sure that the conversion table will actually work?

Russ

Votes

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
community guidelines
New Here ,
Jun 01, 2016 Jun 01, 2016

Copy link to clipboard

Copied

LATEST

I got the code to work. Using the "StuctureDoc" call works regardless of whether the other commands are uppercase of not. Not quite sure why it didnt work initially, but it is good now.

Thank you Russ and Jang

Votes

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
community guidelines