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

Automating an unstructured text selection into a new DITA document

New Here ,
Aug 16, 2013 Aug 16, 2013

Copy link to clipboard

Copied

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?

TOPICS
Scripting

Views

1.1K

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 ,
Aug 20, 2013 Aug 20, 2013

Copy link to clipboard

Copied

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

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 ,
Aug 20, 2013 Aug 20, 2013

Copy link to clipboard

Copied

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

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 ,
Aug 20, 2013 Aug 20, 2013

Copy link to clipboard

Copied

Thanks Russ and Jang.

Indeed, I figured that such a script would be extrememly difficult, if not impossible, to create. The automation isn't critical for me to have, but it sure would be interesting to see and I think it would help me get a better handle on ExtendScript.

As for the Open() method, I've tried all sorts of different variations of it with no success. I've tried using GetProps(), GetOpenDefaultParams(), etc. to get the propVals on an existing document of the kind I want to be able to open, but I can't seem to pull them up. The dearth of supporting documentation for ExtendScript is killing me.

Russ - I don't suppose you could show me a working sample that uses the Open() method?

Thanks again, guys.

//C

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 ,
Aug 20, 2013 Aug 20, 2013

Copy link to clipboard

Copied

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.propVal.ival = Constants.FV_DoCancel;

    }

          i = GetPropIndex ( oaOpenProps, Constants.FS_FileIsOldVersion );

          oaOpenProps.propVal.ival = Constants.FV_DoOK;

          i = GetPropIndex ( oaOpenProps,Constants.FS_FontNotFoundInCatalog );

          oaOpenProps.propVal.ival = Constants.FV_DoOK;

          i = GetPropIndex ( oaOpenProps,Constants.FS_FontNotFoundInDoc );

          oaOpenProps.propVal.ival = Constants.FV_DoOK;

          i = GetPropIndex ( oaOpenProps,Constants.FS_RefFileNotFound );

          oaOpenProps.propVal.ival = Constants.FV_AllowAllRefFilesUnFindable;

          i = GetPropIndex ( oaOpenProps,Constants.FS_UpdateTextReferences );

          oaOpenProps.propVal.ival = Constants.FV_DoNo;

          i = GetPropIndex ( oaOpenProps,Constants.FS_UpdateXRefs );

          oaOpenProps.propVal.ival = Constants.FV_DoNo;

          i = GetPropIndex ( oaOpenProps,Constants.FS_AlertUserAboutFailure );

          oaOpenProps.propVal.ival = false;

          i = GetPropIndex ( oaOpenProps,Constants.FS_UseRecoverFile );

          oaOpenProps.propVal.ival = Constants.FV_DoShowDialog;

    if ( sOptions.match ( "readonly" ) )

    {

                    i = GetPropIndex ( oaOpenProps,Constants.FS_OpenDocViewOnly );

                    oaOpenProps.propVal.ival = true;

          }

    else

    {

                    i = GetPropIndex ( oaOpenProps,Constants.FS_FileIsInUse );

                    if ( sOptions.match ( "forcewritable" ) )

                    {

                              oaOpenProps.propVal.ival = Constants.FV_ResetLockAndContinue;

                    }

                    else

                    {

                              oaOpenProps.propVal.ival = Constants.FV_DoShowDialog;

                    }

          }

          oaRetParms = new PropVals ( );

          oDocOpen = Open ( sFilename, oaOpenProps, oaRetParms );

          return oDocOpen;

}

Good luck

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
New Here ,
Aug 20, 2013 Aug 20, 2013

Copy link to clipboard

Copied

Much obliged, Jang!

Could you give me an example of some parameters I can insert to make the function work. I tried entering a file path into the first parameter and "forewritable" into the second parameter, but nothing happened.

I appreciate the help.

//C

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 ,
Feb 07, 2014 Feb 07, 2014

Copy link to clipboard

Copied

LATEST

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.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

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