MACRO for CLICKABLE User-Defined Index?

I use 25.8 LO dev. on Linux. LO has 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 must manually 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 button 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 the above repetitive 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. I’ve also tried to analyse the U-D Index using the MRI tool, but I was not successful. That is not to say it can’t be done.

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

Thanks much. The macro I use follows, and I have uploaded a small sample .odt file.at 51.6 KB file on MEGA

	 REM Author: Andrew Pitonyak 
	 REM 7.18. Insert an index or table of contents
	 REM https://www.pitonyak.org/AndrewMacro.pdf
	 	 
	 Dim oCurs 'Used to insert the text content.
	 Dim oIndexes 'All of the existing indexes
	 Dim oIndex 'TOC if it exists and a new one if not
	 Dim i As Integer 'Find an existing TOC
	 Dim bIndexFound As Boolean 'Flag to track if the TOC was found
	 Dim s$
	 REM First, find an existing User Index if it exists. If so,
	 REM then this will simply be updated.
	 oIndexes = ThisComponent.getDocumentIndexes()
	 bIndexFound = False
	 For i = 0 To oIndexes.getCount() - 1
	 oIndex = oIndexes.getByIndex(i)
	 If oIndex.supportsService("com.sun.star.text.UserDefinedIndex") Then
	 bIndexFound = True
	 Exit For
	 End If
	 Next
	 If Not bIndexFound Then
		 oIndex = ThisComponent.createInstance("com.sun.star.text.UserIndex")
		 REM CreateFromChapter = False
		 REM CreateFromLevelParagraphStyles = False
		 REM CreateFromOutline = False
		 oIndex.CreateFromMarks= True
		 oIndex.Title="My Highlights"
		 oIndex.IsProtected = False
		 REM You can set all sorts of other things such as the Title or Level
		 oCurs = ThisComponent.CurrentController.getViewCursor()
	'	 oCurs = ThisComponent.getText().createTextCursor()
	'	 oCurs.gotoStart(False)
		 ThisComponent.getText().insertTextContent(oCurs, oIndex, False)
	'UPDATE ALL INDEXES:
		oIndexes = ThisComponent.getDocumentIndexes()
		For i =0 To oIndexes.getCount() - 1
			oIndex = oIndexes.getByIndex(i)
			oIndex.update() 'new index is not updated until right HERE!		
		Next	
		'jump to ToC 'optional, NW
		' oCurs = ThisComponent.CurrentController.getViewCursorByRange(oIndex(1)) ' ERROR
		' oCurs.gotoStart(False)
		' oCurs = ThisComponent.CurrentController.Goto(oIndex(i))
		Out:
	 End If
	
	 REM Even the newly inserted index is not updated until right HERE!
	 REM	 oIndex.update() 'Reduntant when part of TOC update

End Sub

where did you end up ?

maybe upload a simple .odt example, if you want people to jump in and help.

Good idea. I’ve edited my post. Thanks.

Hallo
No need for macro!
open a new writer-doc, insert a user-defined-index, edit it to your needs and:
⇒ File ⇒ Templates ⇒ Save as Template …
use that Template!

That’s a very interesting workaround. I don’t really want to deal with an index in every doc I create, but it would work. Still looking for a macro solution.

You may use different Templates for different purposes.

I make too many template changes to try to keep them in sync for this purpose.