Existing objects in diagrams

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Watermark MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-watermark -- dnx GroupDocs.Watermark.Mcp --yes
Folders, licensing and more →

Watermarker.get_content() returns a DiagramContent whose pages expose the diagram’s shapes and headers/footers. You can iterate the shapes to read their properties, modify them, or remove them.

Extract information about shapes

The example reports the shapes on the first page of a Visio diagram.

from groupdocs.watermark import Watermarker

def extract_shapes():
    with Watermarker("./diagram.vsdx") as watermarker:
        content = watermarker.get_content()
        page = content.pages[0]
        print(f"Pages: {len(content.pages)}; page 1 shapes: {len(page.shapes)}")
        for shape in page.shapes:
            text = (shape.text or "").strip()
            print(f"  shape name={shape.name!r} text={text!r} "
                  f"size={round(shape.width)}x{round(shape.height)}")

if __name__ == "__main__":
    extract_shapes()

diagram.vsdx is the sample file used in this example. Click here to download it.

Pages: 2; page 1 shapes: 12
  shape name='Title' text='Aurora Visuals — Production workflow' size=648x43
  shape name='Stage: Brief' text='Brief' size=115x65
  shape name='Arrow 1' text='' size=32x0
  shape name='Stage: Shoot' text='Shoot' size=115x65
  shape name='Arrow 2' text='' size=32x0
  shape name='Stage: Edit' text='Edit' size=115x65
  shape name='Arrow 3' text='' size=32x0
  shape name='Stage: Review' text='Review' size=115x65
  shape name='Arrow 4' text='' size=32x0
[TRUNCATED]

Download full output

Each shape exposes name, text, image, x, y, width, height, and rotate_angle.

Remove and modify shapes

The shapes collection supports remove_at(index) and remove(shape). Iterate in reverse when removing by index:

from groupdocs.watermark import Watermarker

def remove_and_modify_shapes():
    with Watermarker("./diagram.vsdx") as watermarker:
        content = watermarker.get_content()
        for page in content.pages:
            for i in range(len(page.shapes) - 1, -1, -1):
                if page.shapes[i].name == "Rectangle":
                    page.shapes.remove_at(i)
        watermarker.save("./output.vsdx")

if __name__ == "__main__":
    remove_and_modify_shapes()

diagram.vsdx is the sample file used in this example. Click here to download it.

Binary file (VSDX, 11 KB)

Download full output

You can replace a shape’s text by assigning to shape.text, replace its image by assigning a DiagramWatermarkableImage to shape.image, and modify its position and size through x, y, width, height, and rotate_angle.