[Dropped] Macros to hide details in a Writer list

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Locked
SteveH_66
Posts: 38
Joined: Sun Apr 13, 2008 4:42 pm

[Dropped] Macros to hide details in a Writer list

Post by SteveH_66 »

Hello All, I need help with a couple of macros that I had for years, for outlining purposes, and they worked great, in both LO and AOO. I had originally managed to create them myself, by reading this document https://wiki.openoffice.org/wiki/Docume ... al_content and reading some topics/posts in these forums, particularly this one I am sure. And I am sure asking questions and a lot of kind gurus helping me.

What the macros do is create a variable and create a hidden section, so that you can do an ordered or unordered list and use the macros to make hidden sections in the list where you would put longer blocks of text like details and such. (I know that there is a way of outlining using headings and some other techniques and using the Navigator or something, I will probably learn how to do it, in case my macros are not available for some reason, but I want to get these macros fixed, if at all possible, first.) I want to address getting it working in LO in particular, since I used that more often than AOO these days.

So, a few years ago I had a systems crash or corruption, or profile corruption, something happened and I lost all of my macros. My original hideSection macro worked well, but I had to come here for help recreating the macros. So I started this topic [Solved] Method for hiding text with a variable & a function (lets call this one Topic 1) and posted about how I was recreating the macros and asking questions, and getting a lot of great helpful answers from the gurus here on how to fix my macros. Here is my original code for the original macros:

Code for my "HideText" variable :

Code: Select all

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 = "1"
args1(4).Name = "Format"
args1(4).Value = 10000
args1(5).Name = "Separator"
args1(5).Value = " "

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

end sub
Code for my "TextSec" variable for the hidden section:

Code: Select all

sub TextSec
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 = "Section"
args1(1).Name = "RegionCondition"
args1(1).Value = "hide==1"
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
My TextSec macro worked great for making the hidden section, but there was a time consuming problem with it I had always wanted to get fixed. I am a novice at programming in LO & AOO BASIC, and if this BASIC is the same kind of code as in VB or newer versions of the BASIC language, I am a novice at that as well -- I used to code years ago in the original versions of BASIC (and I know how to do some scripting in REXX and a BASIC-like scripting language for a game helper I use), so I always use recorded macros in LO/AOO. So the section number was always fixed in my recorded macro, and I would have to go in and change the title of the sections manually -- since you need your sections numbered and incremented like they are when you insert them manually in LO (I use LO most of the time, so not sure on AOO), because if you are working in a big outline and I do some huge outlines, losing track of what section is what, and what section you are in when you are adding text, is a nightmare. So I wanted to know if you could code a macro in LO & AOO which would automatically increment the section number.

So I posted a topic about this (lets call this one topic 2) here: [Solved] Way to make a macro increment the number in section and FJCC not only told me that it was possible, he very helpfully wrote some code to make a hidden section named "SectionNumber" and I think somehow it found out the last section number in the document or on that level on a list or whatever, and then automatically incremented that number that it appended to the "SectionNumber" name of the next new section! That was awesome, thanks FJCC! Here is FJCC's macro code that he did for me that incremented the section numbers automatically :
FJCC macro code

Code: Select all

sub TextSec

TextSection = ThisComponent.createInstance("com.sun.star.text.TextSection")

SectionCount = ThisComponent.TextSections.Count

TextSection.setName("SectionNumber" & SectionCount + 1
TextSection.isVisible =  FALSE
TextSection.Condition = "Var1==1"

oVC = ThisComponent.CurrentController.ViewCursor

oText = ThisComponent.Text
oText.insertTextContent(oVC.Start, TextSection, FALSE
end sub
So now we are starting to come to where the problem is with my macros. I think the first macro for setting the variable is fine in the newer versions of LO & AOO (hopefully?), and the problem is with the "TextSec" hidden section macro. When I first recorded my "TextSec" macro for the hidden section, and when FJCC first did his macro code for "TextSec" and when I first ran it, even if the variable was set to 1, which was the condition for hiding the section, the section would be visible not hidden, and you would have to toggle the variable once or twice for the section to hide and unhide correctly. After that, it started working correctly. FJCC even commented in his post about that problem, he noticed the same thing. This was back in a LO version before version 7, probably like 4 or 5 I think.

Now, the problem is that when you run the macros in the latest version of LO, and I think in latest version of AOO (but I am not sure about that because I haven't been trying it much in AOO yet), the section is automatically hidden and you can't get it to appear so that you can start writing in the hidden section and then hide it again by toggling the variable.

But I am pretty sure that the macros are still semi functional, because if you go into my code and change "args1(2).Value = true" to false, and if you go into FJCC's code and change "TextSection.isVisible = FALSE", then the section is visible and you can write in it. But then when you toggle the variable to 1, the condition to hide the section, it won't hide.

So hopefully some of you gurus/experienced macro BASIC writers can take a look at this code and help me with this problem, find out where the code is wrong or if the code for hiding the section or for the variable, or both, needs to be tweaked/modded or needs to be rewritten or what.

I read the Survival Guide for posting in the forums, and (hopefully) I did everything I needed to do before opening this new topic. I did a search looking for any topics that might shed light on this problem, but I couldn't find anything. I tried to give enough detail in this post so that the problem is clear for people who are experienced and knowledgeable about BASIC scripting/macros, without getting too long winded. I have been accused here and there of being too long winded in a forum post/topic :oops: :lol:

So thanks in advance for taking the time to look at this post and for any help anyone may be able to give me to get my macros working again. :)
Last edited by MrProgrammer on Wed Feb 11, 2026 11:09 pm, edited 1 time in total.
Reason: Dropped: No attachment provided by SteveH_66 when requested
OS: Windows 10 X86_64 (build 19045); UI render: Skia/Raster; Libre Office: Version: 25.8.4.2 (X86_64)
Build ID: 290daaa01b999472f0c7a3890eb6a550fd74c6df; Apache OpenOffice: AOO4116m3(Build:9816) - Rev. 277251aa7e
Bidouille
Volunteer
Posts: 700
Joined: Mon Nov 19, 2007 10:58 am
Location: France

Re: Macros That worked in older versions of LibreOffice and OpenOffice not working now, think they just need mods or tun

Post by Bidouille »

Can you attach your document with the embedded macros to your post?
User avatar
Villeroy
Volunteer
Posts: 31365
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Macros That worked in older versions of LibreOffice and OpenOffice not working now, think they just need mods or tun

Post by Villeroy »

Works for me.
Attachments
Untitled.odt
(11.57 KiB) Downloaded 249 times
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Locked