Draw - Basic - Shapes

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Philip Duggins
Posts: 4
Joined: Fri Jan 06, 2012 2:46 am

Draw - Basic - Shapes

Post by Philip Duggins »

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
Philip Duggins
Posts: 4
Joined: Fri Jan 06, 2012 2:46 am

Re: Draw - Basic - Shapes

Post by Philip Duggins »

Thank you!
Philip Duggins
LibreOffice 3.4.4 on Windows XP
User avatar
Charlie Young
Volunteer
Posts: 1559
Joined: Fri May 14, 2010 1:07 am

Re: Draw - Basic - Shapes

Post by Charlie Young »

Philip Duggins wrote:How can I create and modify a shape - for example a "Flowchart: Process" shape - with a macro written in Basic?
Just for starters, this puts such a shape at the top left. One also would like to manipulate the position, fill, line styles, etc.

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
Philip Duggins
Posts: 4
Joined: Fri Jan 06, 2012 2:46 am

Re: Draw - Basic - Shapes

Post by Philip Duggins »

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

Code: Select all

   shapeGeometry(0).Value = "flowchart-process"
would insert text in the shape, but it didn't - it remained blank.

Thank you!
Philip Duggins
LibreOffice 3.4.4 on Windows XP
User avatar
Villeroy
Volunteer
Posts: 31344
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Draw - Basic - Shapes

Post by Villeroy »

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
User avatar
Charlie Young
Volunteer
Posts: 1559
Joined: Fri May 14, 2010 1:07 am

Re: Draw - Basic - Shapes

Post by Charlie Young »

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

Code: Select all

   shapeGeometry(0).Value = "flowchart-process"
would insert text in the shape, but it didn't - it remained blank.

Thank you!
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."

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
And yes, see Villeroys link.
Apache OpenOffice 4.1.1
Windows XP
Post Reply