I have created an 156 pages file in draw by my self. When i was making it i thought it was the right size but now i change my mind, every page has 3-9 images in it, and i want all of them to have the same size but i don’t mind to keep the ratio so i was looking for something like pic tool but for draw, i can’t find the way to do it and im not very interested to change the pictures one by one neither to move my work to writer just for that.
Please upload a 3-4 page sample file here (to see the type and other properties of the graphics objects located in the file)
You can write a macro (you can not record it) for resize all the same type or similarly named graphic objects.
https://drive.google.com/drive/folders/1KjQ__PWJfIDX-OJKRPu1BYTtP-Z6R4vu?usp=drive_link
that’s part of my file. I dint know how to write a macro not either how to record one. Why is that simple think so difficult?
There is an other one reason that is not very possible to work with other programs some parts of my file was in a pdf at first and a lot of people don’t seem to understand that something like draw is the easy way to process and combine those parts of files.
You can not Record a Draw related macro, because the Macro recorder works in the Calc and in the Writer applications only. And the recording the macros is not an effective mode of the macro creation.
Here is a macro snippet:
REM ***** BASIC *****
Option explicit
Sub ResizeImages
Dim oDrawDoc as object
Dim oPages, oDrawPage as object
Dim oShape as object
Dim oSize as object
Dim Ratio as double
Dim iPageCount, iShapeCount, i, j as integer
oDrawDoc = Thiscomponent()
oPages = oDrawDoc.GetDrawPages()
iPageCount = oPages.GetCount()
For i = 0 to iPageCount-1
oDrawPage = oDrawDoc.DrawPages(i)
For j = 0 To oDrawPage.getCount()-1
oShape = oDrawPage.getByIndex(j)
if oShape.supportsService("com.sun.star.drawing.GraphicObjectShape") then
oSize = oShape.getSize()
Ratio = oSize.Height/oSize.Width
oSize.Width = 6000 'in unit hundredths of a millimeter
oSize.Height = int(oSize.Width*Ratio)
oShape.setSize(oSize)
end if
Next j
Next i
End Sub
The macro will change the size of all MAGES on the pages to 6 cm width and it try to preserve the original ratio (the ratio what the images have before the macro running) .
Of course you can calculate and set the Position of the images in same way.
REM ***** BASIC *****
Option explicit
Sub ResizeImages
Dim oDrawDoc as object
Dim oPages, oDrawPage as object
Dim oShape as object
Dim oSize as object
Dim Ratio as double
Dim iPageCount, iShapeCount, i, j as integer
oDrawDoc = Thiscomponent()
oPages = oDrawDoc.GetDrawPages()
iPageCount = oPages.GetCount()
For i = 0 to iPageCount-1
oDrawPage = oDrawDoc.DrawPages(i)
For j = 0 To oDrawPage.getCount()-1
oShape = oDrawPage.getByIndex(j)
if oShape.supportsService("com.sun.star.drawing.GraphicObjectShape") then
oSize = oShape.getSize()
Ratio = oSize.Height/oSize.Width
oSize.Width = 6000 'in unit hundredths of a millimeter
oSize.Height = 4000 'in unit hundredths of a millimeter
oShape.setSize(oSize)
end if
Next j
Next i
End Sub
I’m more interested the images to have my size so i used that instead, thank you!
Thank you for this macro. A question: can you show me the code to reposition the graphic at the same time? In this case I would like all 28 pages to have the graphic at x = 13mm and y = 3mm.
Thanks much for your help.
Have you only one image/page? Or they have some specific name? Can you upload a small sample file here?
Hi:
Thanks for the quick reply.
There is only one image on each page. Your macro did a great job of reducing each to the proper size (after changing the x setting from 6000 to 18000). Now I need code to do the positioning.
Thanks again.
My macro adjusts the .Size property of the images. You need adjust the .Position property.
I suggest you to download and install one of excellent Object Inspection Tools: MRI and XrayTool. Then you will able to examine the programming objects. They can list the existing properties, methods, interface, etc… of the programming objects.
The resolution of the properties .Size and the .Position given in 0,01 mm unit: you need to set 1300 and 300 values for the coordinate values. (You can add the actual Margin values to the X, Y position of the images.)
MoveImages.odg (14.4 KB)
Thank you so very much. This is a big help for many files that need to be edited.