Turning Section Boundaries on/off with macro

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Turning Section Boundaries on/off with macro

Post by JeJe »

I want to set Tools/ Options/OpenOffice/Appearance/Section Boundaries with a macro

I've got as far as trying to adapt the macro for setting the MacroSecurityLevel here...

viewtopic.php?f=25&t=45177

but I can't find the strings to put for how to set the Appearance/Section Boundaries to on or off...
or even to access the Appearance settings. Anyone know this?

Code: Select all


Sub ChangeMacroSecurity
   Dim sNodePath As String
   Dim oCP, oCUA
   
'   sNodePath = "/org.openoffice.Office.Common/Security/Scripting"
      sNodePath = "/org.openoffice.Office.Common.Appearance" '???????????????' this doesn't work.

     Dim aProps(0) As New com.sun.star.beans.PropertyValue

   oCP = CreateUnoService("com.sun.star.configuration.ConfigurationProvider" )
   aProps(0).Name = "nodepath"
   aProps(0).Value = sNodePath
   oCUA = oCP.createInstanceWithArguments("com.sun.star.configuration.ConfigurationUpdateAccess", aProps )
   
'   oCUA.MacroSecurityLevel = 0
  oCUA.SectionBoundaries '???????????????
   oCUA.commitChanges()
End Sub

Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
Lupp
Volunteer
Posts: 3542
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: Turning Section Boundaries on/off with macro

Post by Lupp »

I virtually never use sections and I rarely tamper with the hidden parts of the configuration (in LibreOffice accessible as 'Expert Configuration'). It was, however fun to first stabb in the dark a bit and finally find out by "Thinking and Trial" how to access and to change the respective configuration property. Your slightly reworked code:

Code: Select all

Sub printAndToggleWriterSectionBoundaryVisibility()
    Dim sNodePath As String
    Dim oCP, oCUA
    sNodePath = "/org.openoffice.Office.UI/ColorScheme/ColorSchemes"
    Dim aProps(0) As New com.sun.star.beans.PropertyValue
    oCP = CreateUnoService("com.sun.star.configuration.ConfigurationProvider" )
    aProps(0).Name = "nodepath"
    aProps(0).Value = sNodePath
    oCUA = oCP.createInstanceWithArguments("com.sun.star.configuration.ConfigurationUpdateAccess", aProps )
Print oCUA.GetByName("OpenOffice").WriterSectionBoundaries.IsVisible
    oCUA.GetByName("OpenOffice").WriterSectionBoundaries.IsVisible = _
            NOT oCUA.GetByName("OpenOffice").WriterSectionBoundaries.IsVisible
Print oCUA.GetByName("OpenOffice").WriterSectionBoundaries.IsVisible
    oCUA.commitChanges()
End Sub
Final version:

Code: Select all

Option Explicit

Sub setWriterSectionBoundaryVisibility(Optional pNext As String)
    If IsMissing(pNext) Then pNext = "toggle"
    Dim nodePath As String, newState As Boolean
    Dim confProv As Object, updateAccess As Object
    nodePath = "/org.openoffice.Office.UI/ColorScheme/ColorSchemes"
    Dim props(0 To 0) As New com.sun.star.beans.PropertyValue
    confProv = CreateUnoService("com.sun.star.configuration.ConfigurationProvider" )
    props(0).Name = "nodepath"
    props(0).Value = nodePath
    updateAccess = confProv.createInstanceWithArguments("com.sun.star.configuration.ConfigurationUpdateAccess", props )
    Select Case pNext
        Case "on"
            newState = True
        Case "off"
            newState = False
        Case "toggle"
            newState = NOT updateAccess.GetByName("OpenOffice").WriterSectionBoundaries.IsVisible
        Case Else
            Exit Sub
    End Select
    updateAccess.GetByName("OpenOffice").WriterSectionBoundaries.IsVisible = newState
    updateAccess.commitChanges()
End Sub
Of course this only is "final" concerning the ColorScheme "OpenOffice". If different ColorScheme are to handle ("LibreOffice" e.g.) you may introduce a second parameter pColorSchemeName and use updateAccess.HasByName(pColorSchemeName) or similar. The updateAccess object also has an array-porperty ElementNames.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: Turning Section Boundaries on/off with macro

Post by JeJe »

Brilliant thanks!

Now I know its WriterSectionBoundaries I see someone's asked for it before, in a French thread. I should have looked at the file the settings are all in - but I spent ages on it without thinking of that.

I haven't used sections before either - but I'm writing a screenwriting extension - and the best way to do it looks to be to put each scene in a separate section. Then scenes can be individually protected, hidden, color coded with the background color etc.

Great thanks!
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
Lupp
Volunteer
Posts: 3542
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: Turning Section Boundaries on/off with macro

Post by Lupp »

I just tried with LibO. My findings:
-0- The "org.OpenOffice" part in the node path is unchanged.
-1- The (default?) ColorScheme is named "LibreOffice" there (as should be expected).
-2- The property .WriterSectionBoundaries.IsVisible does still exist.
-3- This property can be edited by the Sub if the name of the ColorScheme is adapted.
-4- There is no longer offered a way to edit it via the Options dialogues.
-5- The property is no longer evaluated. SectionBoundaries are always visible.
-6- Relying on this property is not compliant with interoperability between AOO and LibO.

I did not find an explicit statement about this in the LibreOffice release notes.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: Turning Section Boundaries on/off with macro

Post by JeJe »

Its there in the Options Dialogue/Application colors/Text document
Playing - the problem seems to be visibility depends on text boundaries being visible or not, not on the setting for the section boundary
Setting the color to white has the effect of hiding the border so its possible to have text boundaries visible but secion boundaries looking like they aren't because they're white. But it doesn't look possible to have text boundaries not visible but section boundaries visible.


I found the nodepaths here:
https://github.com/rhoconlinux/Libreoff ... ations.xcu

oor:path="/org.openoffice.Office.UI/ColorScheme/ColorSchemes/org.openoffice.Office.UI:ColorScheme['LibreOffice']/WriterSectionBoundaries"><prop oor:name="Color" oor:op="fuse"><value xsi:nil="true"/></prop></item>
<item oor:path="/org.openoffice.Office.UI/ColorScheme/ColorSchemes/org.openoffice.Office.UI:ColorScheme['LibreOffice']/WriterSectionBoundaries"><prop oor:name="IsVisible" oor:op="fuse"><value>true</value></prop></item>

Code: Select all




Sub setWriterSectionBoundaryVisibility()

    Dim nodePath As String, newState As Boolean
    Dim confProv As Object, updateAccess As Object
'    nodePath = "/org.openoffice.Office.UI/ColorScheme/ColorSchemes"
nodePath = "/org.openoffice.Office.UI/ColorScheme/ColorSchemes/org.openoffice.Office.UI:ColorScheme['LibreOffice']" '/WriterSectionBoundaries"
    
    Dim props(0 To 0) As New com.sun.star.beans.PropertyValue
    confProv = CreateUnoService("com.sun.star.configuration.ConfigurationProvider" )
    props(0).Name = "nodepath"
    props(0).Value = nodePath
    updateAccess = confProv.createInstanceWithArguments("com.sun.star.configuration.ConfigurationUpdateAccess", props )

  updateAccess.WriterSectionBoundaries.isVisible = false 
 updateAccess.WriterSectionBoundaries.color = rgb(255,255,255)
    updateAccess.commitChanges()
End Sub
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: Turning Section Boundaries on/off with macro

Post by JeJe »

I only have LibreOffice 5.3 - if they've ditched the option to set the section boundary visibility in the latest version in the Options dialog... it would make sense in terms of the feature not appearing to work anymore... but it would be better to keep/fix the feature.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Post Reply