B Marcelly wrote:Use the dispatcher.
RoryOF wrote:I'd do this directly. Find All Heading 2 using Styles. All Heading 2s will be selected. The press Ctrl M, or select Clear Formatting from the format dropdown.
Try this on a copy file first - why bother with a macro?
Thx very much for the tip(Dispatcher) now i only gonna have to figure out how to use this in Python
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dispatcher.executeDispatch(document, ".uno:ResetAttributes", "", 0, Array())
B Marcelly wrote:Thx very much for the tip(Dispatcher) now i only gonna have to figure out how to use this in Python
If you don't know how to translate this in Python, stick to Basic.
- Code: Select all Expand viewCollapse view
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dispatcher.executeDispatch(document, ".uno:ResetAttributes", "", 0, Array())
ThisComponent = XSCRIPTCONTEXT.getDocument()
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dispatcher.executeDispatch(document, ".uno:ResetAttributes", "", 0, ())
def do_XXXXXXX(self):
if self.XXXXXXXXXX('XXX'):
self.doHeading('XXXXXXXXXXXXXXXX XXXXXXXXXX XXXXX', "Heading 2")
self.addParagraphBreak()
def doHeading(self, titel, paraStyle, numberingLevel=1):
self.cl_ID += 1
doc = self.edit_doc
cursor = doc.Text.createTextCursor()
cursor.gotoEnd(False)
cursor.ParaStyleName = paraStyle
cursor.NumberingLevel = numberingLevel
cursor.ListId = self.cl_ID
if paraStyle == 'Heading 3':
doc.Text.insertString(cursor, titel, 0)
else:
doc.Text.insertString(cursor, '\t' + titel, 0)
doc.Text.insertControlCharacter(cursor, PARAGRAPH_BREAK, 0)
imr_lor wrote:Im sorry but this wont help me in any way.
1. as I explained above this is something that needs to happen in the code. (this post is in the Macros and UNO API Forum for a reason)
2. it is not working as intended.
but thanks for the advice
from com.sun.star.frame import DispatchHelper
imr_lor wrote:Mh ok.
Is the needed module implemented in UNO(PYUNO)?
import uno
gStyle = 'Heading 3'
class OfficeHelper:
'''Frequently used methods in office context'''
def __init__(self, ctx=uno.getComponentContext()):
self.ctx = ctx
self.smgr = self.ctx.ServiceManager
def createUnoService(self, service):
return self.smgr.createInstance(service)
def getDesktop(self):
return self.smgr.createInstanceWithContext("com.sun.star.frame.Desktop",self.ctx)
def getCurrentComponent(self):
return self.getDesktop().getCurrentComponent()
def getCurrentFrame(self):
return self.getDesktop().getCurrentFrame()
def getCurrentComponentWindow(self):
return self.getCurrentFrame().getComponentWindow()
def getCurrentContainerWindow(self):
return self.getCurrentFrame().getContainerWindow()
def getCurrentController(self):
return self.getCurrentFrame().getController()
def callMRI(self,obj=None):
'''Create an instance of MRI inspector and inspect the given object (default is selection)'''
if not obj:
obj = self.getCurrentController().getSelection()
mri = self.createUnoService("mytools.Mri")
mri.inspect(obj)
def cleanParaStyle():
ohelper = OfficeHelper()
view = ohelper.getCurrentController()
frame = view.getFrame()
doc = view.getModel()
dispatcher = ohelper.createUnoService("com.sun.star.frame.DispatchHelper")
oFind = findParaStyle(doc, gStyle)
view.select(oFind)
dispatcher.executeDispatch(frame, ".uno:ResetAttributes", "", 0, ())
def findParaStyle(obj, s):
oDesc = obj.createSearchDescriptor()
oDesc.SearchAll = True
oDesc.setSearchString(s)
oDesc.SearchStyles = True
return obj.findAll(oDesc)
def doHeading(self, titel, paraStyle, numberingLevel=1):
self.cl_ID += 1
doc = self.edit_doc
cursor = doc.Text.createTextCursor()
cursor.gotoEnd(False)
cursor.ParaStyleName = paraStyle
cursor.NumberingLevel = numberingLevel
cursor.ListId = self.cl_ID
if paraStyle == 'Heading 3':
doc.Text.insertString(cursor, titel, 0)
else:
doc.Text.insertString(cursor, '\t' + titel, 0)
doc.Text.insertControlCharacter(cursor, PARAGRAPH_BREAK, 0)
def doHeading(self, titel, paraStyle, numberingLevel=1):
self.cl_ID += 1
doc = self.edit_doc
cursor = doc.Text.createTextCursor()
cursor.gotoEnd(False)
cursor.ParaStyleName = paraStyle
cursor.NumberingLevel = numberingLevel
cursor.CharWeight = FW_BOLD
cursor.ListId = self.cl_ID
if paraStyle == 'Heading 3':
doc.Text.insertString(cursor, titel, 0)
else:
doc.Text.insertString(cursor, '\t' + titel, 0)
doc.Text.insertControlCharacter(cursor, PARAGRAPH_BREAK, 0)
Users browsing this forum: No registered users and 9 guests