Highlighted

How to re-activate body page after working on reference page?

Advocate ,
Jun 06, 2016

Copy link to clipboard

Copied

Dear friends,

Yet now I can not reproduce the following situation in a short test script:

  1. A document is opened and the script looks for existence of a Reference page "FM-calc"
  2. If found, skip to step 4
  3. If not found, such a reference page is copied from a template
  4. Work on the reference page: replace some paragraphs.
  5. The user does no see that the script has worked on the ref page and invokes a dialoge
  6. This dialog inserts a marker at the current location
  7. The marker is inserted in the reference page where the work has been left

How to go back to the current body page (which is the first one)?

Just placing

var pgf = goCurrentDoc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;

prior to the insertion of the marker does not do the trick.

Normally the user woud place the cursor into the document at a specific location and then invoke the dialog: this works fine.

But this dialog stays open when the user changes the document.

In the new document there may be no reference page and hence the script creates one.

The user click outside the text frame (illegal location for marker insert) - This can be handled with

  if (!goCurrentDoc.TextSelection.beg.obj.ObjectValid()) {
    alert ("Please place cursor in document text flow or select something!");
  return;
  }

But the for the switching back from the work on the ref page I have not found a solution.

Klaus,

I think there are better ways to handle this. The user should not have to finish the work that your script started. Why not just save the original insertion point / text selection before you do any work on the reference page? Then you could restore it afterwards. Something simple like:

var restoreTR = targetDoc.TextSelection;

As long as the variable stays valid (ie, stays within scope), you can do anything you want anywhere else in the file, then simply return the insertion point to that place when you are done.  If you actually switched the view to the reference pages, you could use the CurrentPage property to switch back. So, in summary, I would do something like this:

var restoreTR = targetDoc.TextSelection;

//....  do all the wild Klaus stuff on the reference pages, then;

var bodyPage = targetDoc.FirstBodyPageInDoc;

targetDoc.CurrentPage = bodyPage;

targetDoc.TextSelection = restoreTR;

targetDoc.ScrollToText(restoreTR);

Hope this helps,

Russ

TOPICS
Scripting

Views

216

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 re-activate body page after working on reference page?

Advocate ,
Jun 06, 2016

Copy link to clipboard

Copied

Dear friends,

Yet now I can not reproduce the following situation in a short test script:

  1. A document is opened and the script looks for existence of a Reference page "FM-calc"
  2. If found, skip to step 4
  3. If not found, such a reference page is copied from a template
  4. Work on the reference page: replace some paragraphs.
  5. The user does no see that the script has worked on the ref page and invokes a dialoge
  6. This dialog inserts a marker at the current location
  7. The marker is inserted in the reference page where the work has been left

How to go back to the current body page (which is the first one)?

Just placing

var pgf = goCurrentDoc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;

prior to the insertion of the marker does not do the trick.

Normally the user woud place the cursor into the document at a specific location and then invoke the dialog: this works fine.

But this dialog stays open when the user changes the document.

In the new document there may be no reference page and hence the script creates one.

The user click outside the text frame (illegal location for marker insert) - This can be handled with

  if (!goCurrentDoc.TextSelection.beg.obj.ObjectValid()) {
    alert ("Please place cursor in document text flow or select something!");
  return;
  }

But the for the switching back from the work on the ref page I have not found a solution.

Klaus,

I think there are better ways to handle this. The user should not have to finish the work that your script started. Why not just save the original insertion point / text selection before you do any work on the reference page? Then you could restore it afterwards. Something simple like:

var restoreTR = targetDoc.TextSelection;

As long as the variable stays valid (ie, stays within scope), you can do anything you want anywhere else in the file, then simply return the insertion point to that place when you are done.  If you actually switched the view to the reference pages, you could use the CurrentPage property to switch back. So, in summary, I would do something like this:

var restoreTR = targetDoc.TextSelection;

//....  do all the wild Klaus stuff on the reference pages, then;

var bodyPage = targetDoc.FirstBodyPageInDoc;

targetDoc.CurrentPage = bodyPage;

targetDoc.TextSelection = restoreTR;

targetDoc.ScrollToText(restoreTR);

Hope this helps,

Russ

TOPICS
Scripting

Views

217

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
Jun 06, 2016 0
Advocate ,
Jun 06, 2016

Copy link to clipboard

Copied

Klaus.

Why do you need to switch to the reference pages in the first place? You can insert markers in the reference pages without making them active? And even getting input from the user which is then added into the reference page does not require activating that view. Are we missing some info here?

Can you share the code you are using to switch to the reference pages ?

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...
Jun 06, 2016 0
Advocate ,
Jun 07, 2016

Copy link to clipboard

Copied

Jang,

I use paragraphs on the ref page to keep information for the script, which is relevant for the current document (between sessions). For example:

  oRefPage = targetDoc.GetNamedRefPage (refPageName);

// ...
  oFlow = targetDoc.FirstFlowInDoc;              // go to the relevant flow in ref page

// ...
  oPara = oFlow.FirstTextFrameInFlow.FirstPgf;
  switch (category)  {
    case "Ref-Variables":
      tr = GetParagraphs (oPara, "Ref-Variables");// paragraphs to be replaced
      replaceString  = gasUserVariables.join("\n");  // \n gives new paragraphs; empty array => empty ¶
      targetDoc.TextSelection = tr;              // set up the text range to clear the original text
      targetDoc.Clear(0);                        // clear it
      targetDoc.AddText(tr.end, replaceString);  // insert new text at end of "selection"
      return true;

// ...

I'ts obvious that the current text location now is in the ref page and for a check I need to

  • define a (not used) text loction on the body page. If the user is unaware the marker would be inserted at an unexpected place.
  • or define an 'undefined' TL. This would generate a message to the user to place the curser at a location of his desire. What works in a test script does not work in the 'real world' script.

But then I had this simple idea to just use a flag: Insert before line 13 (and in the other cases):

      gbRefPageUse = true;                        // force user to place cursor in body page


And the test at the Insert Button is just this:

  if (gbRefPageUse) {                             // set in PutRefPageItems
    alert ("Please place cursor in document text flow or select something!");
    gbRefPageUse = false;
  return;
  }


This works as expected... Sometimes I look to far for a solution.

Thanks

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...
Jun 07, 2016 0
Mentor ,
Jun 07, 2016

Copy link to clipboard

Copied

Klaus,

I think there are better ways to handle this. The user should not have to finish the work that your script started. Why not just save the original insertion point / text selection before you do any work on the reference page? Then you could restore it afterwards. Something simple like:

var restoreTR = targetDoc.TextSelection;

As long as the variable stays valid (ie, stays within scope), you can do anything you want anywhere else in the file, then simply return the insertion point to that place when you are done.  If you actually switched the view to the reference pages, you could use the CurrentPage property to switch back. So, in summary, I would do something like this:

var restoreTR = targetDoc.TextSelection;

//....  do all the wild Klaus stuff on the reference pages, then;

var bodyPage = targetDoc.FirstBodyPageInDoc;

targetDoc.CurrentPage = bodyPage;

targetDoc.TextSelection = restoreTR;

targetDoc.ScrollToText(restoreTR);

Hope this helps,

Russ

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...
Jun 07, 2016 0
K.Daube LATEST
Advocate ,
Jun 08, 2016

Copy link to clipboard

Copied

Russ, thank You very much!

Last night I had the same idea, but I did not get it right (soo simplistic approach).

Now it really works as intended!

Klaus

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...
Jun 08, 2016 0