Get coordinates in a 4D Write Pro document

By now, you should be familiar with the WP Get position command. At the very least you’ve read about it in this blog post. Introduced with v17, it helps you get information about the location of elements within your documents.

4D v17 R4 spices things up … now, it also returns coordinates!

new attributes

The WP Get position command returns two new attributes: bounds and rangeHeight.

The bounds attribute is an object which describes the rectangle surrounding a range, according to its type. The type of the range passed can be “default type” (characters), “paragraph type”, “table type”, or “picture type”,  as shown below:

The bounds attribute has attributes of its own: left, top, right, and bottom. They’re numerics and expressed in the current layout unit (mm, cm, in, pt, or px).


This feature allows you to easily set up complex page designs. For example, when using templates you may need to compare the size of a block to insert according to the available space at the end of the current page. If the space isn’t big enough (i.e. “5cm”), you might decide to insert a page break first. Simple and easy. Here’s how to proceed:

$range:=WP Get selection(WParea)
WP SET ATTRIBUTES(WParea;wk layout unit;wk unit cm) // change the unit to "cm"
$position:=WP Get position($range;wk 4D Write Pro layout) // call the WP Get position function
$heightInCm:=$position.rangeHeight // read the height in "cm"
If ($heightInCm<5)
 // insert a break…
End if

here is the detailed content of the returned object

"section": 1,
"page": 1,
"column": 1,
"line": 11,
"position": 49,
"bounds":    // New!
  "left": 1.52,
  "top": 10.65,
  "right": 18.66,
  "bottom": 12.56,
  rangeHeight: 1.9  // New!

See the feature in action with this demo database. 

4D Write Pro: Get an element coordinates

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.