I had a way to hide/unhide text forgot how I set it up though

I had a method of hiding/unhiding text. Don’t remember if I used 2 functions, 2 variables or 1 function and one variable. Then, I assigned a macro to each. I used it mostly for outlining with hidden text, since (as far as I know there is no easy way to do that in Writer, they been talking it to death in LibreOffice and OpenOffice and the argument goes back and forth, for years with different bug or issue reports - don’t remember which, not really relevant here for this question anyway).

I mostly used it in numbered lists or whatever. I would hit my macro key at the end of the list entry, and it would place a field. The field would have a 9 or a 0 in a box (9 to hide, 0 [or I think any other number to unhide]) and it would place a ‘field box’ or whatever you call it in that spot, with a 9 in the box and you could change it to 0 or whatever if you wanted to.

Then, I would select the text in the unnumbered list entry below it, and select all the way up until it was selected up to behind that ‘field box’ or whatever that was showing the 9 (or 0) in it, and hit my other macro. If the field box had the 9 in it, that text was automatically hidden, if it was zero then it wasn’t hidden. But as soon as I double-clicked the ‘field box’ and changed it from 9 to 0, voila - the text was unhidden. If I double-clicked the ‘field box’ again and entered 0, then voila, the text was unhidden.

Anyway, I don’t remember how I set things up to get these 2 functions, variables or function & variable set-up so that they worked in this manner. I set it up years ago, and I am sure I had help from someone on how to do this. My system recently crashed, so I am having to set everything up again, and since I didn’t set it up myself and someone gave me help on how to do the arrangement of this method I can’t remember how to do the setup. Whether a function or variable, I think I remember part of the Condition box (I think it was) having ==9 in it. I don’t remember if there was anything in front of the ==9 or not though, and as I said it was set up so long ago there is no way I can remember how I set it up. Now that I think about it, I think the condition or whatever was hide==9 maybe?

So, I hope someone that reads this will have an idea of what I am talking about, and how to make that work. I am sure the question could have been clearer, but I just can’t think of how to have made it clearer. I am tired, so my apologies, and I hope someone can figure out what I am talking about and how I would set it up. Thanks for any assistance anyone can give me on getting this method back.

Edit :
Here is the text from the BASIC macro file. Maybe someone could look at this and figure out how I did the persistent variable and persistent hidden section? Then I could do that and assign a macro key to them pretty easily :

REM  *****  BASIC  *****

Sub Main

End Sub

sub HideText
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dim args1(5) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Type"
args1(0).Value = 8
args1(1).Name = "SubType"
args1(1).Value = 2
args1(2).Name = "Name"
args1(2).Value = "Hide"
args1(3).Name = "Content"
args1(3).Value = "9"
args1(4).Name = "Format"
args1(4).Value = 10000
args1(5).Name = "Separator"
args1(5).Value = " "

dispatcher.executeDispatch(document, ".uno:InsertField", "", 0, args1())

end sub

sub HideSection
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dim args1(6) as new com.sun.star.beans.PropertyValue
args1(0).Name = "RegionName"
args1(0).Value = "Section4"
args1(1).Name = "RegionCondition"
args1(1).Value = "Hide==9"
args1(2).Name = "RegionHidden"
args1(2).Value = true
args1(3).Name = "RegionProtect"
args1(3).Value = false
args1(4).Name = "LinkName"
args1(4).Value = ""
args1(5).Name = "FilterName"
args1(5).Value = ""
args1(6).Name = "SubRegion"
args1(6).Value = ""

dispatcher.executeDispatch(document, ".uno:InsertSection", "", 0, args1())

end sub

Hope this might be useful for someone to hep me figure out how I did the persistent variable and section. From there, assigning it as a macro (if I need to) and then assigning that to a keyboard shortcut should be pretty straightforward. Thanks

Edit2 : I have been trying to use the techniques described by ajlittoz, in his answer and comments. So far I am having no luck getting it to work, I guess I am just missing something somewhere. I don’t know if this has any bearing on the question, but I am using a live disc so I cannot update LO, and the version it is running is 4.2.3.3 – maybe that has something to do with why I can’t get it to work using ajlittoz methods?

Sections? They can be hidden. Not at pc but I think it is Insert > section

Yes sections can also be hidden, optionally with an expression. However, see my answer about the control action.

Yes, I think now that I did do it as hidden sections. But the method worked out so that I didn’t have to do it for each section, I could just select text, make it a section and type in my shortcut key and it hid the section. Did not have to do it for each section

From what I understand in the macro code, you have a control variable named Hide which you insert at the current position with your macro.

The text to hide/unhide is nested inside a section (this is one way to enclose text in a section: you select it and Insert>Section) with a conditional expression.

IMHO, you probably mess up the XML structure if you repeatedly activate your HideSection macro: you create a new section around an existing section over and over. Writer can handle this up to some point.

Don’t use sections unless you really want to have a different number of columns than in the current page style. In addition, I’d rather recommend to avoid macro use for this kind of formatting.

Even if you find it tedious, field insertion at start of paragraph is much safer and reliable. If you want, to ease your work, use a macro to make this insertion. Don’t do it to change the variable value: your macro inserts a variable whenever you fire it. Then you have …

(continued) … you have several instances of setting your variable in the document. The control expression for the section used the latest known value. The net result is some sections which should be hidden will in fact show because their closest variable field is different from others.

4.2.3.3 is very old indeed.

Just to check, attach a 1-page sample file with your implementation of my technique.I’ll see if you made a mistake.

To be honest, I was never able to fully understand your method enough so that I could get it to work, so I never saved a page.

To be honest, I was never able to fully understand your method enough so that I could get it to work, so I never saved a page.

OK, I attach here a demo file. Study it.

AskLO-HiddenDemo.odt

I don’t use macros for selective hidden/visible text. But you can extend my procedure to ease configuring the control variables.

I define control variables in the document, preferably near the beginning as a series of paragraphs: a short comment and an Insert>Field>More Fields, Variables tab, Type Set variable. I give it a name and a value.

At the start of every paragraph I want to selectively hide or unhide, I Insert>Field>More Fields, Functions tab, Type Hidden Paragraph. In the Condition box, I enter an expression involving my variables. This expression can be as complex as you want to combine the various variables if needed (e.g. if variable ‘a’ is set, it is necessary that variable ‘b’ is also set to show the paragraph).

CAVEAT! Remember that the paragraph is hidden is the expression is true (where we instinctively expect the paragraph to be shown when the expression is true).

It may seem painful to add a field in every paragraph, but this allows you to have a fine-grained control on your document. Also there is no risk to forget a paragraph or so because you have no mouse selection to do.

To change a variable value, just double click on the variable field.

You can add borders, colour, … to the controlling paragraphs.

To show the community your question has been answered, click the ✓ next to the correct answer, and “upvote” by clicking on the ^ arrow of any helpful answers. These are the mechanisms for communicating the quality of the Q&A on this site. Thanks!

In case you need clarification, edit your question (not an answer which is reserved for solutions) or comment the relevant answer.

That is very close to what I am talking about. But somehow I had it set up so that the variable was always persistent, and the hidden section was always persistent. So then all I had to do was hit my shortcut for hide at the end of the list line, then select the text in the unnumbered entry and hit the other shortcut key, and the section could be hidden or unhidden just by changing that variable number.

Can you think of how I might have done that? Thanks

the variable was always persistent

What do you mean? Once defined, a variable persists in the document and you need a voluntary action to change its value.

You can copy and paste fields. So, if you have only one variable, the expression is always the same and a simple paste “configures” the paragraph or sequence of characters.

I’ve never used macros but I imagine you can change the value of a variable with a macro (and assign a shortcut key to conveniently fire the macro).

OK, think I finally got it working, with some help from another forum. And by reading/consulting-back-to this Conditional Text - Libre Office Help LO Help document on conditional text. Here is the process I am using.

  1. Create a Set variable (Insert > Fields > More Fields), make sure you click on General in Format box, I put ‘hide’ in name box, and 1 in Value box. I do all of this as I am recording it as a macro - this is very important! I then click stop recording, assign it the name ‘hideText’ in the macros dialog, and click OK.
  2. Now, I create a hidden section (Insert > Section) and make sure in the Hide area the checkbox next to Hide is checked, and put “hide==1” (no quotes!) in the With Condition box - again, doing all of this as I am recording it as a macro. I click Insert button, section is made and the dialog box closes. I click on “stop recording” in the little popup window, and then I give that macro the name ‘hiddenSection’ (you can call it what you want).
  3. Now, before I try to use them, I like to assign them a keyboard shortcut. How to do that is for another post if anyone needs help on that. I assign Alt+H for ‘hideText’ macro and Alt+Shift+H for ‘hiddenSection’ macro.

Now, you are done doing your macros and are almost ready to start using them. As Ajlittoz said in an earlier post, this would always assign the section the name ‘Section 1’ – as that was the first number to come up when making a section (if it is the first section you make in the document, it will be another number if you already have other sections in it) manually or whatever. What I do is go into the organize macro dialog, and single-click on my ‘hiddenSection’ macro and change “Section1” to “Section” or “Section0” – because I don’t think those would normally be assigned by Writer itself.

And he thought it would mess up XML structure somehow. Regardless of the XML thing, you don’t want a whole list (with sublists in a long document?) of “Section” sections. You can edit them, and change that “Section” to “Section 2” or “Section 4” or whatever the right number is in the list. I do it as soon as the macro stops running, before I even deselect the text in the section – I click on Format > Section and then in the Section Dialog box that pops up, the Section you just did is usually highlighted in the list (but I click on it if not) and I just add the right number to the end of Section in the box up at the top to keep the list in order … and keep from having a whole list of entries in there just named Section. And, if Ajlittoz is right, doing this will keep from messing up the XML whatever he was talking about in his post.

The process is just about perfect now. It would be, if there was a way to change the ‘hiddenSection’ macro so that it automatically incremented the number in the ‘Section name’. It does it in Writer when you are doing sections manually, so it is in the Writer code. Is there a function or something in the LO Basic macro language that accesses this? Anyone know?

Well anyway, that’s how the process seems to be set up. It has been working pretty good for the past couple of days, like it had in the past. So, thanks for reading the question/topic and any help anyone has given.

P.S. : If anyone knows how to make the number in the ‘Section name’ increment in the macro like it does in the creation dialog itself, I would really love to know how to do it. It would make the process really fast and easy!