Draw: "Insert File" into file

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
jep
Posts: 22
Joined: Wed Sep 29, 2010 4:53 pm

Draw: "Insert File" into file

Post by jep »

I've created macros that adjust text, lines and images in draw files to handle various requirements.
Each file need a cover page depending on the content, located in a draw file with a number of pages.
I need code to import one of the cover pages from that file into each macro adjusted file.
The macro should do what you get with Insert->File... select page(s).

Wouldn't mind if the code is expressed as ooRexx or similar.

Can't seem to find code how to switch to a specific page either.
Apache OpenOffice 4.1.13 on ArcaOS 5.0.7
Bidouille
Volunteer
Posts: 574
Joined: Mon Nov 19, 2007 10:58 am
Location: France
Contact:

Re: Draw: "Insert File" into file

Post by Bidouille »

jep
Posts: 22
Joined: Wed Sep 29, 2010 4:53 pm

Re: Draw: "Insert File" into file

Post by jep »

So the link says:

"Currently it is not possible to insert slides from a drawing or presentation into a drawing document through API. To accomplish this, use the Insert – File command from the menu."

Is it possible to call the menu command (Dispatch...)?
Apache OpenOffice 4.1.13 on ArcaOS 5.0.7
jep
Posts: 22
Joined: Wed Sep 29, 2010 4:53 pm

Re: Draw: "Insert File" into file

Post by jep »

I've decided to write code to do it, but how can one select to display a certain page?
Apache OpenOffice 4.1.13 on ArcaOS 5.0.7
jep
Posts: 22
Joined: Wed Sep 29, 2010 4:53 pm

Re: Draw: "Insert File" into file

Post by jep »

self~XDispatchHelper~executeDispatch( self~xDoc~XModel~getCurrentController~getFrame~XDispatchProvider, ".uno:Intersect", "", 0, .UNO~noProps )

I use this code to call "Intersect".
Apache OpenOffice 4.1.13 on ArcaOS 5.0.7
Bidouille
Volunteer
Posts: 574
Joined: Mon Nov 19, 2007 10:58 am
Location: France
Contact:

Re: Draw: "Insert File" into file

Post by Bidouille »

jep wrote: Mon Feb 05, 2024 4:39 pm but how can one select to display a certain page?
You cannot interact with UNO commands
User avatar
Lupp
Volunteer
Posts: 3530
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: Draw: "Insert File" into file

Post by Lupp »

I probably can't understand the subject "Insert File ...", but:

1. The CurrentController of a Draw document can select a DrawPage (all its shapes as a "temporary group").
2. Draw doesn't support the macro recorder.
3. AOO is under very slow (if any) development. Better shift to LibreOffice with such tasks.
4. The attached demo was created with LibO 24.2.0.3. It was also tested successfully with LibO 6.4.5. it failed when tried with AOO 4.1.7.
5. The alternative approach didn't run for me.

(To support tests V 24.2 is already available as a PortableApps package.)

See demo:
aoo111169demoCopyInsertDrawpage.odg
(14.4 KiB) Downloaded 40 times
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
jep
Posts: 22
Joined: Wed Sep 29, 2010 4:53 pm

Re: Draw: "Insert File" into file

Post by jep »

I'll use your approach to copy content, but my pages are completely separated, located in another draw file.
In my case it contain 3 pages, each depending on what the current draw file contain.
The page to insert is static, but describe the content in the current draw file.

Case 1: current draw file contain com.sun.star.drawing.LineShape or com.sun.star.drawing.PolyLineShape
Insert first page from the separate file.

Case 2: current draw file contain com.sun.star.drawing.GraphicObjectShape
Insert second page from the separate file.

Case 3: current draw file contain com.sun.star.drawing.ClosedBezierShape or com.sun.star.drawing.PolyPolygonShape
Insert third page from the separate file.
Last edited by jep on Thu Feb 08, 2024 5:41 pm, edited 1 time in total.
Apache OpenOffice 4.1.13 on ArcaOS 5.0.7
jep
Posts: 22
Joined: Wed Sep 29, 2010 4:53 pm

Re: Draw: "Insert File" into file

Post by jep »

Bidouille wrote: Tue Feb 06, 2024 4:15 pm
jep wrote: Mon Feb 05, 2024 4:39 pm but how can one select to display a certain page?
You cannot interact with UNO commands
I use
self~XDispatchHelper~executeDispatch( self~xDoc~XModel~getCurrentController~getFrame~XDispatchProvider, ".uno:Intersect", "", 0, .UNO~noProps )
to create quite advanced intersecting draw objects with ooRexx paired with BSF4ooRexx to run everything from outside OpenOffice as it is now, and it work great.

I do look for a replacement to ".uno:InsertFile"

A stable API is preferable, and AOO itself has the ability... so it should be possible to call it somehow... but if it refuse, I'll resort to mouse clicks and menu commands then.
Apache OpenOffice 4.1.13 on ArcaOS 5.0.7
User avatar
Lupp
Volunteer
Posts: 3530
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: Draw: "Insert File" into file

Post by Lupp »

I never work with Draw documents unambiguously belonging one of your "cases".
Or are you talking of a currently selected shape?
Or... In what way, precisely, would you distinguish the cases?
Anyway: Simply select your case with a helper function, and set the DrawPage index you actually need to the respective value.
Mainly: I don't know a way to copy/paste a DrawPage object itself. You will need to either create a temporary group making a single shape of the content of the page needing to be copied and pasted, or to copy/paste all the shapes of that page one by one as I demonstrated.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
ms777
Volunteer
Posts: 176
Joined: Mon Oct 08, 2007 1:33 am

Re: Draw: "Insert File" into file

Post by ms777 »

5. The alternative approach didn't run for me.
XTransferableSupplier seems not to be implemented for Draw docs, see https://bugs.documentfoundation.org/sho ... ?id=151713
JeJe
Volunteer
Posts: 2730
Joined: Wed Mar 09, 2016 2:40 pm

Re: Draw: "Insert File" into file

Post by JeJe »

controller.model.getTransferData
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
Lupp
Volunteer
Posts: 3530
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: Draw: "Insert File" into file

Post by Lupp »

¡¿aha?!
Since the number of downloads of my first attachment shows some interest, i attacfh also an enhanced example containig a working solution based on the group/ungroup idea:
aoo111169enhancedDemoCopyInsertDrawpage.odg
(15.36 KiB) Downloaded 23 times
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
Post Reply