Data in Non-Primitive Shape

Accessing Data of Non-Primitive Shape

Sometimes, you need to access data from a shape that is not built-in. Built-in shapes are called primitive shapes; ones that aren’t are called non-primitive. For example, you can define your own shapes using different curve connected lines.

A Non-Primitive Shape

In Aspose.Cells, non-primitive shapes are assigned the type AutoShapeType.NOT_PRIMITIVE. You can check their type using the Shape.getAutoShapeType() method.

Access the shape data using the Shape.getPaths() method. It returns all the connected paths that comprise the non-primitive shape. These paths are of the type ShapePath that holds a list of all the segments which in turn contain the points in each segment.

The following code snippet demonstrates the use of Shape.getPaths() method to access path information of non-primitive shape.

Shows an example of a non-primitive shape

todo:image_alt_text

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the resource directory
String dataDir = Utils.getSharedDataDir(NonPrimitiveShape.class) + "DrawingObjects/";
Workbook workbook = new Workbook(dataDir + "NonPrimitiveShape.xlsx");
Worksheet worksheet = workbook.getWorksheets().get(0);
// Accessing the user defined shape
Shape shape = worksheet.getShapes().get(0);
if (shape.getAutoShapeType() == AutoShapeType.NOT_PRIMITIVE) {
// Access Shape paths
ShapePathCollection shapePathCollection = shape.getPaths();
// Access information of individual shape path
ShapePath shapePath = shapePathCollection.get(0);
// Access shape segment path list
ShapeSegmentPathCollection shapeSegmentPathCollection = shapePath.getPathSegementList();
// Access individual segment path
ShapeSegmentPath shapeSegmentPath = shapeSegmentPathCollection.get(0);
ShapePathPointCollection segmentPoints = shapeSegmentPath.getPoints();
for (Object obj : segmentPoints) {
ShapePathPoint pathPoint = (ShapePathPoint) obj;
System.out.println("X: " + pathPoint.getX() + ", Y: " + pathPoint.getY());
}
}