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 4D Write Pro 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).
Example
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.