[Solved] Change position image in document

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Touf2638
Posts: 14
Joined: Tue Aug 20, 2019 4:21 pm

[Solved] Change position image in document

Post by Touf2638 »

Hi,
I try to change position of an image in a document. I have error message "position can't be changed with this method"
I have try oGraphics(0).SetPosition Opos, oGraphics(0).Position = oPos. I have try with oImg instead of oGraphics(0) etc... Same error
Size works fine. Just position don't work.
What's wrong ?
Thanks

Code: Select all

	Dim oGraphics as Object, ImageName as string, oPos as object
	oGraphics = Doc.getGraphicObjects()   
	Dim oImg as Object  
	For Each oImg in oGraphics   
		ImageName = oImg.name
		if ImageName="Image1" then
			oImg.Width=2000
			oImg.Height=2000
			oPos = New com.sun.star.awt.Point
			oPos.X = 10
			oPos.Y = 10
			oImg.setPosition(oPos)
			exit for
		end if
	Next  
Last edited by Hagar Delest on Sun Sep 08, 2019 9:33 pm, edited 1 time in total.
Reason: tagged solved
OpenOffice 6.2 on Windows 10
JeJe
Volunteer
Posts: 2776
Joined: Wed Mar 09, 2016 2:40 pm

Re: Change position image in document

Post by JeJe »

Use oImg.HoriOrientPosition and oImg.VertOrientPosition

If you don't have MRI...

https://extensions.openoffice.org/en/pr ... ction-tool

Exploring will get you this information and tell you that getposition and setposition won't work.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Touf2638
Posts: 14
Joined: Tue Aug 20, 2019 4:21 pm

Re: Change position image in document

Post by Touf2638 »

Thank's works fine. Sorry but I have search in documentation and I don't find reason get et set position don't works. Where do you see explanation ?
OpenOffice 6.2 on Windows 10
JeJe
Volunteer
Posts: 2776
Joined: Wed Mar 09, 2016 2:40 pm

Re: Change position image in document

Post by JeJe »

I just looked at MRI and saw that getposition and setposition don't work... and looked to find the correct thing to do what you wanted to do. Everything isn't fully documented in OO... you just have to do what I did there... and not worry about that.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
Zizi64
Volunteer
Posts: 11356
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Change position image in document

Post by Zizi64 »

Where do you see explanation ?
The object inspection tools - Like the XrayTool or the MRI - can show list the existing properties and methods of the objects.

Otherwise there are descriptions for the API on the AOO and LibreOffice related webpages.
API: Application Programming Interface
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
JeJe
Volunteer
Posts: 2776
Joined: Wed Mar 09, 2016 2:40 pm

Re: Change position image in document

Post by JeJe »

There will probably be an explanation if you dig around in the documentation... looking at what are the supported services (again from MRI), perhaps you can get that understanding looking at these pages for starters:

https://www.openoffice.org/api/docs/com ... Shape.html

https://www.openoffice.org/api/docs/com ... Frame.html
This interface specifies the access to the shape data (position and size) of the text frame.

This interface is valid before the text frame is attached to a surrounding text, but when attached the values can change (e.g., due to a revised layout of the surrounding text).

The position is relative to the position of the anchor [see XTextFrame::getAnchor()]. Size and position are both measured in 100th mm. The size is not valid if the size is relative and no layout exists or if the layout is invalid.

This interface is only for the layout. In particular, the setting of values is only allowed for the layout component of the owner text of this text component.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Touf2638
Posts: 14
Joined: Tue Aug 20, 2019 4:21 pm

Re: Change position image in document

Post by Touf2638 »

Thanks a lot
OpenOffice 6.2 on Windows 10
Post Reply