4D Blog

Home Product Programmatically access elements in 4D Write Pro

Programmatically access elements in 4D Write Pro

April 26, 2018

Product

4D Write Pro keeps offering more and more programming capabilities! Let’s say you want to programmatically change the style of a table, paragraph, or image in an existing 4D Write Pro document. With 4D v17, it’s possible! Now you can access any element or part of a document, by programming. These parts, called elements, will be returned either as a collection thanks to the WP Get elements function, or as a single element with WP Get element by ID function.

collection of elements

The WP Get elements command returns a collection of elements of any type (paragraphs, tables, images, etc. If a typed range or reference is passed, the command will return a collection containing only elements of the corresponding type (unless specified in the second parameter). Otherwise, the command returns a collection containing all of the available elements, no matter its type.

For example:

  • If the first parameter is a range of a specific type (a paragraph range for instance), then the returned elements will also be paragraphs.
  • If the first parameter is not specific (a full document or a heterogeneous range) then the returned elements can be filtered with a final parameter (optional).

// Returns all elements of the document
$allElements
:=WP Get elements(wpDoc)

// Returns all table elements of the document
$allTables:=WP Get elements(wpDoc;wk type table)

// Returns all paragraphs of the range
$paragraphCol:=WP Get elements($paragraphRange)

// Returns all paragraphs of the table range
$paragraphCol:=WP Get elements($tableRange;wk type paragraph)

// Returns all the tables of the given range
$someTableCol:=WP Get elements($customRange;wk type table)  

Once created, the collection can then be parsed. Each element is an object that can be used as parameter for the command, WP SET ATTRIBUTES.

Single Element

The WP Get element by ID command allows access to a single element. In 4D Write Pro documents, some elements have default IDs (like pictures and tables). When they exist, these IDs can be modified, and when they don’t exist, they can be created. Knowing that, the behavior of the command is quite easy to understand, it returns a single element for a given ID!

Once you get the element, you can manipulate it as shown below:

$element:=WP Get element by ID(myDoc;"Table1")
WP SET ATTRIBUTES($element;wk border style;wk solid)
WP SET ATTRIBUTES($element;wk border width;"4px")
WP SET ATTRIBUTES($element;wk border color;"blue")

Discuss

Tags 4D Write Pro, 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
  • 4D for Mobile
  • Email
  • Development Mode
  • 4D Language
  • ORDA
  • User Interface / GUI
  • Qodly Studio
  • 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 20 R10 21 21 R2 Administration AI Artificial Intelligence Build application Class Client/Server Code editor Collections Compatibility settings Formula 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 20 R10 21 21 R2 Administration AI Artificial Intelligence Build application Class Client/Server Code editor Collections Compatibility settings Formula 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