Page 1 of 1

[Solved] Draw: "Insert File" into document

Posted: Thu Jan 25, 2024 7:09 pm
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.

Re: Draw: "Insert File" into file

Posted: Tue Jan 30, 2024 11:20 am
by Bidouille

Re: Draw: "Insert File" into file

Posted: Mon Feb 05, 2024 4:25 pm
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...)?

Re: Draw: "Insert File" into file

Posted: Mon Feb 05, 2024 4:39 pm
by jep
I've decided to write code to do it, but how can one select to display a certain page?

Re: Draw: "Insert File" into file

Posted: Mon Feb 05, 2024 4:43 pm
by jep
self~XDispatchHelper~executeDispatch( self~xDoc~XModel~getCurrentController~getFrame~XDispatchProvider, ".uno:Intersect", "", 0, .UNO~noProps )

I use this code to call "Intersect".

Re: Draw: "Insert File" into file

Posted: Tue Feb 06, 2024 4:15 pm
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

Re: Draw: "Insert File" into file

Posted: Wed Feb 07, 2024 11:59 pm
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 241 times

Re: Draw: "Insert File" into file

Posted: Thu Feb 08, 2024 5:27 pm
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.

Re: Draw: "Insert File" into file

Posted: Thu Feb 08, 2024 5:39 pm
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.

Re: Draw: "Insert File" into file

Posted: Thu Feb 08, 2024 5:40 pm
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.

Re: Draw: "Insert File" into file

Posted: Sat Feb 10, 2024 2:08 pm
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

Re: Draw: "Insert File" into file

Posted: Sat Feb 10, 2024 9:54 pm
by JeJe
controller.model.getTransferData

Re: Draw: "Insert File" into file

Posted: Sun Feb 11, 2024 9:24 pm
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 633 times