Draw - Basic - Shapes
-
- Posts: 4
- Joined: Fri Jan 06, 2012 2:46 am
Draw - Basic - Shapes
How can I create and modify a shape - for example a "Flowchart: Process" shape - with a macro written in Basic?
Philip Duggins
LibreOffice 3.4.4 on Windows XP
LibreOffice 3.4.4 on Windows XP
-
- Posts: 4
- Joined: Fri Jan 06, 2012 2:46 am
- Charlie Young
- Volunteer
- Posts: 1559
- Joined: Fri May 14, 2010 1:07 am
Re: Draw - Basic - Shapes
Just for starters, this puts such a shape at the top left. One also would like to manipulate the position, fill, line styles, etc.Philip Duggins wrote:How can I create and modify a shape - for example a "Flowchart: Process" shape - with a macro written in Basic?
Code: Select all
Sub InsertProcessShape
Dim oDoc As Object
Dim oDrawPage As Object
Dim oShape As Object
Dim shapeGeometry(0) as new com.sun.star.beans.PropertyValue
Dim oSize As new com.sun.star.awt.Size
oSize.width = 3000
oSize.height = 1000
oDoc = ThisComponent
odrawPage = oDoc.DrawPages(0)
oShape = oDoc.createInstance("com.sun.star.drawing.CustomShape")
shapeGeometry(0).Name = "Type"
shapeGeometry(0).Value = "flowchart-process"
oDrawPage.add(oShape)
oShape.CustomShapeGeometry = shapeGeometry
oShape.Size = oSize
End Sub
Apache OpenOffice 4.1.1
Windows XP
Windows XP
-
- Posts: 4
- Joined: Fri Jan 06, 2012 2:46 am
Re: Draw - Basic - Shapes
Yes, I definitely would like to be able to manipulate its properties - in particular, position and the text it has in it. I thought the code
would insert text in the shape, but it didn't - it remained blank.
Thank you!
Code: Select all
shapeGeometry(0).Value = "flowchart-process"
Thank you!
Philip Duggins
LibreOffice 3.4.4 on Windows XP
LibreOffice 3.4.4 on Windows XP
Re: Draw - Basic - Shapes
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
- Charlie Young
- Volunteer
- Posts: 1559
- Joined: Fri May 14, 2010 1:07 am
Re: Draw - Basic - Shapes
The shapeGeometry.Value is the type of CustomShape. To see what these are, it is probably easiest to draw one manually and inspect it with MRI or xRay, as It isn't always obvious. For example, for a decision shape, the CustomShapeGeometry type is "diamond."Philip Duggins wrote:Yes, I definitely would like to be able to manipulate its properties - in particular, position and the text it has in it. I thought the code
would insert text in the shape, but it didn't - it remained blank.Code: Select all
shapeGeometry(0).Value = "flowchart-process"
Thank you!
But to go a bit further, this version of the macro centers the shape on the page, sets the fill to NONE, gives it a thicker line, and puts some text in it:
Code: Select all
Sub InsertProcessShape
Dim oDoc As Object
Dim oDrawPage As Object
Dim oShape As Object
Dim shapeGeometry(0) as new com.sun.star.beans.PropertyValue
Dim oSize As new com.sun.star.awt.Size
Dim ShapePos As new com.sun.star.awt.Point
oSize.width = 4000
oSize.height = 2000
oDoc = ThisComponent
oDrawPage = oDoc.DrawPages(0)
oShape = oDoc.createInstance("com.sun.star.drawing.CustomShape")
shapeGeometry(0).Name = "Type"
shapeGeometry(0).Value = "flowchart-process"
oDrawPage.add(oShape)
oShape.CustomShapeGeometry = shapeGeometry
oShape.Size = oSize
ShapePos.X = (oDrawPage.width - oSize.width) \ 2
ShapePos.Y = (oDrawPage.height - oSize.height) \ 2
oShape.setPosition(ShapePos)
oShape.FillStyle = com.sun.star.drawing.FillStyle.NONE
oShape.LineWidth = 50
oShape.String = "Spin wheels" & Chr(10) & "(loop forever)"
End Sub
Apache OpenOffice 4.1.1
Windows XP
Windows XP