Setting picture to "Original Size" via macro

Creating a macro - Writing a Script - Using the API

Setting picture to "Original Size" via macro

Postby Paddy Landau » Mon Nov 17, 2008 7:01 pm

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   Expand viewCollapse view
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
User avatar
Paddy Landau
 
Posts: 153
Joined: Wed Nov 28, 2007 12:52 pm

Re: Setting picture to "Original Size" via macro

Postby turtle47 » Mon Nov 17, 2008 10:35 pm

Hi Paddy,

have a look to this Code:
Code: Select all   Expand viewCollapse view
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
turtle47
 
Posts: 31
Joined: Tue Sep 16, 2008 3:54 pm

Re: Setting picture to "Original Size" via macro

Postby Paddy Landau » Tue Nov 18, 2008 12:16 am

Excellent, JD, thank you!

Lots for me to learn from there.
User avatar
Paddy Landau
 
Posts: 153
Joined: Wed Nov 28, 2007 12:52 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 4 guests