4D Blog

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

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

May 2, 2018

Product

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 ($info.page=1) | ($info.page=$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

Discuss

Tags 4D Write Pro, Programming, v17, Word processor

Latest related posts

  • February 3, 2026

    4D Write Pro – Adding a margin automatically when bullets are set using standard actions

  • January 22, 2026

    Transform Static Documents into Actionable Knowledge with AIKit

  • January 22, 2026

    Deploy Fluent UI effortlessly in your 4D applications

Roland Lannuzel
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.
  • Deutsch
  • Français
  • English
  • Português
  • Čeština
  • Español
  • Italiano
  • 日本語

Categories

Browse categories

  • AI
  • 4D View Pro
  • 4D Write Pro
  • Email, Microsoft 365, Gmail
  • Development Mode
  • 4D Language
  • ORDA
  • User Interface / GUI
  • 4D Qodly Pro
  • Server
  • Maintenance
  • Deployment
  • 4D Tutorials
  • Generic
  • 4D Summit sessions and other online videos

Tags

4D-Analyzer 4D AIKit 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 21 21 R2 Administration AI Artificial Intelligence Build application Class Client/Server Code editor Collections Compatibility settings Formula Google Listbox Logs Mail Network Objects OpenAI ORDA PDF Pictures Preemptive Programming REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience vscode Web Word processor

Tags

4D-Analyzer 4D AIKit 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 21 21 R2 Administration AI Artificial Intelligence Build application Class Client/Server Code editor Collections Compatibility settings Formula Google Listbox Logs Mail Network Objects OpenAI ORDA PDF Pictures Preemptive Programming REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience vscode Web Word processor
Subscribe to 4D Newsletter

© 2026 4D SAS - All rights reserved
Terms & Conditions | Legal Notices | Data Policy | Cookie Policy | Contact us | Write for us


Subscribe to 4D Newsletter

* Your privacy is very important to us. Please click here to view our Policy

Contact us

Got a question, suggestion or just want to get in touch with the 4D bloggers? Drop us a line!

* Your privacy is very important to us. Please click here to view our Policy