Manage SmartArt in PowerPoint Presentations Using C++

Overview

SmartArt is a PowerPoint diagram made from nodes, node shapes, and a layout. With Aspose.Slides for C++, you can create SmartArt, read text from its nodes, change its layout, inspect hidden nodes, configure organization chart layouts, and create picture organization charts.

Get Text from a SmartArt Object

A SmartArt node can contain one or more shapes. To read the visible text, iterate through ISmartArt::get_AllNodes, then read the ITextFrame returned by ISmartArtShape::get_TextFrame.

auto presentation = System::MakeObject<Presentation>(u"sample.pptx");
auto slide = presentation->get_Slide(0);
auto shape = slide->get_Shape(0);

if (System::ObjectExt::Is<ISmartArt>(shape))
{
    auto smartArt = System::ExplicitCast<ISmartArt>(shape);

    for (int nodeIndex = 0; nodeIndex < smartArt->get_AllNodes()->get_Count(); nodeIndex++)
    {
        auto node = smartArt->get_AllNodes()->idx_get(nodeIndex);

        for (int shapeIndex = 0; shapeIndex < node->get_Shapes()->get_Count(); shapeIndex++)
        {
            auto nodeShape = node->get_Shape(shapeIndex);

            if (nodeShape->get_TextFrame() != nullptr)
            {
                System::Console::WriteLine(nodeShape->get_TextFrame()->get_Text());
            }
        }
    }
}

presentation->Dispose();

Change the Layout Type of a SmartArt Object

The SmartArt layout controls how nodes are arranged and connected. The following example creates a SmartArt object with the SmartArtLayoutType BasicBlockList value, changes it to the BasicProcess value, and saves the presentation.

auto presentation = System::MakeObject<Presentation>();

auto smartArt = presentation->get_Slide(0)->get_Shapes()->AddSmartArt(
    10.0f, 10.0f, 400.0f, 300.0f, SmartArtLayoutType::BasicBlockList);

smartArt->set_Layout(SmartArtLayoutType::BasicProcess);

presentation->Save(u"ChangeSmartArtLayout_out.pptx", SaveFormat::Pptx);
presentation->Dispose();

Check Whether a SmartArt Node Is Hidden

ISmartArtNode::get_IsHidden indicates whether the node is hidden in the SmartArt data model. Hidden nodes can exist in the structure even when the selected layout does not display them as visible diagram elements.

The following example adds a node to a SmartArt object that uses the SmartArtLayoutType RadialCycle value and checks the node’s hidden state.

auto presentation = System::MakeObject<Presentation>();

auto smartArt = presentation->get_Slide(0)->get_Shapes()->AddSmartArt(
    10.0f, 10.0f, 400.0f, 300.0f, SmartArtLayoutType::RadialCycle);

auto node = smartArt->get_AllNodes()->AddNode();
bool isHidden = node->get_IsHidden();

if (isHidden)
{
    System::Console::WriteLine(u"The node is hidden in the SmartArt data model.");
}

presentation->Save(u"CheckSmartArtHiddenProperty_out.pptx", SaveFormat::Pptx);
presentation->Dispose();

Get or Set the Organization Chart Layout

For SmartArt diagrams that use an organization chart layout, ISmartArtNode::get_OrganizationChartLayout and ISmartArtNode::set_OrganizationChartLayout define how child nodes are arranged under a parent node. For example, you can set child nodes to hang from the left, right, or both sides, depending on the selected OrganizationChartLayoutType.

The following example creates an organization chart and sets the layout for the first node to the OrganizationChartLayoutType LeftHanging value.

auto presentation = System::MakeObject<Presentation>();

auto smartArt = presentation->get_Slide(0)->get_Shapes()->AddSmartArt(
    10.0f, 10.0f, 400.0f, 300.0f, SmartArtLayoutType::OrganizationChart);

auto rootNode = smartArt->get_Node(0);
rootNode->set_OrganizationChartLayout(OrganizationChartLayoutType::LeftHanging);

presentation->Save(u"OrganizationChartLayout_out.pptx", SaveFormat::Pptx);
presentation->Dispose();

Create a Picture Organization Chart

A picture organization chart is a SmartArt layout designed for hierarchy diagrams that include image placeholders. Use the SmartArtLayoutType PictureOrganizationChart value when adding the SmartArt object to a slide.

auto presentation = System::MakeObject<Presentation>();

auto smartArt = presentation->get_Slide(0)->get_Shapes()->AddSmartArt(
    0.0f, 0.0f, 400.0f, 400.0f, SmartArtLayoutType::PictureOrganizationChart);

presentation->Save(u"PictureOrganizationChart_out.pptx", SaveFormat::Pptx);
presentation->Dispose();

FAQ

Does SmartArt support mirroring or reversing for RTL languages?

Yes. The SmartArt::set_IsReversed method switches the diagram direction from left-to-right to right-to-left, or back, when the selected SmartArt layout supports reversal.

How can I copy SmartArt to the same slide or to another presentation while preserving formatting?

You can clone the SmartArt shape with ShapeCollection::AddClone or clone the whole slide that contains the SmartArt. Both approaches preserve size, position, and formatting.

How do I render SmartArt to a raster image for preview or web export?

Render the slide or the whole presentation to PNG or JPEG. SmartArt is rendered as part of the slide.

How can I find a specific SmartArt object on a slide if there are several?

Set a distinctive Shape::set_AlternativeText or Shape::set_Name value on the SmartArt shape, search for that value in BaseSlide::get_Shapes, and then check that the matching shape is an ISmartArt.