Macro command to Import from Style Library…
Macro command to Import from Style Library…
I am new to Nisus Writer Pro Macros (upgraded to version 3.0).
I need open rtf files provided to me and wish to then carry out some formatting to which I wish to apply some styles which I have saved in style library.
Is there a macro command to import a specific style collection from the style library?
Use the menu command method does not appear to work here.
Any help gratefully received.
I need open rtf files provided to me and wish to then carry out some formatting to which I wish to apply some styles which I have saved in style library.
Is there a macro command to import a specific style collection from the style library?
Use the menu command method does not appear to work here.
Any help gratefully received.
Re: Macro command to Import from Style Library…
Hello vw,
there is no specific command to import styles. The macro language has a command to add styles to a document though. You'll need the document object. So it looks like this:
This command can also take an argument to tell it what to do in case of a style conflict. For example "replace" will override the conflict.
So you can get styles from your Style Library by opening the desired Style Library Document, getting the styles you want, and then adding them to the other document. The whole will look something like this:
there is no specific command to import styles. The macro language has a command to add styles to a document though. You'll need the document object. So it looks like this:
Code: Select all
$doc = Document.active
$doc.addStyles $myStyle
So you can get styles from your Style Library by opening the desired Style Library Document, getting the styles you want, and then adding them to the other document. The whole will look something like this:
Code: Select all
$editDoc = Document.active
$styleLibDoc = Document.open "style/library/file/path"
$editDoc.addStyles $styleLibDoc.allStyles, "replace"
$styleLibDoc.close
philip
Re: Macro command to Import from Style Library…
Philip,
Thank you for providing working code. I was able to implement it successfully (although I can understand how individual element work, but how you constructed the macro is beyond me).
My final macro:
Thank you for providing working code. I was able to implement it successfully (although I can understand how individual element work, but how you constructed the macro is beyond me).
My final macro:
Code: Select all
$editDoc = Document.active
$styleLibDoc = Document.open "/Users/victor/Dropbox/Nisus/Nisus Writer Settings/Style Library/LexisNexis Case Formatting.rtf"
$editDoc.addStyles $styleLibDoc.allStyles, "replace"
$styleLibDoc.close
Set Zoom 200
Select All
Format:Paragraph Style:LexisNexis
Format:Text Color:Black
Find and Replace ‘\n\n+’, ‘\n’, ‘Eas’
Save
Sleep 2
Close Window
Re: Macro command to Import from Style Library…
I am trying to use a modified version of the macro code provided by Philip as follows:
When I try to run the macro I am getting the following error:
Screenshots attached. Help with this would be gratefully received.
Code: Select all
$folder = "~/Dropbox/nisus/Nisus Writer Settings/Style Library"
File.requireAccessAtPath($folder)
$editDoc = Document.active
$styleLibDoc = Document.open "~/Dropbox/nisus/Nisus Writer Settings/Style Library/Case report.rtf"
$editDoc.addStyles $styleLibDoc.allStyles, "replace"
$styleLibDoc.close
However, the folder and and file both do exist.There was an error on line 2 in the macro "Macro Find and Replace".
The file does not exist:
~/Dropbox/nisus/Nisus Writer Settings/Style Library
Screenshots attached. Help with this would be gratefully received.
Re: Macro command to Import from Style Library…
In your new macro, you have "~/Dropbox…" where in the earlier versions you had "/Dropbox…" without the "~". Could that be it?I am trying to use a modified version of the macro code provided by Philip as follows:
CODE: SELECT ALL
$folder = "~/Dropbox/nisus/Nisus Writer Settings/Style Library"
File.requireAccessAtPath($folder)
$editDoc = Document.active
$styleLibDoc = Document.open "~/Dropbox/nisus/Nisus Writer Settings/Style Library/Case report.rtf"
$editDoc.addStyles $styleLibDoc.allStyles, "replace"
$styleLibDoc.close
When I try to run the macro I am getting the following error:
There was an error on line 2 in the macro "Macro Find and Replace".
The file does not exist:
~/Dropbox/nisus/Nisus Writer Settings/Style Library
Says Mark a complete non-programmer!

Re: Macro command to Import from Style Library…
Have you tried granting access to the specific file you are going to use (Case Report.rtf)?
The message reads "file doesn't exist" so it seems to expect a file.
In any case the Macro Reference suggests to use the built-in macro "Manage Macro File Access" to grant access once and for all.
For instance you could grant access to your entire Dropbox forlder (or even your Home) using the mentioned macro and then you should be able to run any macros that need to open files in ~/Dropbox whitout using the explicit requireAccessAtPath.
The message reads "file doesn't exist" so it seems to expect a file.
In any case the Macro Reference suggests to use the built-in macro "Manage Macro File Access" to grant access once and for all.
For instance you could grant access to your entire Dropbox forlder (or even your Home) using the mentioned macro and then you should be able to run any macros that need to open files in ~/Dropbox whitout using the explicit requireAccessAtPath.
Re: Macro command to Import from Style Library…
Well the "~" is just an abbreviation for "/Users/victor" and that would seem to be where the "Dropbox" folder is located.
In principle this should work. And personally I just tried a parallel case myself. Did the "required access" command prompt you? Or did that go by without complaint?
But basically Mark is on to something. I would try some simple cases first.
- Write out the full path
- Move/Copy the file to the home folder and try it there
- Try opening other files
- etc.
Also you might try using the following:
Code: Select all
$filePath = Choose File
$styleLibDoc = Document.open $filePath
philip
Re: Macro command to Import from Style Library…
Thank you all for all the replies.
I tried moving the style file to the Documents folder and changed the macro to include what Philip suggested:
and it ran without problem. It also ran without problem when selecting the style file located in the DropBox folder. Again without problem.
I then tried with further version of the macro:
This too ran without problem. I do not know why I had an issue before...
I tried moving the style file to the Documents folder and changed the macro to include what Philip suggested:
Code: Select all
$filePath = Choose File
$styleLibDoc = Document.open $filePath
I then tried with further version of the macro:
Code: Select all
$editDoc = Document.active
$filePath = "~/Dropbox/nisus/Nisus Writer Settings/Style Library/Case report.rtf"
$styleLibDoc = Document.open $filePath
$editDoc.addStyles $styleLibDoc.allStyles, "replace"
$styleLibDoc.close