Search code examples
pythonvbavisio

Visio VBA set dynamic connector to straight connector style


I'm using Python to control Visio via win32com.Client on a Windows 10 Platform. I've had a lot of success with this project but am stuck trying to find an answer. I've been scouring the Microsoft docs (for VBA of course) but cannot find an answer.

I'm adding connections points to shapes and connecting them with dynamic connectors without issue. All connectors that I drop appear as Right-Angle Connectors and I would like to switch some of them to Straight or Curved Connector styles. I haven't found anything in the ShapeSheet that look like the right setting. For what it's worth the code I'm using to drop the connectors is below. Thanks in advance for any assistance provided!

# visSectionConnectionPts = 7
shape = self.v_app.draw_page.Drop(self.v_app.app.ConnectorToolDataObject, 5, 4)
shape.Cells("BeginX").GlueTo(s_shp.shape.CellsSRC(7, s_row, 0))
shape.Cells("EndX").GlueTo(d_shp.shape.CellsSRC(7, d_row, 0))

if arrow:
  shape.Cells("EndArrow").FormulaForceU = "13"
if len(text) > 0:
  shape.Text = text

Solution

  • I haven't found anything in the ShapeSheet that look like the right setting.

    Please check in ShapeLayout section.

    ShapeLayout section

    Especially intrested cells: LineRouteExt Cell and ShapeRouteStyle Cell. Dynamic connector style changes

    import win32com.client as w32 
    visio = w32.Dispatch("visio.Application") 
    visio.Visible = 1 
    shape = visio.Activewindow.Page.Drop (visio.ConnectorToolDataObject, 7, 40)
    
    # define internal Visio constants for SRC-syntax
    visSectionObject = "1"
    visRowShapeLayout = "23"
    visSLOLineRouteExt = "19"
    visSLORouteStyle = "10"
    
    # Switch connector style 
    # Right-Angle Connector
    shape.CellsSRC(visSectionObject, visRowShapeLayout, visSLOLineRouteExt).FormulaU = "1"
    shape.CellsSRC(visSectionObject, visRowShapeLayout, visSLORouteStyle).FormulaU = "1"
    # Curved Connector
    shape.CellsSRC(visSectionObject, visRowShapeLayout, visSLOLineRouteExt).FormulaU = "2"
    # Straight Connector
    shape.CellsSRC(visSectionObject, visRowShapeLayout, visSLOLineRouteExt).FormulaU = "1"
    shape.CellsSRC(visSectionObject, visRowShapeLayout, visSLORouteStyle).FormulaU = "16"