selecting a specific style and changing it

Everything related to our flagship word processor.
Post Reply
jrmitchell
Posts: 10
Joined: 2010-10-25 02:41:35

selecting a specific style and changing it

Post by jrmitchell »

I have an rtf document created by a 1989 PC application. It strucutres a report from the application which in my example has 300 entries. When I open the doc in NWP it does not recognise any styles, but say "Heading 2" is 12pt Arial Narrow, Bold Italic Underlined.
The next line is 10pt, same font but not underlined. Etc
I want to process all 300 entries and set a style and modify the source settings.
I have looked at the macro language and I presume the answer is in there.
I use Applescript a lot so can apply that but its not enough. I'm not good at regex which also might do it?
Here is an example of the text:

42 Facility
General attributes
Object kind: Entity
Notes: A complex of assets above and below ground comprising Buildings, Site Infrastructure(Siteworks and Site Services) which represents a single management unit for financial, operational, maintenance or other purposes.

Source: based on NPWC
Name space:
Value/Range:


Can anyone suggest an approach or give me an example I can customise?
TIA
User avatar
martin
Official Nisus Person
Posts: 5228
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: selecting a specific style and changing it

Post by martin »

It's likely some kind of find & replace operations and/or macro commands can do the job for you. But without knowing exactly what you want, it's hard to advise.
I want to process all 300 entries and set a style and modify the source settings.
So you want to apply paragraph styles to all paragraphs that show similar information? For example, you gave:
Object kind: Entity
Formatting the paragraphs that always begin with the same prefix (eg: "Object kind:") is quite easy. Just set the Find mode to PowerFind Pro and use this search pattern:

Code: Select all

Object kind:.+
You can do a Find All, and then just apply the desired paragraph style to all selected paragraphs. Probably you can see how to adapt this method to cover your other prefixed paragraphs.

Your other paragraphs might be more difficult, eg:
42 Facility
Are these paragraphs always numbered? Are there any other numbered paragraphs?
jrmitchell
Posts: 10
Joined: 2010-10-25 02:41:35

Re: selecting a specific style and changing it

Post by jrmitchell »

Michael tks for feedback; I tried the expression "Object kind:.+" in Powerfind (quotes are for here) and it said Found no occurrences!
However a plain Find with the specific text "Object kind:"did find all and I can style them.
So that leaves the Headings eg "42 Facility". They are all unique and number 1 to 311...
I assume a regex 'start at beginning of line, if there is a number, select the line and find all'?

I experimented with the Find tool Constructor button and created this "\<^[[:digit:]]" which allowed me to select all 311 "headings" & set a style

How would you make this more rigorous? And can I save that as a macro. (The manual is daunting - and no examples!)
Groucho
Posts: 497
Joined: 2007-03-03 09:55:06
Location: Europe

Re: selecting a specific style and changing it

Post by Groucho »

jrmitchell said:
… I tried the expression "Object kind:.+" in Powerfind …
Hi, jrmitchell.
Actually you should select PowerFind Pro, not PowerFind, from the pop-up menu. PFP uses a special language called grep to formulate expressions that match specific text. A period (.), for example, finds any character except newline (return). + sign stands for one or more of the previous. So .+, in Martin’s suggestion, means one or more characters (except newlines) until the end of the paragraph (since a newline character is not found by period).
If you want to know more about grep, you can google for it. I don’t have any address offhand, sorry.

Cheers, Henry.
User avatar
martin
Official Nisus Person
Posts: 5228
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: selecting a specific style and changing it

Post by martin »

jrmitchell wrote:Michael tks for feedback; I tried the expression "Object kind:.+" in Powerfind (quotes are for here) and it said Found no occurrences!
As Henry mentioned, you'll need PowerFind Pro to use regular expressions directly. The normal PowerFind just allows for the use of our special PowerFind "bubbles" which help those unfamiliar with regular expressions build up searches, which it sounds like you discovered.
However a plain Find with the specific text "Object kind:"did find all and I can style them.
Ah yes, I forgot about that. Paragraph Styles always apply to the entire paragraph, so it doesn't really matter if you select the whole paragraph or not before you apply the paragraph style.
So that leaves the Headings eg "42 Facility". They are all unique and number 1 to 311...
I assume a regex 'start at beginning of line, if there is a number, select the line and find all'?

I experimented with the Find tool Constructor button and created this "\<^[[:digit:]]" which allowed me to select all 311 "headings" & set a style
Great, I'm glad your experiments paid off!
How would you make this more rigorous?
In what way did you want to make this more rigorous? It all comes down to the document you have, and any false matches you need to avoid. For this particular type of paragraph, it appears that your digits are always followed by a tab? If so, you might consider either of these:

Code: Select all

\<^[[:digit:]]+\t
^\d+\t
Those two expressions both match the same thing: any number of digits at the start of a paragraph, followed by a tab. The second expression just uses the shorthand "\d". And you'll note that using both start of word "\<" and start of paragraph "^" is redundant.
And can I save that as a macro. (The manual is daunting - and no examples!)
Yes indeed. Once you have a Find expression entered and working, just use the "Macroize" command from the little gear icon menu. That will let you save (or copy) the Find expression in its macro form. Since you want to also apply styles as part of your macro, you'll want to use the name of your style after the find expression in your macro, eg:

Code: Select all

Find All 'Object Kind', 'a'
Heading 2
jrmitchell
Posts: 10
Joined: 2010-10-25 02:41:35

Re: selecting a specific style and changing it

Post by jrmitchell »

The solution gets better & more understood. Tks for the support
Post Reply