Setting picture to "Original Size" via 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

Setting picture to "Original Size" via macro

Post by Paddy Landau »

This is probably very simple, but I just can't figure out to do it:

I insert a picture (Insert -> Picture -> From File...). However, OO changes its displayed size so that it doesn't show at its original size.

I need to change the picture's size to its original size (Format -> Picture... -> Type -> Original Size).

I have to do this with hundreds of pictures, so it would be hugely helpful to create a macro to do this and assign it to a keyboard shortcut.

I know how to create macros and assign them to the keyboard, but I don't know what command to use to assign the correct size. I've got this far...

Code: Select all

sub SetToOriginalSize

dim oPic as Object
oPic = ThisComponent.CurrentSelection

oPic.Height = ???
oPic.Width = ???

end sub
How do I find the correct values for Height and Width, remembering that the pictures come in different sizes?

Thanks
turtle47
Posts: 31
Joined: Tue Sep 16, 2008 3:54 pm

Re: Setting picture to "Original Size" via macro

Post by turtle47 »

Hi Paddy,

have a look to this Code:

Code: Select all

Sub Image_OriginalSize
	Dim size As New com.sun.star.awt.Size
	oDocument = thisComponent
	page = oDocument.drawPage	
	nNumShapes = Page.getCount()
	For i = 0 To nNumShapes - 1
	oShape = Page.getByIndex( i )
	ShapeWidth = oShape.actualSize.Width
	ShapeHeight = oShape.actualSize.Height	
	size.Width = ShapeWidth
	size.Height = ShapeHeight	
	oshape.setSize(size)
	next i
End Sub
Good look.

JD
OOo 3.2.X on Ms Windows 7
User avatar
Paddy Landau
Posts: 153
Joined: Wed Nov 28, 2007 12:52 pm

Re: Setting picture to "Original Size" via macro

Post by Paddy Landau »

Excellent, JD, thank you!

Lots for me to learn from there.
Post Reply