If you want to develop a system of “macros” for the purpose:
You can store ranges in different ways (e.g.):
SheetCellRange - or of the range addresses
SheetCellRanges object [
myRgs = ThisComponent.createInstance("com.sun.star.sheet.SheetCellRanges")]
Specialized structures you define yourself in Basic or… (Type declarations).
The way you choose may depend on the specific features you want to implement.
I don’t yet know a way to ask a spreadsheet for the current level of grouping. Tell me if you find out.
(And I personally next to never used outline groups… not to speak of AutoOutline.)
The (main) related API reference is LibreOffice: XSheetOutline Interface Reference
I would assume the levels are always defined implicitly by nesting.
A simplified example:
REM For a test I had multi-selected three single ranges in one sheet:
doc = ThisComponent
sel = doc.CurrentSelection
For Each rg in sel
ra = rg.RangeAddress
sheet = doc.Sheets(ra.Sheet)
REM The Sub created three (additional) nested outline levels as expected.
REM In a different test the rows of second range weren't a subset of
REM the rows of the first range. There wasn't casted an error,
REM but the second group was not created.