Skip to end of metadata
Go to start of metadata
  

Add and Remove SmartArt Nodes and Child Nodes

In this article we will further look in to managing SmartArt shapes added in presentation slides programatically using Aspose.Slides for Java.

We will use the following source SmartArt shape for our investigation in different sections of this article.

Adding SmartArt Shape Nodes

Aspose.Slides for Java has provided an API to manage the SmartArt shapes. The following sample code will help to add node and child node inside SmartArt shape.

  1. Create an instance of Presentation class and load the presentation with SmartArt Shape.
  2. Obtain the reference of first slide by using its Index.
  3. Traverse through every shape inside first slide.
  4. Check if shape is of SmartArt type and Typecast selected shape to SmartArt if it is SmartArt.
  5. Add a new Node in SmartArt shape NodeCollection and set the text in TextFrame.
  6. Now, Add a Child Node in newly added SmartArt Node and set the text in TextFrame
  7. Save the Presentation.

Adding SmartArt Shape Node at Specific Position

In the following sample code we have explained how to add the child nodes belonging to respective nodes of SmartArt shape at particular position.

  1. Create an instance of Presentation class.
  2. Obtain the reference of first slide by using its Index.
  3. Add a StackedList type SmartArt shape in accessed slide.
  4. Access the first node in added SmartArt shape
  5. Now, add the Child Node for selected Node at position 2 and set its text.
  6. Save the Presentation

Remove SmartArt Shape Node

In this example, we will learn to remove the nodes inside SmartArt shape.

  1. Create an instance of Presentation class and load the presentation with SmartArt Shape.
  2. Obtain the reference of first slide by using its Index.
  3. Traverse through every shape inside first slide.
  4. Check if shape is of SmartArt type and Typecast selected shape to SmartArt if it is SmartArt.
  5. Check if the SmartArt has more than 0 nodes.
  6. Select the SmartArt node to be deleted.
  7. Now, remove the selected node using RemoveNode() method.
  8. Save the Presentation.

Remove SmartArt Shape Node at Specific Position

In this example, we will learn to remove the nodes inside SmartArt shape at particular position.

  1. Create an instance of Presentation class and load the presentation with SmartArt Shape.
  2. Obtain the reference of first slide by using its Index.
  3. Traverse through every shape inside first slide.
  4. Check if shape is of SmartArt type and Typecast selected shape to SmartArt if it is SmartArt.
  5. Select the SmartArt shape node at index 0.
  6. Now, check if the selected SmartArt node has more than 2 child nodes.
  7. Now, remove the node at Position 1 using RemoveNodeByPosition() method.
  8. Save the Presentation.

Accessing SmartArt Nodes and Child Nodes

In this article we will look further in to managing SmartArt shapes added in presentation slides programmatically using Aspose.Slides for Java.

Accessing SmartArt Shape Nodes

Aspose.Slides for Java has provided an API to manage the SmartArt shapes. The following sample code will help to access nodes inside SmartArt shape. Please note that you cannot change the LayoutType of the SmartArt as it is read only and is set only when the SmartArt shape is added.

  1. Create an instance of Presentation class and load the presentation with SmartArt Shape.
  2. Obtain the reference of first slide by using its Index.
  3. Traverse through every shape inside first slide.
  4. Check if shape is of SmartArt type and Typecast selected shape to SmartArt if it is SmartArt.
  5. Traverse through all Nodes inside SmartArt Shape.
  6. Access and display information like SmartArt Node position, level and Text.

Accessing SmartArt Shape Child Nodes

Aspose.Slides for Java has provided an API to manage the SmartArt shapes in an easiest way. The following sample code will help to access the child nodes belonging to respective nodes of SmartArt shape.

  1. Create an instance of Presentation class and load the presentation with SmartArt Shape.
  2. Obtain the reference of first slide by using its Index.
  3. Traverse through every shape inside first slide.
  4. Check if shape is of SmartArt type and Typecast selected shape to SmartArt if it is SmartArt.
  5. Traverse through all Nodes inside SmartArt Shape.
  6. For every selected SmartArt shape Node, traverse through all Child Nodes inside particular node.
  7. Access and display information like Child Node position, level and Text.

Accessing SmartArt Shape Child Node at Specific Position

In this example, we will learn to access the child nodes at some particular position belonging to respective nodes of SmartArt shape.

  1. Create an instance of Presentation class.
  2. Obtain the reference of first slide by using its Index.
  3. Add a StackedList type SmartArt shape.
  4. Access the added SmartArt shape.
  5. Access the node at index 0 for accessed SmartArt shape.
  6. Now, access the Child Node at position 1 for accessed SmartArt node using GetNodeByPosition() method.
  7. Access and display information like Child Node position, level and Text.

Checking Assistant Nodes in SmartArt Shapes

In this article we will further investigate features of SmartArt shapes added in presentation slides programmatically using Aspose.Slides for Java.

We will use the following source SmartArt shape for our investigation in different sections of this article.

Figure: Source SmartArt shape in slide

In the following sample code we will investigate how to identify Assistant Nodes in the SmartArt nodes collection and changing them.

  1. Create an instance of Presentation class and load the presentation with SmartArt Shape.
  2. Obtain the reference of second slide by using its Index.
  3. Traverse through every shape inside first slide.
  4. Check if shape is of SmartArt type and Typecast selected shape to SmartArt if it is SmartArt.
  5. Traverse through all nodes inside SmartArt shape and check if they are Assistant Nodes.
  6. Change the status of Assistant Node to normal node.
  7. Save the Presentation.

Figure: Assistant Nodes Changed in SmartArt shape inside slide

Setting Fill Format for SmartArt Node

Aspose.Slides for Java makes it possible to add custom SmartArt shapes and set their fill format. This article explains how to create and access SmartArt shapes and set their fill format using Aspose.Slides for Java.

Aspose.Slides for Java provides a simple API for creating SmartArt shapes and set their node fill format. Please follow the steps below:

  1. Create an instance of the Presentation class.
  2. Obtain the reference of a slide using its index.
  3. Add a SmartArt shape by setting its LayoutType.
  4. Set the FillFormat for the SmartArt shape nodes.
  5. Write the modified presentation as a PPTX file.

Labels
  • No labels