Create shapes and connectors
Create shapes
vsdx.vsdxfile.VisioFile.create_shape() copies a masterless shape from
the bundled palette into an existing page. Coordinates are Visio page units,
normally inches, and identify the centre of the shape.
from vsdx import VisioFile
with VisioFile("diagram.vsdx") as vis:
page = vis.pages[0]
start = vis.create_shape(
page, "PALETTE_START_END", 2.0, 6.0, text="Start"
)
work = vis.create_shape(
page, "PALETTE_PROCESS", 6.0, 6.0,
w=2.0, h=1.0, text="Do the thing"
)
decision = vis.create_shape(
page, "PALETTE_DECISION", 10.0, 6.0, text="OK?"
)
page.connect_shapes(start, work)
page.connect_shapes(work, decision, route="rightangle")
vis.save_vsdx("flow.vsdx")
Palette names
The bundled palette exposes these names:
PALETTE_PROCESSPALETTE_DECISIONPALETTE_START_ENDPALETTE_PARALLELOGRAMPALETTE_DATABASE
An unknown name raises ValueError.
Connector glue and routing
vsdx.pages.Page.connect_shapes() returns the new connector as a
vsdx.shapes.Shape.
dynamicDynamic shape glue. This is the default.
pointGlue to zero-based connection points selected with
from_cpandto_cp.straight,rightangleorcurvedDynamic glue with the selected route style.
point|straight,point|rightangleorpoint|curvedConnection-point glue with the selected route style.
connector = page.connect_shapes(
source,
target,
route="point|curved",
from_cp=0,
to_cp=2,
)
Re-anchor a connector
vsdx.pages.Page.reanchor_connector() moves either or both endpoints.
Pass None to retain an existing endpoint.
connector = page.find_shape_by_id("9")
new_target = page.find_shape_by_text("Store")
if connector is not None and new_target is not None:
page.reanchor_connector(connector, to_shape=new_target)
Delete a connected shape
Use vsdx.pages.Page.delete_shape() when connector cleanup matters. It
removes incident connector shapes and their Connect records before it
removes the requested shape.
obsolete = page.find_shape_by_text("Obsolete")
if obsolete is not None:
page.delete_shape(obsolete)