[Solved] Inserting boxes and shapes
-
- Posts: 13
- Joined: Sun May 13, 2018 8:40 am
[Solved] Inserting boxes and shapes
Hi, does anyone have a simple Basic macro for inserting a text box in a writer document and tilting it to an angle?
Also one for inserting a geometric figure e.g. a star?
many thanks in anticipation
Also one for inserting a geometric figure e.g. a star?
many thanks in anticipation
Last edited by Hagar Delest on Wed Jun 13, 2018 6:32 pm, edited 1 time in total.
Reason: tagged solved
Reason: tagged solved
OpenOffice 5.3.6.1 on Windows 7
Re: inserting boxes and shapes
There is no simple macro for this.
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
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: inserting boxes and shapes
Draw and adjust it by the Draw application, and put it into the Gallery. Then you can use it by a "drag&Drop" from the Gallery in all of applications.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
-
- Posts: 13
- Joined: Sun May 13, 2018 8:40 am
Re: inserting boxes and shapes
No simple macro? A complicated one then perhaps?
OpenOffice 5.3.6.1 on Windows 7
Re: inserting boxes and shapes
You will write it.A complicated one then perhaps?
Please explain: Why you need it?
You can use a template instead (if you often need same shape in same position of the document), or the gallery with your own shapes.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
-
- Posts: 13
- Joined: Sun May 13, 2018 8:40 am
Re: inserting boxes and shapes
A template is of no interest to me because I want to write the macro for an unknown number of users on a network who subsequently would be required to copy the template to their own gallery to use it. Also I would simply like to know how to do this programatically if it can be done as part of a learning process. And finally a macro would open this possibility of a user customising the use of it to some extent - e.g. the text content of a text box. So yeah I'll have to write it myself from trial and error - I had just hoped tofind a quick shortcut here.
OpenOffice 5.3.6.1 on Windows 7
Re: inserting boxes and shapes
A little bit of searching often throws up helpful OO macros.
I found these
[Solved] Insert Image, Position and Resize via Macro in Calc
[Solved] Add Image using macro
[Solved] Inserting and positioning image
and many others
I also recommend Andrew Pitonyak's works on macros.
I found these
[Solved] Insert Image, Position and Resize via Macro in Calc
[Solved] Add Image using macro
[Solved] Inserting and positioning image
and many others
I also recommend Andrew Pitonyak's works on macros.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
Re: inserting boxes and shapes
Don't you have a common templates folder on the network?
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
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
- Sébastien C
- Posts: 111
- Joined: Mon Jan 04, 2010 5:06 pm
- Location: Meymac, France
Re: Inserting boxes and shapes
If I may, some examples...
Insert a text box in Writer and tilting it to an angle is not a big deal...
A common star is a custom shape, and unfortunately, it is so bad documented.
BUT, in Draw, we can convert it in a polygon shape.
And paste the star in Writer, just for studying it points...
After that, drawing a polygon shape is not a big deal too...
A good way, I think, for beginning to learn code...
Insert a text box in Writer and tilting it to an angle is not a big deal...
Code: Select all
Sub textBoxTilting45degrees()
Dim myForm As Object
Dim myDimensionsForm As New com.sun.star.awt.Size
Dim myPositionForm As New com.sun.star.awt.Point
myForm = thisComponent.createInstance("com.sun.star.drawing.TextShape")
myDimensionsForm.Width = 7500 ' 75 mm.
myDimensionsForm.Height = 2530 ' 25,3 mm.
myPositionForm.X = 5000 ' 50 mm.
myPositionForm.Y = 10000 ' 100 mm.
With myForm
.AnchorType = com.sun.star.text.TextContentAnchorType.AT_PAGE
.AnchorPosition.X = 0
.AnchorPosition.Y = 0
.Size = myDimensionsForm
.Position = myPositionForm
.rotateAngle = 4500 ' 45 degrees
End With
thisComponent.drawPage.add(myForm)
myForm.String = "Hello World !!! Hello World !!! Hello World !!! Hello World !!! Hello World !!! Hello World !!!"
End Sub
BUT, in Draw, we can convert it in a polygon shape.
And paste the star in Writer, just for studying it points...
After that, drawing a polygon shape is not a big deal too...
Code: Select all
Sub aNewStarIsBorn()
Dim myForm As Object
Dim myDimensionsForm As New com.sun.star.awt.Size
Dim myPositionForm As New com.sun.star.awt.Point
Dim thePoints(9) As New com.sun.star.awt.Point
myForm = thisComponent.createInstance("com.sun.star.drawing.PolyPolygonShape")
thisComponent.drawPage.add(myForm)
thePoints(0).X = 10869
thePoints(0).Y = 1512
thePoints(1).X = 10592
thePoints(1).Y = 2421
thePoints(2).X = 9681
thePoints(2).Y = 2421
thePoints(3).X = 10420
thePoints(3).Y = 2987
thePoints(4).X = 10143
thePoints(4).Y = 3889
thePoints(5).X = 10869
thePoints(5).Y = 3336
thePoints(6).X = 11596
thePoints(6).Y = 3889
thePoints(7).X = 11318
thePoints(7).Y = 2987
thePoints(8).X = 12058
thePoints(8).Y = 2421
thePoints(9).X = 11147
thePoints(9).Y = 2421
myForm.PolyPolygon = Array( thePoints() )
myDimensionsForm.Width = 2000 ' 20 mm.
myDimensionsForm.Height = 2000 ' 20 mm.
myPositionForm.X = 1000 ' 10 mm.
myPositionForm.Y = 1000 ' 10 mm.
With myForm
.AnchorPosition.X = 0
.AnchorPosition.Y = 0
.AnchorType = com.sun.star.text.TextContentAnchorType.AT_PAGE
.LineWidth = 80
.Size = myDimensionsForm
.Position = myPositionForm
.rotateAngle = 4500 ' 45 degrees
End With
End Sub
- Attachments
-
- formAndShape.odt
- (14.67 KiB) Downloaded 156 times
LibreOffice v. 7.3.2.2, under GNU-Linux Mint and, in virtualization and just for tests, LibreOffice v. 7.3.2.2 an OpenOffice v. 4.1.12 under M$-W 10 .
-
- Posts: 13
- Joined: Sun May 13, 2018 8:40 am
Re: Inserting boxes and shapes
OK many thanks everyone for your ideas and to Sébastian for the code which set me on a useful path. Here's as far as I've got with Sébastians code and some googling and a lot of trial and error:
I wanted a standalone macro and this Works impeccably as a VB file. I just lack the technique for making the borders of the box visible for it to be complete. (It turned out to be not too complicated)
Code: Select all
Dim args(),aStruct
Set objServiceManager= WScript.CreateObject("com.sun.star.ServiceManager")
Set objCoreReflection= objServiceManager.createInstance("com.sun.star.reflection.CoreReflection")
Set oDsk= objServiceManager.createInstance("com.sun.star.frame.Desktop")
Set oDoc= oDsk.loadComponentFromURL("private:factory/swriter", "_blank", 0, args)
Set objSize = createStruct("com.sun.star.awt.Size")
Set objText= oDoc.getText
Set objCursor= objText.createTextCursor
Set objTextFrame= oDoc.createInstance("com.sun.star.drawing.TextShape")
objSize.Width = 7500
objSize.Height = 2530
objTextFrame.setSize( objSize)
objText.insertTextContent objCursor, objTextFrame, false
objTextFrame.String = "Hello World !!! Hello World !!! Hello World !!! Hello World !!!"
objTextFrame.rotateAngle = 4500
objTextFrame.AnchorType = AS_CHARACTER
objTextFrame.IsFollowingTextFlow = False
objTextFrame.CharHeight="14"
objTextFrame.CharFontName="Trebuchet MS"
objTextFrame.CharColor="1500"
objTextFrame.HoriOrient = 0
objTextFrame.VertOrient = 0
objTextFrame.VertOrientPosition = 3500
objTextFrame.HoriOrientPosition = 2000
Function createStruct( strTypeName)
Set classSize= objCoreReflection.forName( strTypeName)
classSize.createObject aStruct
Set createStruct= aStruct
End Function
OpenOffice 5.3.6.1 on Windows 7
- Sébastien C
- Posts: 111
- Joined: Mon Jan 04, 2010 5:06 pm
- Location: Meymac, France
Re: Inserting boxes and shapes
Cogito ergo sum wrote:I just lack the technique for making the borders of the box visible for it to be complete. (It turned out to be not too complicated)
Code: Select all
objTextFrame.LineStyle = com.sun.star.drawing.LineStyle.SOLID
objTextFrame.LineWidth = 100
objTextFrame.LineColor = rgb(255, 0, 0)
Imagine, just for the line, discover: “LineCap”, “LineColor”, “LineDash”, “LineDashName”, “LineEnd”, “LineEndCenter”, “LineEndName”, “LineEndWidth”, “LineJoint”, “LineStart”, “LineStartCenter”, “LineStartName”, “LineStartWidth”, “LineStyle”, “LineTransparence”, “LineWidth”...
And for the margin: “LeftMargin”, “RightMargin”, “TopMargin”, “BottomMargin”, “ParaLeftMargin”, “ParaRightMargin”, “ParaTopMargin”, “ParaBottomMargin”.
A dream isn’t it ?
LibreOffice v. 7.3.2.2, under GNU-Linux Mint and, in virtualization and just for tests, LibreOffice v. 7.3.2.2 an OpenOffice v. 4.1.12 under M$-W 10 .
-
- Posts: 13
- Joined: Sun May 13, 2018 8:40 am
Re: Inserting boxes and shapes
Well, thank you once Again Sébastian - although objTextFrame.LineStyle = com.sun.star.drawing.LineStyle.SOLID throws up an error, but if I change it quite simply to objTextFrame.LineStyle = 1 then it works fine. Like a dream as you say but the dream becomes a nightmare again if for example I try the same thing with LineDash in order to try and get a dotted border. I now have:
and as can be seen I put a VbLf & before the text because although paraleftmargin works paratopmargin doesn't although it doesn't throw up an error. It could be an idea to try Xray, but does it do more than simply list parameters, properties and methods? What I seem to be lacking is the basic understanding of why some things work and others don't when it would seem logical that when the one works the other would too. And yes I have tried to read Pitonyaks stuff - it's excellent but over my head a lot of the time, unfortunately.
Code: Select all
Dim args(),aStruct
Set objServiceManager= WScript.CreateObject("com.sun.star.ServiceManager")
Set objCoreReflection= objServiceManager.createInstance("com.sun.star.reflection.CoreReflection")
Set oDsk= objServiceManager.createInstance("com.sun.star.frame.Desktop")
Set oDoc= oDsk.loadComponentFromURL("private:factory/swriter", "_blank", 0, args)
Set objSize = createStruct("com.sun.star.awt.Size")
Set objText= oDoc.getText
Set objCursor= objText.createTextCursor
Set objTextFrame= oDoc.createInstance("com.sun.star.drawing.TextShape")
objSize.Width = 7500
objSize.Height = 2530
objText.insertTextContent objCursor, objTextFrame, false
objTextFrame.setSize(objSize)
objTextFrame.String = VbLf & "Hello World !!! Hello World !!! Hello World !!! Hello World !!!"
objTextFrame.rotateAngle = 4500
objTextFrame.paraleftmargin = 300
objTextFrame.topmargin = 700
objTextFrame.LineStyle = 1
objTextFrame.LineWidth = 10
objTextFrame.LineColor = rgb(255, 0, 0)
objTextFrame.AnchorType = AS_CHARACTER
objTextFrame.IsFollowingTextFlow = False
objTextFrame.CharHeight="14"
objTextFrame.CharFontName="Trebuchet MS"
objTextFrame.CharColor="1500"
objTextFrame.HoriOrient = 0
objTextFrame.VertOrient = 0
objTextFrame.VertOrientPosition = 3500
objTextFrame.HoriOrientPosition = 2000
Function createStruct( strTypeName)
Set classSize= objCoreReflection.forName( strTypeName)
classSize.createObject aStruct
Set createStruct= aStruct
End Function
OpenOffice 5.3.6.1 on Windows 7
Re: Inserting boxes and shapes
There are only three LineStyle constants: NONE, SOLID, and DASH.
To use them you need to give the complete qualified names:A lot to type for 0, 1, and 2.
To use them you need to give the complete qualified names:
Code: Select all
com.sun.star.drawing.LineStyle.NONE
com.sun.star.drawing.LineStyle.SOLID
com.sun.star.drawing.LineStyle.DASH
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
---
Lupp from München