Tech Tip: Getting the absolute range for each page in a 4D Write Pro document
PRODUCT: 4D | VERSION: 17 | PLATFORM: Mac & Win
Published On: May 10, 2019
To get an absolute range positions of a selected text in a 4D Write Pro document, the command WP SELECT can report the start and end text range positions. This can be useful when using the WP SELECT command to go to locations of the document. The following utility method can report in an array object of absolute ranges for each page:
// ---------------------------------------------------------------------- // Name: EXTRACT_WP_PAGE_RANGES // Description: Method will extract the pages from the Write Pro area // and return the Page range in an object in absolute positions. // // Parameters: // $1 (POINTER) - Pointer to the Write Pro Area // $2 (POINTER) - Pointer to the Array Object to return Range absolute. // ---------------------------------------------------------------------- C_POINTER($1;$writeProObj) C_POINTER($2;$arrPageRangeObj) C_LONGINT($i;$nbPages;$page;$tableName;$fieldName) C_LONGINT($currentPage;$start_pos;$end_pos) C_OBJECT($range;$body;$info;$paragraph) C_TEXT($varName) C_BOOLEAN($start_read) C_COLLECTION($_paragraphs) ARRAY OBJECT($arrObj;0) If (Count parameters=2) $writeProObj:=$1 $arrPageRangeObj:=$2 $body:=WP Get body($writeProObj->) $_paragraphs:=WP Get elements($body;wk type paragraph) $start_read:=False $currentPage:=0 $start_pos:=0 $end_pos:=0 $i:=0 For each ($paragraph;$_paragraphs) $i:=$i+1 $info:=WP Get position($paragraph) $page:=OB Get($info;"page") WP SELECT($writeProObj->;$paragraph) RESOLVE POINTER($writeProObj;$varName;$tableName;$fieldName) $range:=WP Get selection(*;$varName) If ($currentPage#$page) $currentPage:=$page If ($start_read=False) $start_read:=True $start_pos:=$range.start Else $range:=WP Create range($writeProObj->;$start_pos;$end_pos) APPEND TO ARRAY($arrPageRangeObj->;$range) $start_pos:=$range.end End if Else $end_pos:=$range.end End if If ($i=$_paragraphs.length) $range:=WP Create range($writeProObj->;$start_pos;$end_pos) APPEND TO ARRAY($arrPageRangeObj->;$range) End if End for each End if |
Here is a sample of using the method where a Write Pro document contains 3 pages:
ARRAY OBJECT($arrPageRangeObj;0) EXTRACT_WP_PAGE_RANGES (->WriteProArea;->$arrPageRangeObj) |
The following is reported in the array object: