Adding,Updating and Manipulating SmartArt

Adding and Updating SmartArt

Creating a SmartArt Shape

Aspose.Slides for C++ now facilitates to add custom SmartArt shapes in their slides from scratch. Aspose.Slides for C++ has provided the simplest API to create SmartArt shapes in an easiest way. To create a SmartArt shape in a slide, please follow the steps below:

  • Create an instance of Presentation class.
  • Obtain the reference of a slide by using its Index.
  • Add a SmartArt shape by setting it LayoutType.
  • Write the modified presentation as a PPTX file.

Accessing the SmartArt shape in slide

The following code will be used to access the SmartArt shapes added in presentation slide. In sample code we will traverse through every shape inside the slide and check if it is a SmartArt shape. If shape is of SmartArt type then we will typecast that to SmartArt instance.

Adding SmartArt Shape Nodes

Aspose.Slides for C++ has provided the simplest API to manage the SmartArt shapes in an easiest way. The following sample code will help to add node and child node inside SmartArt shape.

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

Remove SmartArt Shape Node

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

  • Create an instance of Presentation class and load the presentation with SmartArt Shape.
  • Obtain the reference of first slide by using its Index.
  • Traverse through every shape inside first slide.
  • Check if shape is of SmartArt type and Typecast selected shape to SmartArt if it is SmartArt.
  • Check if the SmartArt has more than 0 nodes.
  • Select the SmartArt node to be deleted.
  • Now, remove the selected node using RemoveNode() method* 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.

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

Manipulating SmartArt

Accessing the SmartArt shape in slide

The following code will be used to access the SmartArt shapes added in presentation slide. In sample code we will traverse through every shape inside the slide and check if it is a SmartArt shape. If shape is of SmartArt type then we will typecast that to SmartArt instance.

Changing Layout type of any SmartArt

In order to change the layout type of SmartArt. Please follow the steps below:

  • Create an instance of Presentation class.
  • Obtain the reference of a slide by using its Index.
  • Add SmartArt BasicBlockList.
  • Change LayoutType to BasicProcess.
  • Write the presentation as a PPTX file. In the example given below, we have added a connector between two shapes.

Checking Hidden Property Of SmartArt

Please note Method com.aspose.slides.ISmartArtNode.isHidden() returns true if this node is a hidden node in the data model. In order to check the hidden property of any node of SmartArt. Please follow the steps below:

  • Create an instance of Presentation class.
  • Add SmartArt RadialCycle.
  • Add node on SmartArt.
  • Check isHidden property.
  • Write the presentation as a PPTX file.

In the example given below, we have added a connector between two shapes.

Get Text from SmartArt

Now TextFrame property has been added to ISmartArtShape interface and SmartArtShape class respectively. This property allows you to get all text from SmartArt if it has not only nodes text. The following sample code will help you to get text from SmartArt node.

Get or Set the state of the SmartArt

Some SmartArt diagrams does not support reversal, for example; Vertical bullet list,Vertical Process,Descending Process,Funnel,Gear,,Balance,Circle Relationship,Hexagon Cluster,Reverse List,Stacked Venn. In order to change orientation of SmartArt. Please follow the steps below:

  • Create an instance of Presentation class.
  • Add SmartArt on slide.
  • Get or Set the state of SmartArt Diagram.
  • Write the presentation as a PPTX file. In the example given below, we have added a connector between two shapes.

Get or Set the organization chart type

Methods com.aspose.slides.ISmartArtNode.getOrganizationChartLayout(), setOrganizationChartLayout(int) allow get or sets organization chart type associated with current node. In order to get or set organization chart type. Please follow the steps below:

  • Create an instance of Presentation class.
  • Add SmartArt on slide.
  • Get or Set the organization chart type.
  • Write the presentation as a PPTX file. In the example given below, we have added a connector between two shapes.

Support for setting custom position for child nodes in SmartArt

Now Aspose.Slides for .NET support for setting SmartArtShape X and Y properties. The code snippet below shows how to set custom SmartArtShape position, size and rotation also please note that adding new nodes causes a recalculation of the positions and sizes of all nodes.