Changing the Connector color

J

John

Hi,

I am connecting two shapes by using the following code:

app.ActiveWindow.Select(fromShape, (short)Visio.VisSelectArgs.visSelect);
app.ActiveWindow.Select(toShape, (short)Visio.VisSelectArgs.visSelect);
app.ActiveWindow.Selection.ConnectShapes();

where fromShape and toShape are the two shapes. I need to change the color
of the connection. Does anyone know how I can go about doing this?

Thanks,
- John
 
G

garet

Hi John,
I wrote this routine in VBA, note it does a few other things but you
can see in the testmode field = true it changes the color to 2 (which
is red). I basically use it to connect programmically dropped shapes.

Hope that helps.

Regards,
Garet

Usuage:
connectLine startShapeID, "left", endShapeID, "right", True
left/right are the connection names on the shapes, for example a box
would have left/right/top/bottom (these are named on the stencil shapes
themselves)

Sub connectLine(startID, startConnName, endID, endConnName, fldLine,
Optional connStyle = 16, Optional testMode = False, Optional grpID As
Double, Optional shpClass As String = vbNullString)
On Error GoTo connectLine_err
Dim dynamicLineID As Double
Dim vsoShape1 As Visio.Shape

ignoreDrop = True

Set vsoShape1 =
Application.ActiveWindow.Page.Drop(Application.ConnectorToolDataObject,
5.1211, 8#)
dynamicLineID = vsoShape1.ID

Dim vsoCell1 As Visio.Cell
Dim vsoCell2 As Visio.Cell
Set vsoCell1 =
Application.ActiveWindow.Page.Shapes.ItemFromID(dynamicLineID).CellsU("BeginX")
Set vsoCell2 =
Application.ActiveWindow.Page.Shapes.ItemFromID(startID).Cells("Connections."
& startConnName) '.CellsSRC(7, 1, 0)

Application.ActiveWindow.Page.Shapes.ItemFromID(dynamicLineID).CellsSRC(visSectionObject,
visRowShapeLayout, visSLOLineRouteExt).FormulaU = 1

Application.ActiveWindow.Page.Shapes.ItemFromID(dynamicLineID).CellsSRC(visSectionObject,
visRowShapeLayout, visSLORouteStyle).FormulaU = connStyle

vsoCell1.GlueTo vsoCell2
Set vsoCell1 =
Application.ActiveWindow.Page.Shapes.ItemFromID(dynamicLineID).CellsU("EndX")
Set vsoCell2 =
Application.ActiveWindow.Page.Shapes.ItemFromID(endID).Cells("Connections."
& endConnName)

Application.ActiveWindow.Page.Shapes.ItemFromID(dynamicLineID).CellsSRC(visSectionObject,
visRowShapeLayout, visSLOLineRouteExt).FormulaU = 1

Application.ActiveWindow.Page.Shapes.ItemFromID(dynamicLineID).CellsSRC(visSectionObject,
visRowShapeLayout, visSLORouteStyle).FormulaU = connStyle

vsoCell1.GlueTo vsoCell2
lineType = IIf(fldLine = True, "2", "1")

Application.ActiveWindow.Page.Shapes.ItemFromID(dynamicLineID).CellsSRC(visSectionObject,
visRowLine, visLinePattern).FormulaU = lineType
If testMode = True Then

Application.ActiveWindow.Page.Shapes.ItemFromID(dynamicLineID).CellsSRC(visSectionObject,
visRowLine, visLineColor).FormulaU = "2"
End If

ignoreDrop = False
Exit Sub
connectLine_err:
Select Case Err.Number
Case -2032466967 'Unexpected end of file
msg = "Unable to connect line"
MsgBox msg, vbExclamation + vbOKOnly, "Error Message
(connectLine)"
End Select
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top