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 4D Write Pro documents!
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.
C_COLLECTION(wpSections)
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.
C_OBJECT(wpSection)
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)