Page 1 of 1

Setting picture to "Original Size" via macro

Posted: Mon Nov 17, 2008 7:01 pm
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

Re: Setting picture to "Original Size" via macro

Posted: Mon Nov 17, 2008 10:35 pm
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

Re: Setting picture to "Original Size" via macro

Posted: Tue Nov 18, 2008 12:16 am
by Paddy Landau
Excellent, JD, thank you!

Lots for me to learn from there.