Skip to main content

Create slides from list items

Creates new slides based on the listed items in the current slide. Each list item becomes a slide title.

(function () {
let presentation = Api.GetPresentation();
let activeSlideIndex = presentation.GetCurSlideIndex();
let slide = presentation.GetSlideByIndex(activeSlideIndex);
let fill = Api.CreateSolidFill(Api.CreateRGBColor(51, 51, 51));

if (!slide) {
console.error("No slide is currently selected");
return;
}

function processShapes(shapes, startIndex = 0, numberedItems = []) {
if (startIndex >= shapes.length) {
return numberedItems;
}

let shape = shapes[startIndex];

if (shape.GetContent && shape.GetClassType() === "shape") {
function processParagraphs(content, paraIndex = 0) {
if (paraIndex >= content.GetElementsCount()) {
return;
}

let paragraph = content.GetElement(paraIndex);
let text = paragraph.GetText();

if (paragraph.GetParaPr().GetIndLeft() > 0) {
numberedItems.push(text.trim());
}

processParagraphs(content, paraIndex + 1);
}

let content = shape.GetContent();
processParagraphs(content);
}
return processShapes(shapes, startIndex + 1, numberedItems);
}
function createSlides(items, index = 0) {
if (index >= items.length) {
return;
}

let newSlide = Api.CreateSlide();
presentation.AddSlide(newSlide);

let slideWidth = presentation.GetWidth();
let slideHeight = presentation.GetHeight();

let shapeWidth = slideWidth * 0.7; // Ajdust this value to your liking
let shapeHeight = slideHeight * 0.25; // Adjust this value to your liking

let posX = (slideWidth - shapeWidth) / 2; // Centered, adjust this value to your liking
let posY = slideHeight * 0.1; // On top, adjust this value to your liking

let subtitleShape = Api.CreateShape("rect", shapeWidth, shapeHeight);

subtitleShape.SetPosition(posX, posY);

let placeholder = Api.CreatePlaceholder("subtitle");
subtitleShape.SetPlaceholder(placeholder);

let content = subtitleShape.GetContent();
if (content) {
content.RemoveAllElements();

let newParagraph = Api.CreateParagraph();
let newRun = Api.CreateRun();
let newTextPr = newRun.GetTextPr();
newTextPr.SetFontSize(50);
newTextPr.SetFill(fill);
newRun.AddText(items[index]);
newParagraph.AddElement(newRun);
content.Push(newParagraph);
}

newSlide.AddObject(subtitleShape);

createSlides(items, index + 1);
}

let shapes = slide.GetAllShapes();
let numberedItems = processShapes(shapes);

if (numberedItems.length === 0) {
return;
}

createSlides(numberedItems);
})();

Methods used: GetPresentation, GetCurSlideIndex, GetSlideByIndex, CreateSolidFill, CreateRGBColor, GetClassType, GetElementsCount, GetElement, GetParaPr, GetIndLeft, GetContent, CreateSlide, AddSlide, GetWidth, GetHeight, CreateShape, SetPosition, CreatePlaceholder, SetPlaceholder, RemoveAllElements, CreateParagraph, CreateRun, GetTextPr, SetFontSize, SetFill, AddText, AddElement, Push, AddObject, GetAllShapes

Result

CreateSimilarSlides CreateSimilarSlides