paragraph style as a condition

Get help using and writing Nisus Writer Pro macros.
Post Reply
js
Posts: 229
Joined: 2007-04-12 14:59:36

paragraph style as a condition

Post by js » 2015-04-05 15:18:20

In a document myfile I would like to check the paragraph style of the selection. This works fine like so:

Code: Select all

Document.open  "~/Documents/myfile"
$doc = Document.active
$sel = $doc.textSelection
$parStyle = $sel.paragraphStyle
prompt $parStyle
Now let‘s say the prompt says
Paragraph Style "Normal"
How must I formulate a condition: If Paragraph Style is "Normal" then do suchandsuch?

Code: Select all

If $parStyle = "Normal"
do such and such
end
does not work.

capvideo
Posts: 20
Joined: 2008-03-16 16:41:16
Contact:

Re: paragraph style as a condition

Post by capvideo » 2015-04-05 20:23:12

Judging from my own code, what you want is $parStyle.name. TextSelection.paragraphStyle returns a style object; the property “name” on that object contains the style’s name as text. Getting the style’s name as text allows you to compare the style name to some text of your own.

Code: Select all

$parName = $parStyle.name
If $parName == "Normal"
    do such and such
End
You can see this in the Nisus Macro Reference (under the Help menu) in the DOCUMENT OBJECTS section, Style Object, Style Object Properties. There are quite a few useful properties there for you to use in your macros.

js
Posts: 229
Joined: 2007-04-12 14:59:36

Re: paragraph style as a condition

Post by js » 2015-04-05 23:36:39

Perfect. Thank you.

Post Reply