[Solved]How to change selected picture attributes with macro

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
User avatar
Paddy Landau
Posts: 153
Joined: Wed Nov 28, 2007 12:52 pm

[Solved]How to change selected picture attributes with macro

Post by Paddy Landau »

I have dozens of pictures, and I need to change their attributes in exactly the same way each time (change to a specific size; change the position to centred on the page; wrap-through and in background). I need to do this with new pictures every month.

Creating a macro and assigning it to a key (e.g. Ctrl-F) would mean that I could simply select the picture and press the key, which would save me ages.

I've tried recording a macro (Tools, Macros, Record Macro). But, when I press "Stop Recording", it doesn't record the attribute changes.

I've been going through the BASIC Programming Guide, trying to figure out how to write it by hand. Unfortunately, I can't figure out how to access the currently-selected picture and modify its attributes.

Can someone help please either by pointing to where this is documented, or by showing me how to program the macro?

I'm using OO 2.4.0 on Windows Vista.

Thanks.
Last edited by Hagar Delest on Tue Jun 10, 2008 1:59 pm, edited 2 times in total.
Reason: tagged the thread as Solved.
Ubuntu Hardy 8.04, OpenOffice.org 3.1.1 build 9420
JohnV
Volunteer
Posts: 1585
Joined: Mon Oct 08, 2007 1:32 am
Location: Kentucky, USA

Re: How to change selected picture attributes with macro

Post by JohnV »

This should get you started.

Code: Select all

Sub Main
oDoc = ThisComponent
oPic = oDoc.CurrentSelection
'xray oPic
oPic.Height = 2000
oPic.Width = 2000
oPic.HoriOrient = 2
oPic.TextWrap = 1
End Sub
User avatar
Paddy Landau
Posts: 153
Joined: Wed Nov 28, 2007 12:52 pm

Re: How to change selected picture attributes with macro

Post by Paddy Landau »

Thanks for that.

I'm trying to get my head around how to save it!

I'll post back here once I've succeeded.
Ubuntu Hardy 8.04, OpenOffice.org 3.1.1 build 9420
User avatar
Paddy Landau
Posts: 153
Joined: Wed Nov 28, 2007 12:52 pm

Re: How to change selected picture attributes with macro

Post by Paddy Landau »

JohnV wrote:This should get you started. ...
Thanks, John, much appreciated.

I've saved that and changed the sizes to my required sizes.

Now, where is this all documented, so that I can make the other changes (e.g. "In background")?
Ubuntu Hardy 8.04, OpenOffice.org 3.1.1 build 9420
JohnV
Volunteer
Posts: 1585
Joined: Mon Oct 08, 2007 1:32 am
Location: Kentucky, USA

Re: How to change selected picture attributes with macro

Post by JohnV »

Get the Xray utility to examine the properties and methods of an object.
http://ooomacros.org/dev.php#101416

Add the line "oPic.Opaque = false" for in background.
User avatar
Paddy Landau
Posts: 153
Joined: Wed Nov 28, 2007 12:52 pm

Re: How to change selected picture attributes with macro

Post by Paddy Landau »

That X-Ray Tool is brilliant! Thanks for pointing it out, John.

There are some properties that I don't understand (such as HoriOrientRelation), so I'll get into the documentation and search for them.

I have my macro working now, and looking forward (sort of) to when I need to write another.
Ubuntu Hardy 8.04, OpenOffice.org 3.1.1 build 9420
Post Reply