remove method


Removes itself from the parent.

def remove(self):


Shows how to delete all shapes with images from a document.

doc = aw.Document(MY_DIR + 'Images.docx')
shapes = doc.get_child_nodes(aw.NodeType.SHAPE, True)
self.assertEqual(9, len([node for node in shapes if node.as_shape().has_image]))
for node in shapes:
    shape = node.as_shape()
    if shape.has_image:
self.assertEqual(0, len([node for node in shapes if node.as_shape().has_image]))

Shows how to remove all child nodes of a specific type from a composite node.

doc = aw.Document(file_name=MY_DIR + 'Tables.docx')
self.assertEqual(2, doc.get_child_nodes(aw.NodeType.TABLE, True).count)
cur_node = doc.first_section.body.first_child
while cur_node != None:
    # Save the next sibling node as a variable in case we want to move to it after deleting this node.
    next_node = cur_node.next_sibling
    # A section body can contain Paragraph and Table nodes.
    # If the node is a Table, remove it from the parent.
    if cur_node.node_type == aw.NodeType.TABLE:
    cur_node = next_node
self.assertEqual(0, doc.get_child_nodes(aw.NodeType.TABLE, True).count)

See Also