Styles in new file created by macro

Get help using and writing Nisus Writer Pro macros.
Post Reply
User avatar
phspaelti
Posts: 1349
Joined: 2007-02-07 00:58:12
Location: Japan

Styles in new file created by macro

Post by phspaelti »

In a macro I am creating a new file using the following code

Code: Select all

Document.newWithText $newDoc
When the macro finishes it gives me an untitled file. The drawer shows a complete set of styles, which are clearly the styles from my "Nisus New File". But when I switch to the style sheet, there are only 3 styles (Header, Footer, Normal); no character styles, no list styles, no note styles. Obviously this is some kind of bug. There are two questions here.
  1. Where do these default styles come from?
  2. Why the mismatch between the drawer and the style sheet?
Philip
philip
Kino
Posts: 400
Joined: 2008-05-17 04:02:32

Re: Styles in new file created by macro

Post by Kino »

But what is your $newDoc? If any portion of that text object does not have a defined style, what occurs in opening a plain text file or an rtf file without defined styles (e.g. those created by TextEdit) occurs: the text content formatted according to your settings in Preferences - New File - Format, with Normal style imported from your default dot file without being applied.

If the text object has originated from an existing NWP document (and has been treated as attributed text), the defined styles —at least all styles actually used — will be preserved in a new document thus created.

I don’t seem to have the drawer oddity but, concerning something else and at times, I have noticed NWP’s slowness in refreshing information.
User avatar
martin
Official Nisus Person
Posts: 5230
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Styles in new file created by macro

Post by martin »

phspaelti wrote:1. Where do these default styles come from?
In the absence of normal/header/footer styles in the provided text, a new document will automatically generate those styles (by copying them from your new file template).
Why the mismatch between the drawer and the style sheet?
This would be an updating bug peculiar to the macro command. I'll file it for fixing, thanks.
User avatar
phspaelti
Posts: 1349
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Styles in new file created by macro

Post by phspaelti »

Kino wrote:But what is your $newDoc?
Well you can try it like this:

Code: Select all

Document.newWithText “Hello World”
So Nisus will create a new document containing the the text "Hello World". The style sheet for that document (for me) looks like this with the drawer open. As you can see on the left there are 3 styles, and on the right a couple more. The list on the right seems to be the style sheet from my Nisus New File.
Screen_capture_new_doc_style_bug.jpg
Screen_capture_new_doc_style_bug.jpg (77.75 KiB) Viewed 9995 times
philip
Kino
Posts: 400
Joined: 2008-05-17 04:02:32

Re: Styles in new file created by macro

Post by Kino »

So that is a “Run Selection as Macro” issue. It does not always work in the same way as a macro run from Macro menu.
User avatar
phspaelti
Posts: 1349
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Styles in new file created by macro

Post by phspaelti »

I see what you are saying. But it happens in saved macros too, if the text used to create the new document comes from a string as opposed to text. So the following macro shows the problem if even it is saved and run from the menu:

Code: Select all

$doc = Document.active
$sel = $doc.selectedSubstrings
Document.newWithText $sel[0]
philip
Post Reply