How to remove a specific node by position from SmartArt in PowerPoint

Spire.Presentation for .NET provides two flexible methods: RemoveNode() and RemoveNodeByPosition() for developers to remove nodes from SmartArt. In this article, we will learn how to remove a specific node by position from SmartArt in PowerPoint using the RemoveNodeByPosition() method.

Below is the screenshot of the original SmartArt:

How to remove a specific node by position from SmartArt in PowerPoint

Detail steps:

Step 1: Create a new instance of Presentation class and load the PPT file.

Presentation presentation = new Presentation();
presentation.LoadFromFile("SmartArt.pptx");

Step 2: Get the SmartArt and collect nodes.

ISmartArt smartart = presentation.Slides[0].Shapes[0] as ISmartArt;
ISmartArtNodeCollection nodes = smartart.Nodes;

Step 3: Call nodes.RemoveNodeByPosition(int position) method to remove the specific node by position.

nodes.RemoveNodeByPosition(0);

Step 4: Save the file to disk.

presentation.SaveToFile("RemoveNodes.pptx", FileFormat.Pptx2010);

Running the project, we'll get the following result SmartArt:

How to remove a specific node by position from SmartArt in PowerPoint

Full codes:

[C#]
using Spire.Presentation;
using Spire.Presentation.Diagrams;

namespace Remove_Node_from_SmartArt_in_PowerPoint
{
    class Program
    {
        static void Main(string[] args)
        {
            Presentation presentation = new Presentation();
            presentation.LoadFromFile("SmartArt.pptx");

            ISmartArt smartart = presentation.Slides[0].Shapes[0] as ISmartArt;
            ISmartArtNodeCollection nodes = smartart.Nodes;

            nodes.RemoveNodeByPosition(0);

            presentation.SaveToFile("RemoveNodes.pptx", FileFormat.Pptx2010);
        }
    }
}
[VB.NET]
Imports Spire.Presentation
Imports Spire.Presentation.Diagrams

Namespace Remove_Node_from_SmartArt_in_PowerPoint
	Class Program
		Private Shared Sub Main(args As String())
			Dim presentation As New Presentation()
			presentation.LoadFromFile("SmartArt.pptx")

			Dim smartart As ISmartArt = TryCast(presentation.Slides(0).Shapes(0), ISmartArt)
			Dim nodes As ISmartArtNodeCollection = smartart.Nodes

			nodes.RemoveNodeByPosition(0)

			presentation.SaveToFile("RemoveNodes.pptx", FileFormat.Pptx2010)
		End Sub
	End Class
End Namespace