Insert frame centred vertically in page - what is argument?

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
John_Ha
Volunteer
Posts: 9600
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Insert frame centred vertically in page - what is argument?

Post by John_Ha »

I cannot place a frame centred vertically on the page by recording the macro as the selected "Centre relative to page text area" vertical position is not recorded.

Users have asked for the ability to "centralise all text on a page vertically" - see [Issue] [Workaround] Center text on page vertically. This cannot be done in AOO (MS Office does it) but an easy workaround is with a macro to insert a frame and centre it vertically with respect the page. The sequence is:

Insert > Frame > Type ...
- set Width to Relative, 100%.
- set Position > Vertical to Centre to Entire page.
...

When I record a macro to do this I get as below, where the vertical (Y) position (of the anchor? of the frame?) is set to " 0 ", and the frame is inserted at the top of the page. I tested with a picture and, again, the picture is inserted at the top of the page.

Q1 How do I edit the macro to position the frame vertically?

Q2 Where can I find the specs of the expressions, their arguments and values used in macros so I don't have to ask next time?

Code: Select all

sub z_vert_centre
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dim args1(4) as new com.sun.star.beans.PropertyValue
args1(0).Name = "AnchorType"
args1(0).Value = 0
args1(1).Name = "Pos.X"
args1(1).Value = 0
args1(2).Name = "Pos.Y"
args1(2).Value = 0
args1(3).Name = "Size.Width"
args1(3).Value = 17000
args1(4).Name = "Size.Height"
args1(4).Value = 499

dispatcher.executeDispatch(document, ".uno:InsertFrame", "", 0, args1())

end sub
Thanks
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
UnklDonald418
Volunteer
Posts: 1566
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Insert frame centred vertically in page - what is argume

Post by UnklDonald418 »

X-Y coordinate values in oO are in twips, 1440 / inch as per “Andrew Pitonyak's Macros Explained”, under the heading 9.1.2. Determine pixel size (in twips)
In your macro Pox.Y is the vertical position, so just change to a positive value to move down.

If you don't have that document it can be downloaded from http://www.pitonyak.org/oo.php
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
John_Ha
Volunteer
Posts: 9600
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Insert frame centred vertically in page - what is argume

Post by John_Ha »

Thanks. I was hoping there was an argument which was equivalent to Centre to page text area because the frame will then expand both up and down when text is added. If I just get the current page height and halve it, then the frame will be inserted half way down the page, but will only grow downwards - it will not remain centred in the page.

Do yu know where these arguments are specified in any documentation? I have been looking at service TextFrame in the Developer's Guide API which is tantalisingly close but does not give me quite what I need.

I have Andrew's book, but could not find it in there.
 Edit: Isn't Ms Google good!

I asked her what she knew about openoffice BaseFrameProperties.VertOrientRelation and she pointed me to Re: Set Wrap option and position of image and text frame which is almost what I need and I can probably hack it.

I do wish I could find the documentation!

Code: Select all

 With oGraph
    .GraphicURL = sURL
    .Width = w
    .Height = h
    .VertOrient         = com.sun.star.text.VertOrientation.BOTTOM
    .VertOrientRelation = com.sun.star.text.RelOrientation.PAGE_PRINT_AREA
    .HoriOrient         = com.sun.star.text.HoriOrientation.CENTER
    .HoriOrientRelation = com.sun.star.text.RelOrientation.PAGE_PRINT_AREA
    .Surround           = com.sun.star.text.WrapTextMode.THROUGHT
  End With
 
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
musikai
Volunteer
Posts: 294
Joined: Wed Nov 11, 2015 12:19 am

Re: Insert frame centred vertically in page - what is argume

Post by musikai »

Hi,

To vertically center a frame:

Code: Select all

oGraph.VertOrient         = com.sun.star.text.VertOrientation.CENTER
oGraph.VertOrientRelation = com.sun.star.text.RelOrientation.PAGE_FRAME
You can center to these Relations:

Code: Select all

'   hori

'1   PRINT_AREA = Paragraph text area
'0   FRAME = Paragraph area
'5   FRAME_LEFT = Left paragraph border
'6   FRAME_RIGHT = Right paragraph border
'3   PAGE_LEFT = Left page border
'4   PAGE_RIGHT = Right page border
'8   PAGE_PRINT_AREA = Page text area
'7   PAGE_FRAME = Entire page
'2   CHAR = Character

'   vert
'0   FRAME = Margin
'1   PRINT_AREA = Paragraph text area
'7   PAGE_FRAME = Entire page
'8   PAGE_PRINT_AREA = Page text area
'2   CHAR = Character
'9   TEXT_LINE = Line of text
Win7 Pro, Lubuntu 15.10, LO 4.4.7, OO 4.1.3
Free Project: LibreOffice Songbook Architect (LOSA)
http://struckkai.blogspot.de/2015/04/li ... itect.html
John_Ha
Volunteer
Posts: 9600
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Insert frame centred vertically in page - what is argume

Post by John_Ha »

Thank you - that's just what I need. Do you know where the values are documented so I can find out others for myself? I found the VertOrient and VertOrientation variables in the API documentation at service BaseFramePropertiestext but there were no values associated with them.

My google searches with uno.InsertFrame uncovered How to ref. properties? (eg. w/ ".uno:InsertFrame") dispatch which states
Working with the dispatcher will make you crazy. Use an object inspector as explained in [Tutorial] Introduction into object inspection with MRI. Using that tool I came up with this code to insert a frame and adjust its position.
I fully agree with the sentence in red! I shall look at MRI which looks good though I haven't read it yet.

I was also wondering about writing a macro to read the properties of a frame which I had placed manually! The value is recorded as MIDDLE in content.xml.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
User avatar
Villeroy
Volunteer
Posts: 31345
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Insert frame centred vertically in page - what is argume

Post by Villeroy »

Writing macros without MRI is close to impossible. XRay is very helpful too but MRI has many more features.
File>New>Text
Insert>Frame...
Hor.Orientation: Center
Tools>AddOns>MRI<--Selection
Shows property "HoriOrient" = 2
MRI-menu:Mode>Set
Double-click "HoriOrient" and set it to 1 and the frame goes to the right border
Double-click "HoriOrient" and set it to 3 and the frame goes to the left border
OR: change the orientation in the GUI, open a second MRI window and compare what has changed.
Put the cursor on "HoriOrient" and click the [IDL Ref] button. If you are running AOO, this will take you to the documentation of BaseFrameProperties, however the documentation about how the 3 constants 1,2,3 determine the HoriOrientation did not make it into the docs. Normally, the documentation of such property has a link to the enumeration of constants where the meaning of the constants is explained.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
John_Ha
Volunteer
Posts: 9600
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Insert frame centred vertically in page - what is argume

Post by John_Ha »

Villeroy

Thanks. I have downloaded MRI and I am playing with it - I will report back on my progress.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
musikai
Volunteer
Posts: 294
Joined: Wed Nov 11, 2015 12:19 am

Re: Insert frame centred vertically in page - what is argume

Post by musikai »

The macro that you create is it part of a document or is it for different docs? I ask because If it is part of a document then the easiest way is to create a custom Framestyle and just assign it to your Frame:

Code: Select all

g.FrameStyleName = "My FrameStyle"
I also installed MRI some days ago and this makes things much easier. It was really too much searching.
So now only searching for constants is to do.

The list about the relorientations is here:
https://www.openoffice.org/api/docs/com ... ation.html

I really don't know anymore where all the other constants are listed. I put some snippets for you:

Code: Select all

rem----Anchor
   g.AnchorType = com.sun.star.text.TextContentAnchorType.AT_PAGE
  g.AnchorType = com.sun.star.text.TextContentAnchorType.AT_PARAGRAPH
  g.AnchorType = com.sun.star.text.TextContentAnchorType.AT_CHARACTER
  g.AnchorType = com.sun.star.text.TextContentAnchorType.AS_CHARACTER

rem-----Wrap
   g.Surround           = com.sun.star.text.WrapTextMode.NONE
  g.Surround           = com.sun.star.text.WrapTextMode.LEFT
  g.Surround           = com.sun.star.text.WrapTextMode.PARALLEL
  g.Surround           = com.sun.star.text.WrapTextMode.RIGHT
  g.Surround           = com.sun.star.text.WrapTextMode.DYNAMIC
   g.Surround           = com.sun.star.text.WrapTextMode.THROUGHT
  g.Opaque = FALSE
Win7 Pro, Lubuntu 15.10, LO 4.4.7, OO 4.1.3
Free Project: LibreOffice Songbook Architect (LOSA)
http://struckkai.blogspot.de/2015/04/li ... itect.html
User avatar
Villeroy
Volunteer
Posts: 31345
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Insert frame centred vertically in page - what is argume

Post by Villeroy »

[quote="musikai"]The macro that you create is it part of a document or is it for different docs? I ask because If it is part of a document then the easiest way is to create a custom Framestyle and just assign it to your Frame:

Code: Select all

g.FrameStyleName = "My FrameStyle"
+1
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply