How to search font styles using python

I would like to search for a characters/words with a given font style and set it’s paragraph style using python macro. But I’m stuck with:

Unknown property: CharPosture (Error during invoking function search in module file:///home/shemgp/.config/libreoffice/4/user/Scripts/python/StylizeDocument.py (<class 'uno.com.sun.star.beans.UnknownPropertyException'>: Unknown property: CharPosture

File “/usr/lib/libreoffice/program/pythonscript.py”, line 905, in invoke
ret = self.func( *args )
File “/home/shemgp/.config/libreoffice/4/user/Scripts/python/StylizeDocument.py”, line 18, in search
search.setPropertyValue(‘CharPosture’, FontSlant.ITALIC)
))

Here’s my initial code:

def search():
	class FontSlant():
		from com.sun.star.awt.FontSlant import (NONE, ITALIC,)
	document = XSCRIPTCONTEXT.getDocument()
	search = document.createSearchDescriptor()
	search.SearchString = "(.*)"
	search.SearchAll = True
	search.SearchWords = True
	search.SearchRegularExpression = True
	search.SearchCaseSensitive = False
	search.setPropertyValue('CharPosture', FontSlant.ITALIC)
	selsFound = document.findAll(search)
	if selsFound.getCount() == 0:
                return
	for selIndex in range(0, selsFound.getCount()):
                selFound = selsFound.getByIndex(selIndex)
                selFound.setString("abc")

Hi,

You have to provide the search attributes of the descriptor :

from com.sun.star.awt.FontSlant import ITALIC
from com.sun.star.beans import PropertyValue  
def shemgp():
    doc = XSCRIPTCONTEXT.getDocument()
    search = doc.createSearchDescriptor()
    search.SearchString = "(.*)"
    search.SearchAll = True
    search.SearchWords = True
    search.SearchRegularExpression = True
    search.SearchCaseSensitive = False
    prop = PropertyValue('CharPosture', 0, ITALIC, 0)
    search.SearchAttributes = (prop,)
    search.ReplaceString = "abc"
    found = doc.replaceAll(search)

Regards.

It worked. Thanks.