Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active October 5, 2021 17:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/0306bb6e0ef50710e2a4afb0e7261b10 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/0306bb6e0ef50710e2a4afb0e7261b10 to your computer and use it in GitHub Desktop.
Create SmartArt in PowerPoint Presentations using C++
// File path
const String sourceFilePath = u"OutputDirectory\\CreateSmartArt_out.pptx";
// Load the Presentation file
SharedPtr<Presentation> presentation = MakeObject<Presentation>(sourceFilePath);
// Loop through the shapes
for (auto shape : presentation->get_Slides()->idx_get(0)->get_Shapes())
{
// Check if shape is of SmartArt type
if (System::ObjectExt::Is<Aspose::Slides::SmartArt::SmartArt>(shape))
{
// Typecast shape to SmartArt
auto smartArt = System::DynamicCast_noexcept<ISmartArt>(shape);
Console::WriteLine(String::Format(u"Shape Name: {0}", smartArt->get_Name()));
// Checking SmartArt Layout
/*if (smartArt->get_Layout() == SmartArtLayoutType::BasicBlockList)
{
Console::WriteLine(u"Do some thing here....");
}*/
}
}
// File paths
const String sourceFilePath = u"OutputDirectory\\CreateSmartArt_out.pptx";
const String outputFilePath = u"OutputDirectory\\ChangeSmartArt_out.pptx";
// Load the Presentation file
SharedPtr<Presentation> presentation = MakeObject<Presentation>(sourceFilePath);
// Loop through the shapes
for (auto shape : presentation->get_Slides()->idx_get(0)->get_Shapes())
{
// Check if shape is of SmartArt type
if (System::ObjectExt::Is<Aspose::Slides::SmartArt::SmartArt>(shape))
{
// Typecast shape to SmartArt
auto smartArt = System::DynamicCast_noexcept<ISmartArt>(shape);
// Check SmartArt style
if (smartArt->get_QuickStyle() == SmartArtQuickStyleType::SimpleFill) {
// Change SmartArt Style
smartArt->set_QuickStyle(SmartArtQuickStyleType::Cartoon);
}
// Check SmartArt color type
if (smartArt->get_ColorStyle() == SmartArtColorType::ColoredFillAccent1) {
// Change SmartArt color type
smartArt->set_ColorStyle(SmartArtColorType::ColorfulAccentColors);
}
}
}
// Save Presentation
presentation->Save(outputFilePath, Aspose::Slides::Export::SaveFormat::Pptx);
// File path
const String outputFilePath = u"OutputDirectory\\CreateSmartArt_out.pptx";
// Load the Presentation file
SharedPtr<Presentation> presentation = MakeObject<Presentation>();
// Retrieve the first slide
SharedPtr<ISlide> slide = presentation->get_Slides()->idx_get(0);
// Add SmartArt
auto smartArt = slide->get_Shapes()->AddSmartArt(0, 0, 400, 400, Aspose::Slides::SmartArt::SmartArtLayoutType::BasicBlockList);
smartArt->get_AllNodes()->idx_get(0)->get_TextFrame()->set_Text(u"First Block");
smartArt->get_AllNodes()->idx_get(1)->get_TextFrame()->set_Text(u"Second Block");
// Save Presentation
presentation->Save(outputFilePath, Aspose::Slides::Export::SaveFormat::Pptx);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment