Manage sections with code in a 4D Write Pro document

Automatically translated from English

Want a different background per section? Or maybe a different margin per section? How about a different number of columns per section? Want to do all this with code?

With 4D v17 R3, you can manipulate sections with code to create complex and beautiful documents!

Database example

sections and a subsections

Sections allow you to have different layouts in the same document. For example, for each section you can define a different paper size and orientation, different margins, use columns, have different headers and footers, and so on.

A section can contain subsections. There are three types of subsections: first, left, and right page. For example, in a brochure, you want to align the titles and page numbers on the outer edges of your brochure, so left for left pages and right for right pages.

Retrieve the current section or all sections

You can retrieve a collection of sections in your document with the new command: WP Get sections.

wpSections:=WP Get sections(wpDoc)

You can also retrieve a reference to the first section intersected by the selection (range or element) the with the command: WP Get section.

wpSection:=WP Get section(WP Get selection(wpDoc))

Update an attribute for a specific section

Now that you can retrieve the section, it’s very easy to change the attributes for a specific section or its content. Just pass the section reference to the WP SET ATTRIBUTES and WP GET ATTRIBUTES commands.

For example, if you want three columns in the current section, you’d write:

WP SET ATTRIBUTE(wpSection;wk column count;3)

Create subsections with code

You can create a subsection with code using the new command: WP Create subsection.

You can create a subsection for the left page as follows:

$subSection:=WP Create subsection(wpSection;wk left page)

With a subsection reference, you can access the subsection’s header or footer and modify its attributes. It’s similar to the section.

For example, to left align the text in the header:

$header:=WP Get header($subSection)
WP SET ATTRIBUTES($header;wk text align;wk left)


When you create the left subsection, the right subsection is automatically created. You can get the reference to the right subsection with the WP Get subsection command.

On the right page, to right align the header text:

$subSection:=WP Get subsection(wpSection;wk right page)
$header:=WP Get header($subSection)
WP SET ATTRIBUTES($header;wk text align;wk right)

Vanessa Talbot

• Product Owner •

Vanessa Talbot joined 4D Program team in June, 2014. As a Product Owner, she is in charge of writing the user stories then translating it to functional specifications. Her role is also to make sure that the feature implementation delivered is meeting the customer need.

Since her arrival, she has worked to define key features in 4D. She has worked on most of preemptive multi-threading new features and also on a very complex subject: the new architecture for engined application. Vanessa has a degree from Telecom Saint-Etienne. She began her career at the Criminal Research Institute as a developer for the audiovisual department. She has also worked in media and medical fields as expert in technical support, production as well as documenting new features.