Macro for clickable User-defined Index in LO Writer

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
paul1149
Posts: 29
Joined: Mon Jun 27, 2016 12:56 am

Macro for clickable User-defined Index in LO Writer

Post by paul1149 »

If this is not in the best subforum, sorry, please relocate.

I use LO 7.4. on Linux. A little while back LO implemented clickable user-defined indexes in the Writer module. As with a Table of Contents, you can now set up a user-defined index so that each entry can be clicked on to navigate to its text.

To do that, you go to the Entries tab on the Index setup dialog, click on the level of entry you want to edit, then click on a graphical depiction of the entry and select the hyperlink icon. You select hyperlink twice for each entry.

I have a macro to create the user-defined index. But I haven't been able to find what properties to specify so that all the above work would be done by it. So each time I create a U-D index I have to add that manually.

I tried to record the process, but the steps are not picked up by the macro recorder.

Does anyone know how to do this, or how to find out the pertinent properties to work with?

Thanks much.
JeJe
Volunteer
Posts: 2784
Joined: Wed Mar 09, 2016 2:40 pm

Re: Macro for clickable User-defined Index in LO Writer

Post by JeJe »

You might get more help if you provide an example document. Do you use MRI?

https://github.com/hanya/MRI/releases
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
paul1149
Posts: 29
Joined: Mon Jun 27, 2016 12:56 am

Re: Macro for clickable User-defined Index in LO Writer

Post by paul1149 »

Ok, I've attached a file with a user Index. After making the Index I made the level 3 entries clickable. That's the property I want to home in on.

MRI might be exactly what I'm looking for - if I can figure out how to use it. Thanks for the suggestion!
Attachments
Lorem Ipsum.odt
(54.63 KiB) Downloaded 49 times
LibreOffice 7.6.4.1
JeJe
Volunteer
Posts: 2784
Joined: Wed Mar 09, 2016 2:40 pm

Re: Macro for clickable User-defined Index in LO Writer

Post by JeJe »

Just:

install it.
Run the sub LoadMriLibrary in MyMacros/MriLib (Edit: I set an IDE toolbar shortcut for this)
Then its MRI yourobjectname anywhere in your code

A window pops up with all about the object

eg put the caret where you want it and put this in a sub

vc = thiscomponent.currentcontroller.viewcursor
MRI vc
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
JeJe
Volunteer
Posts: 2784
Joined: Wed Mar 09, 2016 2:40 pm

Re: Macro for clickable User-defined Index in LO Writer

Post by JeJe »

perhaps you just need to set the following just like any other hyperlink?

HyperLinkEvents
HyperLinkName
HyperLinkTarget
HyperLinkURL

with the caret on one of your existing links you can examine those with MRI vc as above

Edit
Select the text where you want the hyperlink then try
vc.HyperLinkName = whatever
and so on
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
paul1149
Posts: 29
Joined: Mon Jun 27, 2016 12:56 am

Re: Macro for clickable User-defined Index in LO Writer

Post by paul1149 »

JeJe wrote: Fri Dec 09, 2022 1:09 am
vc = thiscomponent.currentcontroller.viewcursor
MRI vc
Thanks, that plus `Globalscope.BasicLibraries.LoadLibrary( "MRILib" )` got me running. On the Properties tab, with one of the index entries under the caret in the document, I find this in MRI:

Code: Select all

HyperLinkEvents                  .container.XNameReplace    -INTERFACE-                    Maybevoid             51  
HyperLinkName                    string                     ""                             Maybevoid             51  
HyperLinkTarget                  string                     ""                             Maybevoid             51  
HyperLinkURL                     string                     #1%19mauris%20e...             Maybevoid             51  
I have no idea what to do with that however. It's reporting the existence of a hyperlink, but I don't see any parameters for setting one.
LibreOffice 7.6.4.1
JeJe
Volunteer
Posts: 2784
Joined: Wed Mar 09, 2016 2:40 pm

Re: Macro for clickable User-defined Index in LO Writer

Post by JeJe »

Just the = operator

vc.HyperLinkName = yourhyperlinkname
vc.HyperLinkTarget = yourhyperlinktarget

etc.

Easiest might be to make a copy of what you have there for one you've set, make the modifications, then change the selection and apply them there.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
paul1149
Posts: 29
Joined: Mon Jun 27, 2016 12:56 am

Re: Macro for clickable User-defined Index in LO Writer

Post by paul1149 »

Ok, but what I'm trying to do is not to specify certain names and targets, but to make all Level 3 entries subsequently added to the Index clickable. This would be for a generic user-defined index I could generate for any document. I already have the Index-generating macro, I just need to find what to add to it to make Level 3 entries clickable.
LibreOffice 7.6.4.1
JeJe
Volunteer
Posts: 2784
Joined: Wed Mar 09, 2016 2:40 pm

Re: Macro for clickable User-defined Index in LO Writer

Post by JeJe »

Do the HyperLinkEvents not do what you want?
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
paul1149
Posts: 29
Joined: Mon Jun 27, 2016 12:56 am

Re: Macro for clickable User-defined Index in LO Writer

Post by paul1149 »

I have no idea how to implement it. I don't see any spec there for Level 3, for instance.
LibreOffice 7.6.4.1
JeJe
Volunteer
Posts: 2784
Joined: Wed Mar 09, 2016 2:40 pm

Re: Macro for clickable User-defined Index in LO Writer

Post by JeJe »

Looking again HyperLinkEvents are empty anyway.

I'm not understanding what you want here. If you select some words in your document and run this:

Code: Select all

thiscomponent.currentcontroller.viewcursor.hyperlinkurl = "#1%19mauris%20elit,%20nec%20elementum%19UUser-Defined%7Ctoxmark"
It makes it a hyperlink that takes it to your first link target because the url is the same. Nothing else is needed, that's what does it.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
paul1149
Posts: 29
Joined: Mon Jun 27, 2016 12:56 am

Re: Macro for clickable User-defined Index in LO Writer

Post by paul1149 »

IIUC, that is the problem. It would take me to the first link. That link will not exist in other documents.

I'm not looking to embed specific links in an Index, I'm trying to make all subsequent Level 3 entries added to an index clickable. But it's quite possible I'm misunderstanding what you're saying.
LibreOffice 7.6.4.1
JeJe
Volunteer
Posts: 2784
Joined: Wed Mar 09, 2016 2:40 pm

Re: Macro for clickable User-defined Index in LO Writer

Post by JeJe »

As you've had no other responses, you could try posting over at here - might get more help:

https://ask.libreoffice.org/
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
paul1149
Posts: 29
Joined: Mon Jun 27, 2016 12:56 am

Re: Macro for clickable User-defined Index in LO Writer

Post by paul1149 »

ok. thanks again.
LibreOffice 7.6.4.1
JeJe
Volunteer
Posts: 2784
Joined: Wed Mar 09, 2016 2:40 pm

Re: Macro for clickable User-defined Index in LO Writer

Post by JeJe »

Try exploring

mri thiscomponent.documentindexes.getbyindex(0)
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
paul1149
Posts: 29
Joined: Mon Jun 27, 2016 12:56 am

Re: Macro for clickable User-defined Index in LO Writer

Post by paul1149 »

Interesting. I still don't see anything to work from for this specific problem, but interesting nonetheless.

Code: Select all

(Name)                          (Value Type)                (Value)             (Info.)   (Attr.)              (Handle)  
Anchor                          .text.XTextRange            -INTERFACE-         Pseud     Read_Only                 
BackColor                       long                        -1                                                 105  
BackGraphic                     .graphic.XGraphic           -void-                                             105  
BackGraphicFilter               string                      ""                                                 105  
BackGraphicLocation             .style.GraphicLocation      NONE                                               105  
BackGraphicURL                  string                      -Error-                                                 
BackTransparent                 boolean                     True                                               105  
ContentSection                  .text.XTextSection          -INTERFACE-                   Read_Only            1053  
CreateFromChapter               boolean                     False                                              1008  
CreateFromEmbeddedObjects       boolean                     False                                              1029  
CreateFromGraphicObjects        boolean                     False                                              1028  
CreateFromLevelParagraphStyles  boolean                     False                                              1052  
CreateFromMarks                 boolean                     True                                               1005  
CreateFromTables                boolean                     False                                              1026  
CreateFromTextFrames            boolean                     False                                              1027  
DocumentIndexMarks              [].text.XDocumentIndexMark  -Sequence-                    Read_Only            1050  
HeaderSection                   .text.XTextSection          -INTERFACE-                   Maybevoid,Read_Only  1054  
HideTabLeaderAndPageNumber      boolean                     -void-                                             1023  
ImplementationId                []byte                      -SEQUENCE-          Pseud     Read_Only                 
ImplementationName              string                      SwXDocumentIndex    Pseud     Read_Only                 
IsProtected                     boolean                     True                                               1031  
IsRelativeTabstops              boolean                     True                                               1051  
LevelFormat                     .container.XIndexReplace    -INTERFACE-                                        1021  
LevelParagraphStyles            .container.XIndexReplace    -INTERFACE-                   Read_Only            1022  
LocalName                       string                      content.xml#id3...  Attr.     Read_Only                 
MetadataReference               .beans.StringPair           -STRUCT-            Attr.                               
Name                            string                      User-Defined1                                      1057  
Namespace                       string                      file:///home/pa...  Attr.     Read_Only                 
ParaStyleHeading                string                      User Index Heading                                 1037  
ParaStyleLevel1                 string                      User Index 1                                       1039  
ParaStyleLevel10                string                      User Index 10                                      1048  
ParaStyleLevel2                 string                      User Index 2                                       1040  
ParaStyleLevel3                 string                      User Index 3                                       1041  
ParaStyleLevel4                 string                      User Index 4                                       1042  
ParaStyleLevel5                 string                      User Index 5                                       1043  
ParaStyleLevel6                 string                      User Index 6                                       1044  
ParaStyleLevel7                 string                      User Index 7                                       1045  
ParaStyleLevel8                 string                      User Index 8                                       1046  
ParaStyleLevel9                 string                      User Index 9                                       1047  
PropertySetInfo                 .beans.XPropertySetInfo     -INTERFACE-         Pseud     Read_Only                 
ServiceName                     string                      com.sun.star.te...  Pseud     Read_Only                 
StringValue                     string                      file:///home/pa...  Attr.     Read_Only                 
SupportedServiceNames           []string                    -Sequence-          Pseud     Read_Only                 
TOCBookmark                     string                      ""                                                 1061  
TOCNewLine                      boolean                     -void-                                             1062  
TOCParagraphOutlineLevel        boolean                     -void-                                             1063  
TabInTOC                        boolean                     -void-                                             1024  
TextColumns                     .text.XTextColumns          -INTERFACE-                                        109  
Title                           string                      Index Entries                                      1003  
Types                           []type                      -Sequence-          Pseud     Read_Only                 
UseLevelFromSource              boolean                     False                                              1020  
UserIndexName                   string                      User-Defined                                       1036  
LibreOffice 7.6.4.1
Post Reply