Styles 'Document' not a regular object? Error unknown macro command.
Posted: 2019-11-16 23:47:07
Hi,
I have written a macro to style text based on markup, but Nisus Writer Pro 3.0.4 reports a difficult to comprehend error:
Unknown macro command:
Document.styleWithName "Emphatic"
From the Macro Language reference:
Style Object
A Style object represents a single user-defined style which collects together a group of text attributes in a particular document. Style objects can be retrieved using:
Style.editingStyles
Document.allStyles
Document.styleWithName <———
Selection.characterStyle
[…]
.styleWithName name v1.2
Returns the Style object with the given name, or the undefined value if no such style exists.
The document is a standard Nisus Writer Pro document with the emphasis and bold styles added to the document’s collection of Character styles. Is perhaps ‘Document’ not regular object or am I missing something? 'Read Document.styleWithName' results in the same error message.
I would be grateful for some assistance.
###### the Macro ########
$aDoc=Document.Active
$range = Range.new(0,$aDoc.text.length)
$selection = TextSelection.new($aDoc.text, $range)
$aDoc.setSelection($selection)
$data = $aDoc.selection.substring
$styles = Hash.new
$styles["Emphatic"] = Document.styleWithName "Emphatic"
$styles["Strong"] = Document.styleWithName "Strong"
Begin Perl
$data =~ s/(@@@)(emph|bld)\((.+?)\)((?:emph|bld)_end)/$1${2}&&&&&&&&&&&&&&&${3}${4}&&&&&&&&&&&&&&&/gs;
End
$aDoc.text.replaceInRange $range, $data
$aDoc.find("@@@emph&&&&&&&&&&&&&&&.+?emph_end&&&&&&&&&&&&&&&", "E")
$styles["Emphatic"].apply
$aDoc.findAndReplace("@@@emph&&&&&&&&&&&&&&&(.+?)emph_end&&&&&&&&&&&&&&&", “\\1”, "aE")
$aDoc.find(@@@bld&&&&&&&&&&&&&&&.+?bld_end&&&&&&&&&&&&&&&, 'E')
$styles["Strong"].apply
$aDoc.findAndReplace("@@@bld&&&&&&&&&&&&&&&(.+?)bld_end&&&&&&&&&&&&&&&", “\\1”, "aE")
Regards,
Martin
I have written a macro to style text based on markup, but Nisus Writer Pro 3.0.4 reports a difficult to comprehend error:
Unknown macro command:
Document.styleWithName "Emphatic"
From the Macro Language reference:
Style Object
A Style object represents a single user-defined style which collects together a group of text attributes in a particular document. Style objects can be retrieved using:
Style.editingStyles
Document.allStyles
Document.styleWithName <———
Selection.characterStyle
[…]
.styleWithName name v1.2
Returns the Style object with the given name, or the undefined value if no such style exists.
The document is a standard Nisus Writer Pro document with the emphasis and bold styles added to the document’s collection of Character styles. Is perhaps ‘Document’ not regular object or am I missing something? 'Read Document.styleWithName' results in the same error message.
I would be grateful for some assistance.
###### the Macro ########
$aDoc=Document.Active
$range = Range.new(0,$aDoc.text.length)
$selection = TextSelection.new($aDoc.text, $range)
$aDoc.setSelection($selection)
$data = $aDoc.selection.substring
$styles = Hash.new
$styles["Emphatic"] = Document.styleWithName "Emphatic"
$styles["Strong"] = Document.styleWithName "Strong"
Begin Perl
$data =~ s/(@@@)(emph|bld)\((.+?)\)((?:emph|bld)_end)/$1${2}&&&&&&&&&&&&&&&${3}${4}&&&&&&&&&&&&&&&/gs;
End
$aDoc.text.replaceInRange $range, $data
$aDoc.find("@@@emph&&&&&&&&&&&&&&&.+?emph_end&&&&&&&&&&&&&&&", "E")
$styles["Emphatic"].apply
$aDoc.findAndReplace("@@@emph&&&&&&&&&&&&&&&(.+?)emph_end&&&&&&&&&&&&&&&", “\\1”, "aE")
$aDoc.find(@@@bld&&&&&&&&&&&&&&&.+?bld_end&&&&&&&&&&&&&&&, 'E')
$styles["Strong"].apply
$aDoc.findAndReplace("@@@bld&&&&&&&&&&&&&&&(.+?)bld_end&&&&&&&&&&&&&&&", “\\1”, "aE")
Regards,
Martin