Retrieving numbering (list item) details from a paragraph

Keyboard macros or custom scripts

Retrieving numbering (list item) details from a paragraph

Postby _savage » Tue Nov 18, 2014 5:16 pm

While my script iterates over the paragraphs of a document:

Code: Select all   Expand viewCollapse view
    parenum = document.Text.createEnumeration()
    while parenum.hasMoreElements() :
        par = parenum.nextElement()
        if par.supportsService("com.sun.star.text.Paragraph") :
            ...

it detects a bullet or enumeration list through the paragraph's "NumberingStyleName" property: if it's not an empty string then the paragraph is some form of list item. (Loading documents from different sources like Word versions etc, however, seems to result in all sorts of numbering strings.)

My question now is: how can I differentiate nested lists? I mean, looking at a paragraph which properties tell me if this is a numbered or bullet list, style of numbering, and it's nesting depth.

Thanks!
Mac 10.11 using LO 5.3.6.1, Gentoo Linux using LO 5.3.4.2 headless.
_savage
 
Posts: 162
Joined: Sun Apr 21, 2013 12:55 am

Re: Retrieving numbering (list item) details from a paragrap

Postby karolus » Tue Nov 18, 2014 5:47 pm

Hallo

check
Code: Select all   Expand viewCollapse view
par.NumberingLevel


and use MRI

Karolus
AOO4, Libreoffice - 5.1 … 5.3.2.2 on Linux Mint17
User avatar
karolus
Volunteer
 
Posts: 843
Joined: Sat Jul 02, 2011 9:47 am

Re: Retrieving numbering (list item) details from a paragrap

Postby _savage » Tue Nov 18, 2014 7:18 pm

Thanks :)

I've clicked through MRI for an open document but I found it quite overwhelming to sift through all the information that I'm looking for. Having said that, I could have just checked the UNO Paragraph API.
Mac 10.11 using LO 5.3.6.1, Gentoo Linux using LO 5.3.4.2 headless.
_savage
 
Posts: 162
Joined: Sun Apr 21, 2013 12:55 am

Re: Retrieving numbering (list item) details from a paragrap

Postby _savage » Thu Nov 20, 2014 7:04 pm

The NumberingLevel property of the par does indeed provide a short integer value between 0 (outer-most) and N (increasing number of nesting levels) that I can use.

The next question then is whether a numbering uses bullets of various kinds or an enumeration. So I looked at the paragraph's NumberingRules property which gives a few hints by its own NumberingType and Name properties. However, scanning through a document I found that most of those properties are set to None or some funky integer (Name=45990630598139397491). Continuing my search I then found a NumberingLevel service but neither the paragraph nor the numbering rules provide that service.

EDIT After some playing around I found that the following code works and it returns an integer which represents the NumberingType value. It iterates over the NumberingRules's PropertyValue list to find the one I'm interested in:

Code: Select all   Expand viewCollapse view
# Helper function get access an object's attribute; return None if the attribute didn't exist for the object.
def get_uno_attr(obj, attr) :
    return getattr(obj, attr) if hasattr(obj, attr) else None

# Helper function to iterate over a PropertyValue list to find a property by name, and return its value; return None if not found.
def get_uno_pval(plist, vname) :
    for pval in plist :
        if vname == get_uno_attr(pval, "Name") :
            return get_uno_attr(pval, "Value")
    return None


# Get the numbering rules for this paragraph, which contain more details.
rules = get_uno_attr(paragraph, "NumberingRules")

# Get the number of PropertyValue items for the paragraph's numbering rule set.
pnum = get_uno_attr(rules, "Count")

# Oddly, any hardwired index between 0..pnum-1 works and returns the same list or PropertyValues.
numtype = get_uno_pval(rules.getByIndex(0), "NumberingType"))

The numtype is an integer representing any of the NumberingType values. Other properties are the ones I found provided by the NumberingLevel service mentioned above. However, I can't explain why the above call to getByIndex() would return the entire list (array) instead of the indexed item.
Mac 10.11 using LO 5.3.6.1, Gentoo Linux using LO 5.3.4.2 headless.
_savage
 
Posts: 162
Joined: Sun Apr 21, 2013 12:55 am

Re: Retrieving numbering (list item) details from a paragrap

Postby _savage » Sun Mar 18, 2018 2:44 am

_savage wrote:However, I can't explain why the above call to getByIndex() would return the entire list (array) instead of the indexed item.

See also this comment on the “Starbasic Macro for bullets and numbering look” thread.
Mac 10.11 using LO 5.3.6.1, Gentoo Linux using LO 5.3.4.2 headless.
_savage
 
Posts: 162
Joined: Sun Apr 21, 2013 12:55 am


Return to OpenOffice Basic, Python, BeanShell, JavaScript

Who is online

Users browsing this forum: No registered users and 3 guests