Skip navigation
Cronos75
Currently Being Moderated

Automating an unstructured text selection into a new DITA document

Aug 16, 2013 4:30 PM

Hi everyone,

 

Lately I've been thinking that it would come in handy to have a script that would allow me to select/highlight (using a mouse) a few words of text in an unstructured FM document, and then choose from a dropdown menu the kind of DITA doc (Task, Concept, or Reference) that I want to paste the text into. Upon making the selection, a new FM DITA page would be automatically generated with the copied text pasted in between its title tags.

 

Is the kind of automation I'm looking for within the realm of possiblity using ExtendScript? It seems like I might be able to cobble together some scripts I've found to take care of the copying & pasting and the dropdown menu, but I have yet to figure out how to write a script that will create and open a new document in FrameMaker.

 

Any thoughts?

 
Replies
  • Currently Being Moderated
    Aug 20, 2013 4:39 AM   in reply to Cronos75

    Cronos75,

     

    I'll offer a few thoughts since no one else has. I'm not sure, though, that I'll be very helpful.

     

    I think the biggest challenge here is the invocation of a structuring mechanism, not general document management. It is normally very simple to open a new document with the Open() method, once you figure out how the input parameter scheme works. The addition of the DITA structure, though, is a different story. Presumably, you would need to invoke the Structure Generator using a conversion table which is possible, but this process could have much risk for error. You would probably have to paste the text into a separate file, structure it, then copy it into the existing DITA structure in the target file. Lots of things could go wrong there.

     

    Anyway, I'm sure what you want to do is possible with ES, but you'll have lots of work to do.

     

    Russ

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 20, 2013 4:57 AM   in reply to Russ Ward

    Cronos,

     

    I have done plenty of conversion projects in the past years and from my experience I can only give you one very good advice about this: FORGET IT.

     

    Creating a script that allows selecting a piece of text in an unstructured document and convert it into a valid DITA file is not something you should even want to create. It is impossible to capture all the possible errors due to text selections that are impossible to structure.

     

    You have two options to go forward building on this idea:

     

    1. Create somthing that allows copying the currently selected piece of text into an existing DITA document, in which case the selected text should always be wrapped into something that cannot invalidate the structure. I would suggest gluing all paragraph text together so that you have one single paragraph and wrap that content into a single <p> element in your existing DITA file. Although this method might sound like a good idea, I do not think it is.

     

    2. Structure the entire document and save it as DITA - if you can make it valid DITA, that is. This process can be highly optimized using scripts to pre- and post-process the document (removing some horrible unstructured stuff before conversion and augmenting the resulting structure after).

     

    I hope you will find my advice useful. I am not trying to step on anyone's toes, just helping you to learn from my experience.

     

    Kind regards

     

    Jang

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 20, 2013 11:03 AM   in reply to Cronos75

    Hello again Cronos,

     

    Here is a routine I created as a function to call from almost all my scripts. This function not only allows opening an FM document without updating all kinds of stuff but also doing this as read-only and/or invisible. Note that when you have opened a FM document invisible, it will remain invisible unless you change its visibility status. In general, you should make sure you close all invisibly opened files before your script quits (even in case an error occurs).

     

     

    function OpenDoc ( sFilename, sOptions )

    {

              var oaOpenProps = GetOpenDefaultParams ( );

     

        if ( sOptions.match ( "invisible" ) )

        {

            i = GetPropIndex ( oaOpenProps, Constants.FS_MakeVisible );

            oaOpenProps[i].propVal.ival = Constants.FV_DoCancel;

        }

     

              i = GetPropIndex ( oaOpenProps, Constants.FS_FileIsOldVersion );

              oaOpenProps[i].propVal.ival = Constants.FV_DoOK;

     

              i = GetPropIndex ( oaOpenProps,Constants.FS_FontNotFoundInCatalog );

              oaOpenProps[i].propVal.ival = Constants.FV_DoOK;

     

              i = GetPropIndex ( oaOpenProps,Constants.FS_FontNotFoundInDoc );

              oaOpenProps[i].propVal.ival = Constants.FV_DoOK;

     

              i = GetPropIndex ( oaOpenProps,Constants.FS_RefFileNotFound );

              oaOpenProps[i].propVal.ival = Constants.FV_AllowAllRefFilesUnFindable;

     

              i = GetPropIndex ( oaOpenProps,Constants.FS_UpdateTextReferences );

              oaOpenProps[i].propVal.ival = Constants.FV_DoNo;

     

              i = GetPropIndex ( oaOpenProps,Constants.FS_UpdateXRefs );

              oaOpenProps[i].propVal.ival = Constants.FV_DoNo;

     

              i = GetPropIndex ( oaOpenProps,Constants.FS_AlertUserAboutFailure );

              oaOpenProps[i].propVal.ival = false;

     

              i = GetPropIndex ( oaOpenProps,Constants.FS_UseRecoverFile );

              oaOpenProps[i].propVal.ival = Constants.FV_DoShowDialog;

     

        if ( sOptions.match ( "readonly" ) )

        {

                        i = GetPropIndex ( oaOpenProps,Constants.FS_OpenDocViewOnly );

                        oaOpenProps[i].propVal.ival = true;

              }

        else

        {

                        i = GetPropIndex ( oaOpenProps,Constants.FS_FileIsInUse );

                        if ( sOptions.match ( "forcewritable" ) )

                        {

                                  oaOpenProps[i].propVal.ival = Constants.FV_ResetLockAndContinue;

                        }

                        else

                        {

                                  oaOpenProps[i].propVal.ival = Constants.FV_DoShowDialog;

                        }

              }

     

              oaRetParms = new PropVals ( );

              oDocOpen = Open ( sFilename, oaOpenProps, oaRetParms );

              return oDocOpen;

    }

     

     

    Good luck

     

    Jang

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 7, 2014 5:40 PM   in reply to Cronos75

    Don't know if you're still around, Cronos75, but here is a simple example of using the Open() function to create a new FrameMaker file.

     

    -------------------------

    // This gives you a PropVals object with default values that you will feed to Open().

    var oPropVals = GetOpenDefaultParams();

     

    // These two lines set a value in the PropVals object that says this is a new file to create.

    var i=GetPropIndex(oPropVals,Constants.FS_NewDoc);

    oPropVals[i].propVal.ival=true;

     

    // This gives you another PropVals object that Open() requires for some reason.

    oRetParms = new PropVals();

     

    // The full file path and filename of the FrameMaker file to use as a template for the new file.

    // Use two slashes instead of one in paths.

    sFilename = "C:\\Users\\myname\\dev\\template.fm";

     

    Open(sFilename, oPropVals, oRetParms);

    -------------------------

     

    Result: This opens an untitled file in FrameMaker that is based on the template file you supplied. The template could be any damn FrameMaker file you have sitting around.

     

    Mark

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points