Thanks to Ratslinger’s help my macro to bring an image to the foreground now works but I want to be able to adjust the image using a Format/Object menu command. To do this, the image must be selected, which is done by clicking it. (The cursor then changes from a single arrow to a 4-way arrow). But in a macro, clicking the image does not have this effect. The cursor remains a single arrow. Is there an basic macro command to perform this selection?
You are still going to have the same problems with recorded macros. Depending upon what exactly you are trying to do (not stated) this can be done with the original macro provided with some modifications. Bringing to the foreground wouldn’t even be necessary. So what else exactly are you looking to do?
I would like to rotate an image - or at least bring up the Position and Size dialogue and display the Rotate tab. Ideally the user could just enter a + or - change in degrees and the macro would do the rest.
We have 1000s of images to transcribe weather data from. Some are not scanned straight.
In case the user first selects the image, you can use this selection. See the macro in the attached file. PictureRotation.ods
I agree with Ratslinger, that the user interface is the problem.
@Regina Nice sample. You may not have noticed but the image(s) being dealt with are in the background. However, I don’t see too much in the way of change to adopt this code. Code has already been provided (this post and another) to access the background image.
See sample in my answer for modified version to rotate background image.
Rotating the Image was not a problem. Trying to make this somewhat user friendly was. Using the
Position and Size dialog as an example, the values go from 0.00 to 360.00 with 0.00 179.99 increasingly moving to the right and 360.00 to 180.01 moving increasingly to the left. So 359.00 is a SLIGHT movement to the right. This means to move slightly to the right involves math each time (360.00 - x.xx).
Additionally, using the dialog has two other problems. First entering a change, the dialog closes & if further changes are needed you must start the dialog again. Also with the dialog, the arrows up/down move the degrees +1/-1 and ignore the hundredths settings making fine tuning difficult.
The routine attached takes this into consideration. When the routine is started an input box is presented:
Here you can see the Current value in the title bar, allowed entries, and a default of 99999. The
Cancel button will just return to this input box. The
OK button will accept the number placed on the input line and return to this same input box so the user may make adjustments until satisfied. Each time it returns, the new current setting is in the Title bar so the user won’t have to guess or calculate. If The
OK button is selected without any input (leaving the 99999 as is) the routine will end. BTW, no need to erase the 99999 for input. Any key entry will overwrite the 9’s.
In case you are wondering the large numbers are used because this is exactly how they are stored internally; without decimals. Code:
sub ImageForeground dim oDrawPage as object dim oImage as object dim iCount as Integer dim lText as Long dim lCurrentAngle as Long rem get access to the document oDrawPage = ThisComponent.getSheets().getByName("YOUR-SHEET-NAME").getDrawPage() iCount = oDrawPage.Count for x = 0 to iCount -1 oImage = oDrawPage.getByIndex(x) If oImage.Name = "YOUR-IMAGE-NAME" Then lText = oImage.RotateAngle lCurrentAngle = oImage.RotateAngle If lCurrentAngle > 18000 Then lCurrentAngle = lCurrentAngle - 36000 while lText <> "99999" lText = InputBox ("Enter a Value from -18000 (Rotate to Right) to 18000 (Rotate to Left):","Current Value = " & lCurrentAngle, "99999") If (lText > -18001 and lText < 18001) then lCurrentAngle = lText If lText < 0 then lText = lText + 36000 oImage.RotateAngle = lText Else If lText <> "99999" Then MsgBox "Invalid Input! " & lText End If Wend Exit Sub End If Next x rem Image not found - error MsgBox "Object not Found" End Sub
I’m sure more can be done but enough time spent for me. You have code you can modify if needed. I hope this a viable solution.
Edit: Kudos to @Regina. Here is a modified version using a background image. Code in sample works fine but must be modified if copied to another Calc document - Sheet name & image name. Also easy to modify to increment in hundredths if wanted.
Sample: RotateImage.ods modified version of PictureRotation.ods
Just to be clear, an entry of 180 is a movement of 1.80 degrees. Also, to move input box to upper left corner, replace this line
lText = InputBox ("Enter a Value from -18000 (Rotate to Right) to 18000 (Rotate to Left):","Current Value = " & lCurrentAngle, "99999") with
lText = InputBox ("Enter a Value from -18000 (Rotate to Right) to 18000 (Rotate to Left):","Current Value = " & lCurrentAngle, "99999", 0, 0)
Thanks Regina and Ratslinger. Your answers are very helpful. I am just getting my feet wet with LO as you can see. It will take me a while to absorb all this. I did realize the limitations of working with Position and Size dialogue. It’s nice to see this can be circumvented.
Should I be concerned that SDK documentation says that the RotateAngle property is ‘deprecated’?
As SDK documentation is a large area to cover, what specifically are you looking at. I have not seen any reference thus far.
It belongs to com::sun::drawing::RotationDescriptor. The integer properties will be replaced by double properties. But that is a long time goal and as far as I know, currently no one work on it. In case you are really concerned and you will learn more about the objects, you should use the transformation matrix instead. You need to read the matrix, decompose it, change the angle, compose it and put it back. You would need a lot of tool functions and subroutines, but it is possible.
I modified your macro to rotate the image with a spinner, Ratslinger. It works well except that when you change directions if doesn’t react immediately. For example, if you click the left arrow after having previously clicked the right one the image will rotate to the right the first time. Subsequent clicks on the left arrow rotate the image left. I can’t put my script in this comment so I will try to put it in an Answer below.
Problem fixed. I should have used the “Button Released” event rather than “Button Pressed”