pzajk
Sep 21, 2023Brass Contributor
Status:
New
[PowerPoint javascript API] Add event listener for objects removed from slide
With the current version of Office js API it is not possible to track whether an object was removed from the slide.
Would it be possible to have an event listener triggered when object is removed from the slide or when slide itself is removed? Ideally this event should return data about removed object.
use case: User removes image directly from the slide, currently corresponding object in the add-in will still be present as we are not able to detect removed objects
1 Comment
- FromTheArcticCopper Contributor
Although there is nothing in office.js that supports this directly, you should be able to achieve what you need by using
Office.context.document.addHandlerAsync(Office.EventType.DocumentSelectionChangedThis allows you to run a function every time a selection change happens. If your add-in keeps track of all shapes (usingconst slide = context.presentation.slides.getItemAt(<currently selected slide index);const shapes = slide.shapes;// Load all the shapes in the collection without loading their properties.shapes.load("items/Name");) you can detect a removal by comparing to the previous set of shapes. As part of that comparison you can then get the data of the removed shape (for example its Name in the example above)