[Solved] Change selected style from visible to invisible

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
susancragin
Posts: 7
Joined: Wed Jul 08, 2009 7:49 pm

[Solved] Change selected style from visible to invisible

Post by susancragin »

Hello.
I currently make an editable "outline" view in my Writer documents simply by changing the properties of Text Body from visible to invisible.
I change back and forth a lot, but was hoping to record a macro that would change it in a keyclick.
I've tried, but I'm obviously above my head.

I've tried:
Record Macro
M-S style (Alt-S)
E edit style

That works. But from there I can't get it to check the FontEffects and then Hidden options, and close the dialogue box.

I also need one to restore properties from hidden to unhidden.
Last edited by Hagar Delest on Wed Jul 08, 2015 10:36 pm, edited 1 time in total.
Reason: tagged [Solved].
OOo 3.1.X on Ubuntu 8.x
FJCC
Moderator
Posts: 9280
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Macro to change selected style from visible to invisible

Post by FJCC »

This macro toggles the visibility of the Text body paragraph style.

Code: Select all

Sub ToggleTextBody
oStyleFam = ThisComponent.StyleFamilies
ParaStyles =oStyleFam.getByName("ParagraphStyles")
TextBod = ParaStyles.getByName("Text body")
If TextBod.CharHidden = True Then
	TextBod.CharHidden = False
Else
	TextBod.CharHidden = True
End If
End Sub
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
susancragin
Posts: 7
Joined: Wed Jul 08, 2009 7:49 pm

Re: Macro to change selected style from visible to invisible

Post by susancragin »

This works. Thank you very much!
I now have my own intrinsic outline function. :bravo:
Now will just bind it to a keystroke and I'm set!
OOo 3.1.X on Ubuntu 8.x
susancragin
Posts: 7
Joined: Wed Jul 08, 2009 7:49 pm

Re: [Solved] Change selected style from visible to invisible

Post by susancragin »

Hey, what's the equivalent to TextBod for e.g. "Heading 1" and so on?
This macro has changed my life. I'm going to write 6 more of them so I have Show/Hide at all heading levels I use.
OOo 3.1.X on Ubuntu 8.x
User avatar
RoryOF
Moderator
Posts: 34618
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: [Solved] Change selected style from visible to invisible

Post by RoryOF »

I put entire chapters each in their own OpenOffice Section. When a Chapter is finalised, I can /Edit /Section and mark the Section as Hidden.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
susancragin
Posts: 7
Joined: Wed Jul 08, 2009 7:49 pm

Re: [Solved] Change selected style from visible to invisible

Post by susancragin »

Thanks. That's good to know, and I'll take advantage of that to hide text.
But I would still like to develop a macro to hide a couple of heading styles on command.
For instance, each chapter has a title (heading 1). And underneath it (heading 2) is a synopsis. And heading 3 describes what plot/character advances have been made.
OOo 3.1.X on Ubuntu 8.x
User avatar
RoryOF
Moderator
Posts: 34618
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: [Solved] Change selected style from visible to invisible

Post by RoryOF »

Read
https://wiki.openoffice.org/w/images/e/ ... Fields.odt
for information on working with Fields, It is possible to set some global variables to cause some inserted fields to be displayed or suppressed.

I use four Heading styles in my writings: Heading 1 is Chapter number, Heading 2 is Chapter title. Heading 3 is subsection title and Heading 4 is time/date (for steering the course of the narrative). Heading 3 and 4 are displayed or not depending on the setting of a global variable at top of the file - they will ultimately not be displayed in the final print, but are invaluable for steering the course of the narrative, particularly if subsections are relocated. It should be relatively easy to tie their display to a key rather than an intext variable. I'm at the end of my day, so will leave instructions on how I have done this until tomorrow lest I get confused and write in error.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
User avatar
RoryOF
Moderator
Posts: 34618
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: [Solved] Change selected style from visible to invisible

Post by RoryOF »

At the top of my docment(s) I have two inserted fields and two prompt lines:

Enter 1 to display Subheader
followed by
Field defined as follows Type: Set variable, Selection :Subheader, Format : Text, Value : 1

Enter 1 to display TimeFlow
followed by
Field defined as follows Type: Set variable, Selection: TimeFlow, Format: General, Value: 1

Note that these two entries differ: the first is using a variable as text, the second as a number. The only reason for this is that I was experimenting to see if there was any difference in the examples, between use of text values and numeric values; I never bothered to unify them.


In my document when I need Heading 3, I insert a field
Type: Conditional text
Condition: Subheader EQ "1"
Then: Text for my Heading 3 entry
Else: text I want if this detail is omitted

Note that the 1 must be in quotes, as this is a text entry

For the Heading 4 entry I insert a field
Type: Conditional text
Condition: TimeFlow EQ 1
Then: text for my Heading 4 entry - usually a date/time in my case, for narration steering purposes
Else: Entry I want if this detail is omitted

Note that the 1 here is not quoted as it is a numeric value

These fields are entered for my first chapter in my standard book template, then I Copy/Paste them and edit their values for other chapters and subheadings.

By changing the values for either of the prompt lines at top of the document I can suppress the displays of Heading 3 and/or Heading 4 entries.

Clunky, maybe, but it suits what I am doing.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
User avatar
RoryOF
Moderator
Posts: 34618
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: [Solved] Change selected style from visible to invisible

Post by RoryOF »

susancragin wrote:Thanks. That's good to know, and I'll take advantage of that to hide text.
But I would still like to develop a macro to hide a couple of heading styles on command.
For instance, each chapter has a title (heading 1). And underneath it (heading 2) is a synopsis. And heading 3 describes what plot/character advances have been made.
In the light of your posting quoted above, you should look at two extensions/ancilliary programs
oStorybook
and
Organon

both designed as writing assistants.

There is also PlumeCreator but that is currently undergoing very heavy revision.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
susancragin
Posts: 7
Joined: Wed Jul 08, 2009 7:49 pm

Re: [Solved] Change selected style from visible to invisible

Post by susancragin »

Any idea why this macro doesn't work to toggle Heading 2 from visible to invisible? It gets stuck on CharHidden.

Sub ToggleHeading2
oStyleFam = ThisComponent.StyleFamilies
ParaStyles =oStyleFam.getByName("ParagraphStyles")
Heading2 = ParaStyles.getByName("Heading 2")
If Heading2.CharHidden = True Then
Heading2.CharHidden = False
Else
Heading2.CharHidden = True
End If
End Sub
OOo 3.1.X on Ubuntu 8.x
User avatar
RoryOF
Moderator
Posts: 34618
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: [Solved] Change selected style from visible to invisible

Post by RoryOF »

Is FJCC's macro (as written) working?
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
susancragin
Posts: 7
Joined: Wed Jul 08, 2009 7:49 pm

Re: [Solved] Change selected style from visible to invisible

Post by susancragin »

I have gotten help from another source, and have gotten the macro to work, as written.
How I did it was simply to delete all the modules and re-enter them.
(I probably had had a rogue character in there somewhere.)
FJCC's macro always worked.
Thank you for your help.
OOo 3.1.X on Ubuntu 8.x
Post Reply