writer: macro to change writer line/arrow/shape object properties programmatically

Since writer shape styles are not implemented using regular styles method it is not a quick and simple task to set some pre-set paramaters for some shapes. The mentioned question/post indicates that it takes time to go into properties and manually change varying properties of a shape.

Once I have an appropriately edited shape such as a line (eg, appropriate width, any arrows, colour, size, etc) I tend to copy and paste this shape in the event that it is needed again. However, some undesirable options such as angle are copied as well.

So I want to create a macro which I can bind to a keyboard sequence to set the angle of a line/arrow/shape object to 0 after I have pasted it but not sure how.

Have found the following code which is for OpenOffice and meant to generate lines in writer. However, in
LibreOffice it generates some lines it in LO Draw rather than resetting the selected writer shape angle to zero.

Whilst this is not exactly what I am looking for, it is a starting point. Miserably terrible at macros and programming so wondering if anybody has an idea how to programmatically set currently selected line or shape angle to zero. Additionally, if there is any guidance on other properties which can be implemented / edited programmatically individual macros can be set up as a kind of “style”. (because apparently workable styles for shapes are not available in LO at this point).

EXAMPLE MACRO DrawLinesInWriteDocument, page 323 of Andrew Pitonyak’s OpenOffice.org Macros Explained - V4: (section text below):

13.9.3 Writer,

"Each Writer document contains a single draw page for the entire document. In Writer, the page is like a transparent layer containing drawing data on top of the standard document data.
Writer documents do not support the XDrawPagesSupplier interface, because they only contain a single draw page. They do, however, support the XDrawPageSupplier interface, which defines the single object method getDrawPage().

The macro in Listing 290 uses optional draw page properties — namely height and width. The draw page from a Writer document does not contain these properties. The draw page in a Writer document has other peculiarities, however. For example, adding lines to the draw page — as done in Listing 290 — adds them as characters at the cursor position rather than interpreting the positions as specific locations in the document. The macro in Listing 292 draws lines to demonstrate this behavior (also see Figure 85)"

Sub DrawLinesInWriteDocument
  Dim oDoc       'Newly created Writer document
  Dim oDrawPage  'The draw page that will contain the graphics image
  Dim oShape     'Shape to insert

  REM Create a new Writer document!
  oDoc = StarDesktop.loadComponentFromURL("private:factory/swriter",_
                                          "_default", 0, Array())
  oDrawPage = oDoc.getDrawPage()
  Dim i As Long
  Dim oSize as new com.sun.star.awt.Size
  Dim dStepSize As Double
  dStepSize = 800
  For i = 0 To 10
    oShape = oDoc.createInstance("com.sun.star.drawing.LineShape")
    oShape.LineColor = rgb(255, 255 - 20 * i, 20 * i)
    oShape.LineWidth = 50
    oSize.width = dStepSize - CLng(CDbl(i) * dStepSize / 10)/2
    oSize.width = CLng(dStepSize/5 * i - dStepSize)
    oSize.height= dStepSize
End Sub

I think it is methodologically wrong to try and do everything from within Writer alone. LO comes with several component, including Draw which is a nice tool for vector drawings.

Your request above addresses only a part of your goal. You don’t use arrows as mere decorative objects. You use them to emphasise a relation between two other objects.

Then you should prepare the entire illustration (the two objects of interest and the linking arrow) with Draw where you can benefit from full-fledged graphic styles. After that, you copy the illustration into Writer.

This was already partly explained in the answer to the question you link to.

Trying to link text processing Writer blocks and drawing in a non trivial manner (i.e. not simply anchored) is doomed to fail or cause even more formatting problems.

To show the community your question has been answered, click the ✓ next to the correct answer, and “upvote” by clicking on the ^ arrow of any helpful answers. These are the mechanisms for communicating the quality of the Q&A on this site. Thanks!

In case you need clarification, edit your question (not an answer) or comment the relevant answer.

Basically I cram as much information on the sheet as possible in a type of “cheat sheet” or detailed brochure/flyer/newspaper style. Layout and text flow can be complex in some cases occassionaly use of lines in my documents can also serve to act as a border/partition to provide visual separation of sometimes indistinguishable sections. This work may be classified as DTP but all the other DTP softwares I have tried are unfriendly to use. Have tried Scribus and QuarkXPress briefly but don’t have time right now and CBF learning a whole other suite.

Generally the maximum document size is around 4 pages (crammed in size 7 arial). Using shapes in writer is kept to a minimum. Only use writer for simple arrows and lines and often use them for decorative purposes because they are quick and easy and do not require switching to Draw. For example, use a simple line as a “stick label” pointing to an area of an image in order to label that area appropriately…(continued next comment).

Of course editing such an image itself is favourable if there are more than 2 or 3 stick-labels required. The use of lines in my documents also serve to act as a border to (where required) provide visual separation of sections which might otherwise be indistinguishable from each other. (ie, appear as same sect). Since the layout and text flow can be complex in some (where required)

Here is an example of what types of documents I produce:


Always looking for better ways to work, so if you have any thoughts or comments better produce the following layouts this would be great.

As always, your comments on how to better work are always welcome and very much appreciated and valued.

I had a look at the example. Your structure is faulty: frames within frames within frames, aggravated by the fact you are not using styles with the consequence that you add tons of empty paragraphs to position your elements. Since I have not your fonts, your doc becomes a real mess on my computer when I compare to PDF.

Your design choice is not “newspaper style”. It would have been based on a 2-column page instead of frames. It must be very difficult to format because of the interference between the frames because of their wrap property.

Superficially, if you want to stay with your structure and layout method, you’d better off to do everything with Draw instead of Writer. You lose in text formatting richness but your text decorations are relatively basic, so it can be done in Draw with text boxes.

Lines (separators between topics): every frame can have a border; you can do it presently. Select the needed side (any combination of top, left, bottom, right).

Your document looks like mind-mapping notes. The basic tool for this is a list which offers automatic level management and numbering.

I tried to reformat part of your document along this track with 2 columns (“newspaper style”).

Unfortunately, your document is so badly structured that I can’t see exactly where the frames are, where they are anchored (some are erroneously anchored to page and thus not related to other paragraphs). They are difficult to select and grab.

Some paragraphs which logically are grouped are hosted in separate frames.

Your document is impossible to maintain. It is such a mess you can’t even add or remove anything in it. You have heavily used direct formatting instead of relyinf on paragraph and character styles.

Disorder is such that you lose the general organisation: you gave the same number to several paragraphs instead of usiing a list which would have prevented number clash. (…)

In my attempt to tidy up
I primarily use a list.

Some of your frames are conceptually footnotes (definition of terms whiwh are better located at bottom of page instead of inside a side frame).

Large drawings (illustrations) can remain as side frames when it is obvious they are related to a paragraph. Otherwise, add a caption to them; position them anywhere in the page (but anchored to some paragraph so that text flow can lay out them where convenient) and reference the caption “see fig. x” from the text.

This should leave only a handful of frames. You have presently 80-90 frames over 2 pages which is way excessive! and also prevent you from editing because you didn’t give names to the frames. Trying to select one is a pure guess game.