Working with PowerPoint SmartArt
10 Sep 202423 minutes to read
A SmartArt diagram is a visual representation of your information, to effectively communicate your ideas in presentations. You can add and modify the SmartArt diagrams in PowerPoint presentations using Essential Presentation library.
To quickly start creating a SmartArt in a PowerPoint Presentation using .NET PowerPoint library, please check out this video:
Adding SmartArt to a Slide
You can add any of the predefined SmartArt diagrams to PowerPoint Presentation. The following code example demonstrates adding a SmartArt to a Slide.
// Create an instance of PowerPoint Presentation
IPresentation pptxDoc = Presentation.Create();
//Add a blank slide to the Presentation
ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.Blank);
//Add a BasicBlockList SmartArt to the slide at the specified size and position.
ISmartArt smartArt = slide.Shapes.AddSmartArt(SmartArtType.BasicBlockList, 0, 0, 640, 426);
//Save the PowerPoint Presentation as stream
FileStream outputStream = new FileStream("SmartArt.pptx", FileMode.Create);
pptxDoc.Save(outputStream);
//Close the Presentation
pptxDoc.Close();
// Create an instance of PowerPoint Presentation
IPresentation pptxDoc = Presentation.Create();
//Add a blank slide to the Presentation
ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.Blank);
//Add a BasicBlockList SmartArt to the slide at the specified size and position.
ISmartArt smartArt = slide.Shapes.AddSmartArt(SmartArtType.BasicBlockList, 0, 0, 640, 426);
//Save the Presentation
pptxDoc.Save("SmartArt.pptx");
//Close the Presentation
pptxDoc.Close();
'Create an instance of PowerPoint Presentation
Dim pptxDoc As IPresentation = Presentation.Create()
'Add a blank slide to the Presentation
Dim slide As ISlide = pptxDoc.Slides.Add(SlideLayoutType.Blank)
'Add a BasicBlockList SmartArt to the slide at the specified size and position.
Dim smartArt As ISmartArt = slide.Shapes.AddSmartArt(SmartArtType.BasicBlockList, 0, 0, 640, 426)
'Save the Presentation
pptxDoc.Save("SmartArt.pptx")
'Close the Presentation
pptxDoc.Close()
You can download a complete working sample from GitHub.
Adding a node to the SmartArt
You can add a new node to the SmartArt diagram. The following code example demonstrates the same.
// Create an instance of PowerPoint Presentation
IPresentation pptxDoc = Presentation.Create();
//Add a blank slide to the Presentation
ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.Blank);
//Add a SmartArt to the slide at the specified size and position
ISmartArt smartArt = slide.Shapes.AddSmartArt(SmartArtType.AlternatingHexagons, 0, 0, 640, 426);
// Add a new node to the SmartArt.
ISmartArtNode newNode = smartArt.Nodes.Add();
// Set the text to the newly added node.
newNode.TextBody.AddParagraph("New main node added.");
//Save the PowerPoint Presentation as stream
FileStream outputStream = new FileStream("SmartArt.pptx", FileMode.Create);
pptxDoc.Save(outputStream);
//Close the Presentation.
pptxDoc.Close();
// Create an instance of PowerPoint Presentation
IPresentation pptxDoc = Presentation.Create();
//Add a blank slide to the Presentation
ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.Blank);
//Add a SmartArt to the slide at the specified size and position
ISmartArt smartArt = slide.Shapes.AddSmartArt(SmartArtType.AlternatingHexagons, 0, 0, 640, 426);
// Add a new node to the SmartArt.
ISmartArtNode newNode = smartArt.Nodes.Add();
// Set the text to the newly added node.
newNode.TextBody.AddParagraph("New main node added.");
//Save the Presentation.
pptxDoc.Save("SmartArt.pptx");
//Close the Presentation.
pptxDoc.Close();
'Create an instance of PowerPoint Presentation
Dim pptxDoc As IPresentation = Presentation.Create()
'Add a blank slide to the Presentation
Dim slide As ISlide = pptxDoc.Slides.Add(SlideLayoutType.Blank)
'Add a SmartArt to the slide at the specified size and position
Dim smartArt As ISmartArt = slide.Shapes.AddSmartArt(SmartArtType.AlternatingHexagons, 0, 0, 640, 426)
'Add a new node to the SmartArt.
Dim newNode As ISmartArtNode = smartArt.Nodes.Add()
'Set the text to the newly added node.
newNode.TextBody.AddParagraph("New main node added.")
'Save the Presentation.
pptxDoc.Save("SmartArt.pptx")
'Close the Presentation.
pptxDoc.Close()
You can download a complete working sample from GitHub.
In SmartArt diagrams, you can also add nodes to several nested levels. The maximum limit of nested levels may vary based on SmartArt types. The following code example demonstrates adding nested level nodes in a SmartArt.
// Create an instance of PowerPoint Presentation
IPresentation pptxDoc = Presentation.Create();
//Add a blank slide to the Presentation
ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.Blank);
//Add a SmartArt to the slide at the specified size and position.
ISmartArt smartArt = slide.Shapes.AddSmartArt(SmartArtType.AlternatingHexagons, 0, 0, 640, 426);
// Add a new node to the SmartArt.
ISmartArtNode newNode = smartArt.Nodes.Add();
// Add a child node to the SmartArt node
ISmartArtNode childNode = newNode.ChildNodes.Add();
// Set a text to newly added child node.
childNode.TextBody.AddParagraph("Child node of the existing node.");
//Save the PowerPoint Presentation as stream
FileStream outputStream = new FileStream("SmartArt.pptx", FileMode.Create);
pptxDoc.Save(outputStream);
//Close the Presentation.
pptxDoc.Close();
// Create an instance of PowerPoint Presentation
IPresentation pptxDoc = Presentation.Create();
//Add a blank slide to the Presentation
ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.Blank);
//Add a SmartArt to the slide at the specified size and position.
ISmartArt smartArt = slide.Shapes.AddSmartArt(SmartArtType.AlternatingHexagons, 0, 0, 640, 426);
// Add a new node to the SmartArt.
ISmartArtNode newNode = smartArt.Nodes.Add();
// Add a child node to the SmartArt node
ISmartArtNode childNode = newNode.ChildNodes.Add();
// Set a text to newly added child node.
childNode.TextBody.AddParagraph("Child node of the existing node.");
//Save the Presentation.
pptxDoc.Save("SmartArt.pptx");
//Close the Presentation.
pptxDoc.Close();
'Create an instance of PowerPoint Presentation
Dim pptxDoc As IPresentation = Presentation.Create()
'Add a blank slide to the Presentation
Dim slide As ISlide = pptxDoc.Slides.Add(SlideLayoutType.Blank)
'Add a SmartArt to the slide at the specified size and position.
Dim smartArt As ISmartArt = slide.Shapes.AddSmartArt(SmartArtType.AlternatingHexagons, 0, 0, 640, 426)
'Add a new node to the SmartArt.
Dim newNode As ISmartArtNode = smartArt.Nodes.Add()
'Add a child node to the SmartArt node
Dim childNode As ISmartArtNode = newNode.ChildNodes.Add()
'Set a text to newly added child node.
childNode.TextBody.AddParagraph("Child node of the existing node.")
'Save the Presentation.
pptxDoc.Save("SmartArt.pptx")
'Close the Presentation.
pptxDoc.Close()
You can download a complete working sample from GitHub.
Modifying SmartArt appearance
You can modify the SmartArt appearance by modifying the fill type, color, transparency etc. The below code example demonstrates modifying the appearance of SmartArt nodes.
//Loads or open an PowerPoint Presentation
FileStream inputStream = new FileStream("Sample.pptx",FileMode.Open);
IPresentation pptxDoc = Presentation.Open(inputStream);
//Get the Slide from Presentation
ISlide slide = pptxDoc.Slides[0];
//Get the SmartArt from Slide.
ISmartArt smartArt = slide.Shapes[0] as ISmartArt;
//Get the first node
ISmartArtNode firstNode = smartArt.Nodes[0];
// Set the text content of node.
firstNode.TextBody.AddParagraph("First Node");
//Set the fill type of node.
firstNode.Shapes[0].Fill.FillType = FillType.Solid;
// Set the fill color of node.
firstNode.Shapes[0].Fill.SolidFill.Color = ColorObject.GreenYellow;
//Set transparency value of fill
firstNode.Shapes[0].Fill.SolidFill.Transparency = 30;
//Save the PowerPoint Presentation as stream
FileStream outputStream = new FileStream("SmartArt.pptx", FileMode.Create);
pptxDoc.Save(outputStream);
//Close the Presentation.
pptxDoc.Close();
//Open a PowerPoint Presentation
IPresentation pptxDoc = Presentation.Open("SampleDocument.pptx");
//Get the Slide from Presentation
ISlide slide = pptxDoc.Slides[0];
//Get the SmartArt from Slide.
ISmartArt smartArt = slide.Shapes[0] as ISmartArt;
//Get the first node
ISmartArtNode firstNode = smartArt.Nodes[0];
// Set the text content of node.
firstNode.TextBody.AddParagraph("First Node");
//Set the fill type of node.
firstNode.Shapes[0].Fill.FillType = FillType.Solid;
// Set the fill color of node.
firstNode.Shapes[0].Fill.SolidFill.Color = ColorObject.GreenYellow;
//Set transparency value of fill
firstNode.Shapes[0].Fill.SolidFill.Transparency = 30;
//Save the Presentation.
pptxDoc.Save("SmartArt.pptx");
//Close the Presentation.
pptxDoc.Close();
'Open a PowerPoint Presentation
Dim pptxDoc As IPresentation = Presentation.Open("SampleDocument.pptx")
'Get the Slide from Presentation
Dim slide As ISlide = pptxDoc.Slides(0)
'Get the SmartArt from Slide.
Dim smartArt As ISmartArt = TryCast(slide.Shapes(0), ISmartArt)
'Get the first node
Dim firstNode As ISmartArtNode = smartArt.Nodes(0)
' Set the text content of node.
firstNode.TextBody.AddParagraph("First Node")
'Set the fill type of node.
firstNode.Shapes(0).Fill.FillType = FillType.Solid
' Set the fill color of node.
firstNode.Shapes(0).Fill.SolidFill.Color = ColorObject.GreenYellow
'Set transparency value of fill
firstNode.Shapes(0).Fill.SolidFill.Transparency = 30
'Save the Presentation.
pptxDoc.Save("SmartArt.pptx")
'Close the Presentation.
pptxDoc.Close()
You can download a complete working sample from GitHub.
Iterating through child nodes of an existing SmartArt
You can iterate through the child nodes and access the properties of each node in a SmartArt. The following code example demonstrates accessing and modifying the text content of node.
//Loads or open an PowerPoint Presentation
FileStream inputStream = new FileStream("Sample.pptx",FileMode.Open);
IPresentation pptxDoc = Presentation.Open(inputStream);
//Traverse through shape in the first slide.
foreach (IShape shape in pptxDoc.Slides[0].Shapes)
{
if (shape is ISmartArt)
{
//Traverse through all nodes inside SmartArt
foreach (ISmartArtNode mainNode in (shape as ISmartArt).Nodes)
{
if (mainNode.TextBody.Text == "Old Content")
//Change the node content
mainNode.TextBody.Paragraphs[0].TextParts[0].Text = "New Content";
}
}
}
//Save the PowerPoint Presentation as stream
FileStream outputStream = new FileStream("SmartArt.pptx", FileMode.Create);
pptxDoc.Save(outputStream);
//Close the Presentation.
pptxDoc.Close();
//Open a PowerPoint Presentation
IPresentation pptxDoc = Presentation.Open("SampleDocument.pptx");
//Traverse through shape in the first slide.
foreach (IShape shape in pptxDoc.Slides[0].Shapes)
{
if (shape is ISmartArt)
{
//Traverse through all nodes inside SmartArt
foreach (ISmartArtNode mainNode in (shape as ISmartArt).Nodes)
{
if (mainNode.TextBody.Text == "Old Content")
//Change the node content
mainNode.TextBody.Paragraphs[0].TextParts[0].Text = "New Content";
}
}
}
//Save the Presentation.
pptxDoc.Save("SmartArt.pptx");
//Close the Presentation.
pptxDoc.Close();
'Open a PowerPoint Presentation
Dim pptxDoc As IPresentation = Presentation.Open("SampleDocument.pptx")
'Traverse through shape in the first slide.
For Each shape As IShape In pptxDoc.Slides(0).Shapes
If TypeOf shape Is ISmartArt Then
'Traverse through all nodes inside SmartArt
For Each mainNode As ISmartArtNode In TryCast(shape, ISmartArt).Nodes
If mainNode.TextBody.Text = "Old Content" Then
'Change the node content
mainNode.TextBody.Paragraphs(0).TextParts(0).Text = "New Content"
End If
Next
End If
Next
'Save the Presentation.
pptxDoc.Save("SmartArt.pptx")
'Close the Presentation.
pptxDoc.Close()
You can download a complete working sample from GitHub.
Removing node from an existing SmartArt
You can remove a node from the SmartArt diagram. The following code example demonstrates the same.
//Loads or open an PowerPoint Presentation
FileStream inputStream = new FileStream("Sample.pptx",FileMode.Open);
IPresentation pptxDoc = Presentation.Open(inputStream);
//Get the first slide from the Presentation.
ISlide slide = pptxDoc.Slides[0];
//Get the SmartArt from slide.
ISmartArt smartArt = slide.Shapes[0] as ISmartArt;
//Remove a node at the specified index.
smartArt.Nodes.RemoveAt(4);
//Save the PowerPoint Presentation as stream
FileStream outputStream = new FileStream("SmartArt.pptx", FileMode.Create);
pptxDoc.Save(outputStream);
//Close the Presentation.
pptxDoc.Close();
//Open a PowerPoint Presentation
IPresentation pptxDoc = Presentation.Open("SampleDocument.pptx");
//Get the first slide from the Presentation.
ISlide slide = pptxDoc.Slides[0];
//Get the SmartArt from slide.
ISmartArt smartArt = slide.Shapes[0] as ISmartArt;
//Remove a node at the specified index.
smartArt.Nodes.RemoveAt(4);
//Save the Presentation.
pptxDoc.Save("SmartArt.pptx");
//Close the Presentation.
pptxDoc.Close();
'Open a PowerPoint Presentation
Dim pptxDoc As IPresentation = Presentation.Open("SampleDocument.pptx")
'Get the first slide from the Presentation.
Dim slide As ISlide = pptxDoc.Slides(0)
'Get the SmartArt from slide.
Dim smartArt As ISmartArt = TryCast(slide.Shapes(0), ISmartArt)
'Remove a node at the specified index.
smartArt.Nodes.RemoveAt(4)
'Save the Presentation.
pptxDoc.Save("SmartArt.pptx")
'Close the Presentation.
pptxDoc.Close()
You can download a complete working sample from GitHub.
Assistant nodes in SmartArt
You can check whether a node is an assistant or not. Also you can change a node as assistant node or revert an assistant node to normal node. The following code example demonstrates making an assistant node as normal node.
// Create an instance of PowerPoint Presentation
IPresentation pptxDoc = Presentation.Create();
//Add a blank slide to the Presentation
ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.Blank);
//Add a SmartArt to the slide at the specified size and position
ISmartArt smartArt = slide.Shapes.AddSmartArt(SmartArtType.OrganizationChart, 0, 0, 640, 426.96);
//Traverse through all nodes of the SmartArt.
foreach (ISmartArtNode node in smartArt.Nodes)
{
//Check if the node is assistant or not.
if (node.IsAssistant)
//Set the assistant node to false.
node.IsAssistant = false;
}
//Save the PowerPoint Presentation as stream
FileStream outputStream = new FileStream("SmartArt.pptx", FileMode.Create);
pptxDoc.Save(outputStream);
//Close the Presentation.
pptxDoc.Close();
// Create an instance of PowerPoint Presentation
IPresentation pptxDoc = Presentation.Create();
//Add a blank slide to the Presentation
ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.Blank);
//Add a SmartArt to the slide at the specified size and position
ISmartArt smartArt = slide.Shapes.AddSmartArt(SmartArtType.OrganizationChart, 0, 0, 640, 426.96);
//Traverse through all nodes of the SmartArt.
foreach (ISmartArtNode node in smartArt.Nodes)
{
//Check if the node is assistant or not.
if (node.IsAssistant)
//Set the assistant node to false.
node.IsAssistant = false;
}
//Save the Presentation.
pptxDoc.Save("Sample.pptx");
//Close the Presentation.
pptxDoc.Close();
'Create an instance of PowerPoint Presentation
Dim pptxDoc As IPresentation = Presentation.Create()
'Add a blank slide to the Presentation
Dim slide As ISlide = pptxDoc.Slides.Add(SlideLayoutType.Blank)
'Add a SmartArt to the slide at the specified size and position
Dim smartArt As ISmartArt = slide.Shapes.AddSmartArt(SmartArtType.OrganizationChart, 0, 0, 640, 426.96)
'Traverse through all nodes of the SmartArt.
For Each node As ISmartArtNode In smartArt.Nodes
'Check if the node is assistant or not.
If node.IsAssistant Then
'Set the assistant node to false.
node.IsAssistant = False
End If
Next
'Save the Presentation.
pptxDoc.Save("Sample.pptx")
'Close the Presentation.
pptxDoc.Close()
Limitations
The modifications in a SmartArt (like add/remove nodes, modify position and size of nodes etc., which involve SmartArt layout changes) done by Essential Presentation will not reflected in Image and PDF conversion. Whereas layout changes will be reflected properly in the generated PPTX file when opened using Microsoft PowerPoint.
Supported SmartArt layout types
- Basic Block List
- Alternating Hexagons
- Picture Caption List
- Lined List
- Vertical Bullet List
- Vertical Box List
- Horizontal Bullet List
- Square Accent List
- Picture Accent List
- Bending Picture Accent List
- Stacked List
- Increasing Circle Process
- Pie Process
- Detailed Process
- Grouped List
- Horizontal Picture List
- Continuous Picture List
- Picture Strips
- Vertical Picture List
- Alternating Picture Blocks
- Vertical Picture Accent List
- Titled Picture Accent List
- Vertical Block List
- Vertical Chevron List
- Vertical Accent List
- Vertical Arrow List
- Trapezoid List
- Descending Block List
- Table List
- Segmented Process
- Vertical Curved List
- Pyramid List
- Target List
- Vertical Circle List
- Table Hierarchy
- Basic Process
- Step Up Process
- Step Down Process
- Accent Process
- Alternating Flow
- Continuous Block Process
- Increasing Arrows Process
- Continuous Arrow Process
- Process Arrows
- Circle Accent Time Line
- Basic Time Line
- Basic Chevron Process
- Closed Chevron Process
- Chevron List
- Sub-Step Process
- Phased Process
- Random to Result Process
- Staggered Process
- Process List
- Circle Arrow Process
- Basic Bending Process
- Vertical Bending Process
- Ascending Picture Accent Process
- Upward Arrow
- Descending Process
- Circular Bending Process
- Equation
- Vertical Equation
- Funnel
- Gear
- Arrow Ribbon
- Opposing Arrows
- Converging Arrows
- Diverging Arrows
- Basic Cycle
- Text Cycle
- Block Cycle
- Non directional Cycle
- Continuous Cycle
- Multi Directional Cycle
- Segmented Cycle
- Basic Pie
- Radial Cycle
- Basic Radial
- Diverging Radial
- Radial Venn
- Radial Cluster
- Organization Chart
- Name and Title Organization Chart
- Half Circle Organization Chart
- Circle Picture hierarchy
- Hierarchy
- Labeled Hierarchy
- Horizontal Organization Chart
- Horizontal Multi-Level Hierarchy
- Horizontal Hierarchy
- Horizontal Labeled Hierarchy
- Balance
- Circle Relationship
- Hexagon Cluster
- Opposing Ideas
- Plus and Minus
- Reverse List
- Counter Balance Arrows
- Segmented Pyramid
- Nested Target
- Converging Radial
- Radial List
- Basic Target
- Basic Matrix
- Titled Matrix
- Grid Matrix
- Cycle Matrix
- Accent Picture
- Circular Picture Callout
- Snapshot Picture List
- Spiral Picture
- Captioned Pictures
- Bending Picture Caption
- Bending Picture-Semi Transparent Text
- Bending Picture Blocks
- Bending Picture Caption List
- Titled Picture Blocks
- Picture Grid
- Picture Accent Blocks
- Alternating Picture Circles
- Title Picture Lineup
- Picture Lineup
- Framed Text Picture
- Bubble Picture List
- Basic Pyramid
- Inverted Pyramid
- Basic Venn
- Linear Venn
- Stacked Venn
- Hierarchy List
- Picture Accent Process
- Repeating Bending Process
- Vertical Process