Get the position of any part of a 4D Write Pro document

4D Write Pro is continuously evolving; thanks to the new features and functionalities we’re shipping with every R-release. A world of possibilities is wide open! Today, thanks to a new command, you can get a set of information about the location of any element within your documents.

Here is a database example to get you up and running with this new feature: 

4D Write Pro: Get an element position

Five DATA POINTS at once

A new command, dedicated to 4D Write Pro is now available: WP Get position. Given a specific range, element, or reference, this command returns an object variable with five important data points at once: the section number where the range begins, the page number, the column number, the line number, and even the position of the first character of the range in the line!

This feature will allow you to easily generate your documents by programming. For instance, applying complex rules like “Set the fonts of all the paragraphs of page 3 in Arial 18pt” or “Create an index based on the bookmarks on the last page”, can now be done in just a few lines of code. It’s a breeze!

CODE example

Here is a code snippet to set the color of the first and last page of a document to blue (and the rest to black):

$nbPages:=WP Get page count([DOC]Sample)
$body:=WP Get body([DOC]Sample)
$_paragraphs:=WP Get elements($body;wk type paragraph)
For each ($paragraph;$_paragraphs)
 $info:=WP Get position($paragraph)
 If ($ | ($$nbPages// First and last page paragraphs in blue
  WP SET ATTRIBUTES($paragraph;wk text color;"blue")
 Else   // Other pages paragraphs in black
  WP SET ATTRIBUTES($paragraph;wk text color;"black")
 End if 
End for each

Roland Lannuzel
• Product Owner & 4D Expert •After studying electronics, Roland went into industrial IT as a developer and consultant, building solutions for customers with a variety of databases and technologies. In the late 80’s he fell in love with 4D and has used it in writing business applications that include accounting, billing and email systems.Eventually joining the company in 1997, Roland’s valuable contributions include designing specifications, testing tools, demos as well as training and speaking to the 4D community at many conferences. He continues to actively shape the future of 4D by defining new features and database development tools.