# Revision history [back]

### Macro: combine text frames for faster insertion

I have a macro that inserts a lot of text frames and adds text in each frame as it goes along and applies styles to the text and whatnot (see code mockup below). The problem is, it runs rather slowly. It takes about 5 seconds to insert 15-20 frames, and I figure that is because it is manipulating the Writer document as it is going along inserting each frame.

Is there a way to build all the frames and manipulate their contents and then insert them all at once into the document? And would that actually speed things up? I tried moving the insertion command to the end, but then the macro crashed at "oFrame.Text.String =".

oFrame = ThisComponent.createInstance( "com.sun.star.text.TextFrame" )
oFrame.widthType = 0
oFrame.FrameStyleName = "My Special Frame"
oFrame.Text.AnchorType = com.sun.star.text.TextContentAnchorType.AS_CHARACTER
oFrame.Text.VertOrient = 7
...
...
...
ThisComponent.Text.insertTextContent( viewCursor.Start, oFrame, false )
oFrame.Text.String = "[important stuff]"
[do stuff to the text in the frame]


### Macro: combine text frames for faster insertion

I have a macro that inserts a lot of text frames and adds text in each frame as it goes along and applies styles to the text and whatnot (see code mockup below). The problem is, it runs rather slowly. It takes about 5 seconds to insert 15-20 frames, and I figure that is because it is manipulating the Writer document as it is going along inserting each frame.

Is there a way to build all the frames and manipulate their contents and then insert them all at once into the document? And would that actually speed things up? I tried moving the insertion command to the end, but then the macro crashed at "oFrame.Text.String =".

(This happens inside a for-loop.)
oFrame = ThisComponent.createInstance( "com.sun.star.text.TextFrame" )
oFrame.widthType = 0
oFrame.FrameStyleName = "My Special Frame"
oFrame.Text.AnchorType = com.sun.star.text.TextContentAnchorType.AS_CHARACTER
oFrame.Text.VertOrient = 7
...
...
...
ThisComponent.Text.insertTextContent( viewCursor.Start, oFrame, false )
oFrame.Text.String = "[important stuff]"
[do stuff to the text in the frame]

frame]

### Macro: combine text frames for faster insertion

I have a macro that inserts a lot of text frames and adds text in each frame as it goes along and applies styles to the text and whatnot (see code mockup below). The problem is, it runs rather slowly. It takes about 5 seconds to insert 15-20 frames, and I figure that is because it is manipulating the Writer document as it is going along inserting each frame.

Is there a way to build all the frames and manipulate their contents and then insert them all at once into the document? And would that actually speed things up? I tried moving the insertion command to the end, but then the macro crashed at "oFrame.Text.String =".

(This happens inside a for-loop.) for-loop.)

oFrame = ThisComponent.createInstance( "com.sun.star.text.TextFrame" )
oFrame.widthType = 0
oFrame.FrameStyleName = "My Special Frame"
oFrame.Text.AnchorType = com.sun.star.text.TextContentAnchorType.AS_CHARACTER
oFrame.Text.VertOrient = 7
...
...
...
ThisComponent.Text.insertTextContent( viewCursor.Start, oFrame, false )
oFrame.Text.String = "[important stuff]"
[do stuff to the text in the frame]frame]


### Macro: combine text frames for faster insertion

I have a macro that inserts a lot of text frames and adds text in each frame as it goes along and applies styles to the text and whatnot (see code mockup below). The problem is, it runs rather slowly. It takes about 5 seconds to insert 15-20 frames, and I figure that is because it is manipulating the Writer document as it is going along inserting each frame.

Is there a way to build all the frames and manipulate their contents and then insert them all at once into the document? And would that actually speed things up? I tried moving the insertion command to the end, but then the macro crashed at "oFrame.Text.String =".

(This happens inside a for-loop.)

oFrame = ThisComponent.createInstance( "com.sun.star.text.TextFrame" )
oFrame.widthType = 0
oFrame.FrameStyleName = "My Special Frame"
oFrame.Text.AnchorType = com.sun.star.text.TextContentAnchorType.AS_CHARACTER
oFrame.Text.VertOrient = 7
...
...
...
ThisComponent.Text.insertTextContent( viewCursor.Start, oFrame, false )
oFrame.Text.String = "[important stuff]"
[do stuff to the text in the frame]


UPDATE: This question doesn't really matter so much anymore, because it seems like LibreOffice was just being slow for no reason. After restarting, my existing code runs much faster.