z_order property
ShapeBase.z_order property
Determines the display order of overlapping shapes.
@property
def z_order(self) -> int:
...
@z_order.setter
def z_order(self, value: int):
...
Remarks
Has effect only for top level shapes.
The default value is 0.
The number represents the stacking precedence. A shape with a higher number will be displayed as if it were overlapping (in “front” of) a shape with a lower number.
The order of overlapping shapes is independent for shapes in the header and in the main text of the document.
The display order of child shapes in a group shape is determined by their order inside the group shape.
Examples
Shows how to manipulate the order of shapes.
doc = aw.Document()
builder = aw.DocumentBuilder(doc=doc)
# Insert three different colored rectangles that partially overlap each other.
# When we insert a shape that overlaps another shape, Aspose.Words places the newer shape on top of the old one.
# The light green rectangle will overlap the light blue rectangle and partially obscure it,
# and the light blue rectangle will obscure the orange rectangle.
shape = builder.insert_shape(shape_type=aw.drawing.ShapeType.RECTANGLE, horz_pos=aw.drawing.RelativeHorizontalPosition.LEFT_MARGIN, left=100, vert_pos=aw.drawing.RelativeVerticalPosition.TOP_MARGIN, top=100, width=200, height=200, wrap_type=aw.drawing.WrapType.NONE)
shape.fill_color = aspose.pydrawing.Color.orange
shape = builder.insert_shape(shape_type=aw.drawing.ShapeType.RECTANGLE, horz_pos=aw.drawing.RelativeHorizontalPosition.LEFT_MARGIN, left=150, vert_pos=aw.drawing.RelativeVerticalPosition.TOP_MARGIN, top=150, width=200, height=200, wrap_type=aw.drawing.WrapType.NONE)
shape.fill_color = aspose.pydrawing.Color.light_blue
shape = builder.insert_shape(shape_type=aw.drawing.ShapeType.RECTANGLE, horz_pos=aw.drawing.RelativeHorizontalPosition.LEFT_MARGIN, left=200, vert_pos=aw.drawing.RelativeVerticalPosition.TOP_MARGIN, top=200, width=200, height=200, wrap_type=aw.drawing.WrapType.NONE)
shape.fill_color = aspose.pydrawing.Color.light_green
shapes = list(filter(lambda a: a is not None, map(lambda b: system_helper.linq.Enumerable.of_type(lambda x: x.as_shape(), b), list(doc.get_child_nodes(aw.NodeType.SHAPE, True)))))
# The "ZOrder" property of a shape determines its stacking priority among other overlapping shapes.
# If two overlapping shapes have different "ZOrder" values,
# Microsoft Word will place the shape with a higher value over the shape with the lower value.
# Set the "ZOrder" values of our shapes to place the first orange rectangle over the second light blue one
# and the second light blue rectangle over the third light green rectangle.
# This will reverse their original stacking order.
shapes[0].z_order = 3
shapes[1].z_order = 2
shapes[2].z_order = 1
doc.save(file_name=ARTIFACTS_DIR + 'Shape.ZOrder.docx')
See Also
- module aspose.words.drawing
- class ShapeBase
- property ShapeBase.behind_text