0

I'm trying to programmatically set two text styles inside an also programmatically created 4D Write Pro document, but the last style set is the only one assumed for the whole document.

I have created a new 4D Write Pro document (wpDoc), created a range for the whole document ($range), and used "WP Set Attributes" to format the text.

C_OBJECT(wpDoc;$range)
wpDoc:=WP New
$range:=WP Text range(wpDoc;wk start text;wk end text)

// Style 1
WP SET ATTRIBUTES($range;wk font;"DIN-Bold")
WP SET ATTRIBUTES($range;wk font size;"12pt")
WP SET TEXT($range;"Name: ";wk append)

// Style 2
WP SET ATTRIBUTES($range;wk font;"DIN-Regular")
WP SET ATTRIBUTES($range;wk font size;"10pt")
WP SET TEXT($range;[Companies]Name;wk append)

WP PRINT(wpDoc)

it should look like:

Name: Sample Company name

but it shows like:

Name (plain text): Sample Company name (plain text)

MarkAsh
  • 33
  • 6

1 Answers1

0

Since your range is growing with the text you are appending, you need to alter your range. The following code worked for me.

You should confirm that your font exists otherwise the attributes command will have no effect (FONT LIST). I switched to a font that I know my system has.

'WP Text range' is not valid in the version I am using (perhaps you have an older version. I am using v17.3). My code uses 'WP Create range'.

C_OBJECT(wpDoc;$range)

wpDoc:=WP New

$range:=WP Create range(wpDoc;wk start text;wk end text)

// Style 1

WP SET TEXT($range;"Name: ";wk append)

WP SET ATTRIBUTES($range;wk font;"Book Antiqua Bold")

WP SET ATTRIBUTES($range;wk font size;"12pt")

// Style 2

$range:=WP Create range(wpDoc;7;wk end text)

WP SET TEXT($range;[Companies]Name;wk append)

WP SET ATTRIBUTES($range;wk font;"Book Antiqua")

SET PRINT PREVIEW(True)

WP PRINT(wpDoc)

MacGuido
  • 46
  • 1