Free Support Forum - aspose.com

How to identify the type of a Shape?

Aspose::Slides::Slide::get_Shapes() can return all shapes from a slide. But how do I know what kind of shapes are those? So I want to detect if the Shape is an Aspose::Slides::Table or Aspose::Slides::AutoShape etc.

What’s the best way to do this?

Thanks in advance!

@gtamas

Aspose::Slides::Slide::get_Shapes() return collection of shapes. There are many types of shapes on slide. Therefore, in order to work on properties of particular type of shape, you need to type cast that to desired type. You need to use dynamic_cast to cast that desired shape type. I suggest you to please visit this documentation link with working example for your convenience.

@gtamas,
You can check the shape type as follows:

for (int i = 0; i < slide->get_Shapes()->get_Count(); i++)
{
	SharedPtr<IShape> shape = slide->get_Shapes()->idx_get(i);
	if (ObjectExt::Is<Table>(shape))
	{
		SharedPtr<Table> table = System::DynamicCast<Table>(shape);

		// some code...
	}
}

API Reference:
System::ObjectExt Class Reference, System::ObjectExt Member List

Thanks great! I also used DynamicCast, but in a different way, didn’t know about this ObjectExt::Is. Cool! Thanks!