XMetaL Tips and Tricks
XMetaL Community Forum › XMetaL Tips and Tricks › Script Example: Functions for Selecting the Next or Previous Word
-
Derek Read May 5, 2010 at 12:06 am
Script Example: Functions for Selecting the Next or Previous Word
May 5, 2010 at 12:06 amParticipants 0Replies 1Last Activity 12 years, 10 months agoProducts: XMetaL Author (Enterprise and Essential) and XMAX
Tested with XMetaL Author Enterprise 6.0Should function in practically any version of XMAX or Author, at least going back to 3.x but probably all the way back to 1.0. Regardless of which version you are developing for make sure you properly test these in your environment together with all of your other scripts. Our clients do interesting things with our products so there is no way to predict every use case in advance.
Description:
Two functions for creating a Range object containing the next or previous word in the document with an option to show the resulting Range as a Selection (ie: make it visible to the author).Legal:
* Licensed Materials – Property of JustSystems, Canada, Inc.
*
* (c) Copyright JustSystems Canada, Inc. 2010
* All rights reserved.
*
*——————————————————————-
* The sample contained herein is provided to you “AS IS”.
*
* It is furnished by JustSystems Corporation as a simple example and has not been
* thoroughly tested under all conditions. JustSystems Canada, Inc., therefore, cannot
* guarantee its reliability, serviceability or functionality.
*
* This sample may include the names of individuals, companies, brands and products
* in order to illustrate concepts as completely as possible. All of these names are
* fictitious and any similarity to the names and addresses used by actual persons or
* business enterprises is entirely coincidental.
*———————————————————————[code]function getPreviousWord(boolMoveSelection) {
var rng1 = ActiveDocument.Range;
var rng2 = ActiveDocument.Range;
rng1.Collapse(1);
rng2.Collapse(1);
rng1.GotoPrevious(sqWordStart);
rng2.GotoPrevious(sqWordStart);
rng2.GotoNext(sqWordEnd);
rng1.ExtendTo(rng2);
if(boolMoveSelection) {
rng1.Select();
}
return(rng1);
}function getNextWord(boolMoveSelection) {
var rng1 = ActiveDocument.Range;
var rng2 = ActiveDocument.Range;
rng1.Collapse(0);
rng2.Collapse(0);
rng1.GotoNext(sqWordEnd);
rng2.GotoNext(sqWordEnd);
rng2.GotoPrevious(sqWordStart);
rng1.ExtendTo(rng2);
if(boolMoveSelection) {
rng1.Select();
}
return(rng1);
}[/code]Syntax:
getNextWord([boolMoveSelection])
getPreviousWord([boolMoveSelection])When boolMoveSelection = true the author's selection is moved.
When boolMoveSelection = false (or null) the author's selection is not moved.Returns:
A Range representing the previous/next word in the document. The Range can be used like any other Range object.
JScript Examples:- Show the text of the next word in the document without moving the selection.
Application.Alert(getNextWord(false).text); - Move the selection to the next word in the document.
getNextWord(true); - Show the text of the previous word in the document without moving the selection.
Application.Alert(getPreviousWord(false).text); - Move the selection to the previous word in the document.
getPreviousWord(true);
Siva January 14, 2016 at 4:58 pm
Reply to: Script Example: Functions for Selecting the Next or Previous Word
January 14, 2016 at 4:58 pmHi,
I have a requirement to get previous word in the current document and the based on the previous value, quotes ” have to changed to open curly quotes or closed curly quotes . I tried to use getPreviousWord(false).text to get the previous value but it is not working. I am getting the error message . object doesn't support this property or method. Kindly help.
- Show the text of the next word in the document without moving the selection.
-
AuthorPosts
- You must be logged in to reply to this topic.