Copy link to clipboard
Copied
Dear friends,
Yet now I can not reproduce the following situation in a short test script:
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 pla
...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 ?
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
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
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
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