CannedMan wrote:
@Villeroy: I take it that the lines
is where one would insert the style name one has for the small caps / petits?
Yes, you should add your own routines (and possibly remove mine). The code is just is a plain text file in your profile folder. Writer can handle that, Notepad almost as well if you obey one thing: Python is the only(?) programming language where white space has a meaning. Every indentation level is 4 white spaces wide.
If you write your custom routine, copy one of mine, change the name after "def", specify your 3 arguments.
The attached Writer document installs my code to [My Macros] > pyWriter > FirstWordCharStyle.py
Use Ctrl+F10 to watch the indentations of 4,8,12 white spaces and push the button to install the code. An embedded Basic macro will store the plain document text to the right location where it will be detected as a Python macro. I use to store my Python macros in folders named pyWriter, pyCalc etc. in order to distinguish them from the Basic macros which can be edited in the Basic GUI only.
Python code is editable in any application that can handle text, preferably some kind of code editor but Writer or Windows Notepad will do.
Code: Select all
def First_3_Words_Emphasis_Conditional(*args):
CharStyleName = 'Strong Emphasis'
WordCount = 3
ParaStyeNames = ('Standard', 'Text body indent',)
FormatParagraphsFirstWord(CharStyleName, WordCount, ParaStyeNames)
First_3_Words_Emphasis_Conditional can be called directly from a dialog or button without any arguments. (*args) is a blank placeholder to take and ignore any passed arguments. The office sometimes passes over some info about the calling button which is not important here but raises an error when not handled this way.
This routine calls FormatParagraphsFirstWord which is the working routine actually performing the job.
First argument to FormatParagraphsFirstWord is the character style name to be applied.
Second argument (3) is the count of words.
Third argument is an optional list of paragraph style names.
The working routine ignores any paragraph styles that are not in this list. If you leave out that list, all paragraphs are treated equally. This way you create one working routine which can be called easily by very simple routines. In the calling routines you declare the gory details as argument and pass them over to the working routine.
The working routine FormatParagraphsFirstWord appears together with the calling routines in the macro dialogs although it can not be called directly from there. Nothing bad will happen if you try, just an error message.