Impress - Duplicating master slides with a macro

Hello,
using LibO Version: 7.3.6.2 / LibreOffice Community
Build ID: c28ca90fd6e1a19e189fc16c05f8f8924961e12e
CPU threads: 4; OS: Linux 5.4; UI render: default; VCL: gtk3
Locale: fr-FR (fr_FR.UTF-8); UI: fr-FR
Calc: threaded

OS is LinuxMint 20.3 (Cinnamon)

I’d like to create a macro in Basic for Impress that would duplicate an existing masterslide. This would be a workaround to the missing “Copy” option that exists in the UI for standard slides but not for masterslides.

I found that Impress documents expose the .Duplicate() method, as documented here:
https://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1drawing_1_1XDrawPageDuplicator.html

where one can read:

creates a duplicate of a DrawPage or MasterPage, including the Shapes on that page and inserts it into the same model.

Unfortunately, I can’t make this method to work with master slides. Any attempt results in actually duplicating the referenced standard slide instead of the master slide. The attached demo shows the ill-behaved code TestODP_duplicates.odp (14.6 KB).

Am I missing something? Or is it a bug of sorts?

indeed, both lines copy the same (normal) slide.

ThisComponent.duplicate(ThisComponent.getDrawPages().getByIndex(0))
ThisComponent.duplicate(ThisComponent.getMasterPages().getByIndex(0))

Thanks.
I found that a bug is already opened (for the UI part). I’ve updated that 10yrs old bug, here:
https://bugs.documentfoundation.org/show_bug.cgi?id=45617

I know this is not exactly the solution you wanted, but I did find a workaround for duplicating master slides without using a Macro. First, save your presentation as a template using: File → Templates → Save as Template. Then, create a new regular slide and do Slide → Change Slide Master and click the Load button. Find the template you created earlier and choose the master slide you want to duplicate. After clicking OK, the master slide will be duplicated when you go to the slide masters view where you can rename it and modify it.

Thanks Stephen.
I know of UI use for the duplication task.

I just want to mimic it using macros… :slight_smile:

Thanks anyway. Your suggestion might be of use to others not wanting to bother about macros.