get_shape_renderer method

get_shape_renderer()

Creates and returns an object that can be used to render this shape into an image.

def get_shape_renderer(self):
    ...

Remarks

This method just invokes the ShapeRenderer constructor and passes this object as a parameter.

Returns

The renderer object for this shape.

Examples

Shows how to use a shape renderer to export shapes to files in the local file system.

doc = aw.Document(file_name=MY_DIR + 'Various shapes.docx')
shapes = [x.as_shape() for x in list(doc.get_child_nodes(aw.NodeType.SHAPE, True)) if isinstance(x.as_shape(), aw.drawing.Shape)]
self.assertEqual(7, len(shapes))
# There are 7 shapes in the document, including one group shape with 2 child shapes.
# We will render every shape to an image file in the local file system
# while ignoring the group shapes since they have no appearance.
# This will produce 6 image files.
for shape in [x.as_shape() for x in list(doc.get_child_nodes(aw.NodeType.SHAPE, True)) if isinstance(x.as_shape(), aw.drawing.Shape)]:
    renderer = shape.get_shape_renderer()
    options = aw.saving.ImageSaveOptions(aw.SaveFormat.PNG)
    renderer.save(file_name=ARTIFACTS_DIR + f'Shape.RenderAllShapes.{shape.name}.png', save_options=options)

See Also