如何在 Visio 中为连接器端点添加标签?

huangapple go评论58阅读模式
英文:

How does one add labels to connector ends in visio?

问题

我正在使用Visio 2306进行网络文档编写,并希望在连接器的末端添加端口号。看到UML类箭头,这显然是可以做到的,但我在复制它时运气不佳。

到目前为止的步骤:

  • 制作新的连接器
  • 将连接器转换为组
  • 制作文本字段
  • 将文本字段添加到组

这几乎可以工作:连接器仍然能够正常工作,而文本框似乎也连接到了末端。

但实际上仍然存在两个问题:

  • 大小相对于连接器的大小而缩放
    • 即使在形状行为中已经关闭了这个选项
  • 位置相对于连接器的中心而缩放
    • 即使文本标签确实保持在连接器末端

也许需要一些VBA?我还没有深入研究VBA,也许这就是我还没有找到解决方案的原因。

我也查看了形状表,但编辑PinX和PinY的值似乎在拖动附加的形状后不会保留。

英文:

I'm doing some network documentation in visio 2306 and want to add port numbers to the ends of the connectors. Seeing the UML class arrows, this is obviously possible to do, but I have no luck in replicating that.

Steps so far:

  • Make a new connector
  • Convert connector to group
  • Make text fields
  • Add the text fields to the group

This almost works: the connector still functions nicely and the text boxes seem to attach to the ends.

In practice this still has 2 problems:

  • The size scales relatively to the size of the connector
    • Even when that has been turned off in the shape behaviour
  • The position scales relative to the center of the connector
    • Even though the text label does stay nicely attached to the connector end.

Maybe some VBA is required? I haven't looked into VBA much yet, maybe that's why I havent found a solution yet.

I have looked in the shape sheet as well, but editing the PinX and PinY value doesn't seem persist after dragging the attached shapes around.

答案1

得分: 1

以下是您要翻译的内容:

"Also you can try solution by y4cine which you can find in VisioGuy forum's thread Insert shape data values in sub-shape text
如何在 Visio 中为连接器端点添加标签?

Video description

UPDATE you cant download file from VisioGuy's forum without registration. I asked the author for permission to publish the code here, he kindly allowed it.

Option Explicit
' This code originally published http://visguy.com/vgforum/index.php?topic=6318.msg25957;topicseen#msg25957

Private Sub cmRun_Click()
    Dim shp As Shape, shp2 As Shape
    Dim i As Integer
    
    Select Case ActiveWindow.Selection.Count
    Case 0:
        MsgBox "You need to select a shape to perform the operation"
        Exit Sub
    Case 1:
        Set shp = ActiveWindow.Selection(1)
        ActiveWindow.DeselectAll
        ActiveWindow.Select shp, visSelect
        ActiveWindow.Selection.Copy
        On Error Resume Next
        shp.ConvertToGroup
        On Error GoTo 0
        If shp.OneD = False Then
        shp.OpenDrawWindow.Activate
        ActiveWindow.Shape.Paste
        ActiveWindow.SelectAll
        Set shp2 = ActiveWindow.Selection(ActiveWindow.Selection.Count)
            shp2.Cells("PinX").Formula = shp.NameU & "!width*0.5"
            shp2.Cells("PinY").Formula = shp.NameU & "!height*0.5"

        shp2.DeleteSection visSectionProp
        shp2.SendToBack
        ActiveWindow.Close
        shp.DeleteSection visSectionFirstComponent
        End If
        If shp.SectionExists(visSectionProp, False) Then
            listProps.Clear
            For i = 0 To shp.Section(visSectionProp).Count - 1
                listProps.AddItem shp.Section(visSectionProp).Row(i).Name
            Next i
        Else
            MsgBox "Your shape does not have shape data"
            Exit Sub
        End If
    Case Else:
        MsgBox "please select only one shape"
        Exit Sub
    End Select
    
End Sub
Private Sub cmInsert_Click()
    Dim shp As Shape, shp2 As Shape
    Dim i As Integer
    
    Select Case ActiveWindow.Selection.Count
    Case 0:
        MsgBox "You need to select a shape to perform the operation"
        Exit Sub
    Case 1:
        Set shp = ActiveWindow.Selection(1)
        If shp.SectionExists(visSectionProp, False) Then
            For i = 0 To listProps.ListCount - 1
                If listProps.Selected(i) Then
                    insertField shp, listProps.List(i)
                End If
            Next i
        Else
            MsgBox "Your shape does not have shape data"
            Exit Sub
        End If
    Case Else:
        MsgBox "please select only one shape"
        Exit Sub
    End Select

End Sub

Sub insertField(shp As Shape, field As String)
Dim shp2 As Shape
Dim shpChars As Visio.Characters

    If Not shp.SectionExists(visSectionControls, False) Then
        shp.AddSection visSectionControls
    End If
    shp.AddRow visSectionControls, visRowLast, visTagDefault

    Set shp2 = shp.DrawRectangle(0, 0, 1, 1)
    shp2.TextStyle = "Normal"
    shp2.LineStyle = "Text Only"
    shp2.FillStyle = "Text Only"
    Set shpChars = shp2.Characters
    shpChars.Begin = 0
    shpChars.End = 0
    shpChars.AddCustomFieldU "sheet." & shp.ID & "!prop." & field, visFmtNumGenNoUnits
    shp2.Cells("PinX").Formula = "sheet." & shp.ID & "!controls.row_" & shp.RowCount(visSectionControls)
    shp2.Cells("PinY").Formula = "sheet." & shp.ID & "!controls.row_" & shp.RowCount(visSectionControls) & ".Y"
    shp2.Cells("Width").FormulaU = "textwidth(thetext)"
    shp2.Cells("Height").FormulaU = "textheight(thetext, textwidth(thetext))"

End Sub

Download DisplayProps.vss"

英文:

Also you can try solution by y4cine which you can find in VisioGuy forum's thread Insert shape data values in sub-shape text
如何在 Visio 中为连接器端点添加标签?

Video description

UPDATE you cant download file from VisioGuy's forum without registration. I asked the author for permission to publish the code here, he kindly allowed it.

Option Explicit
' This code originally published http://visguy.com/vgforum/index.php?topic=6318.msg25957;topicseen#msg25957
Private Sub cmRun_Click()
Dim shp As Shape, shp2 As Shape
Dim i As Integer
Select Case ActiveWindow.Selection.Count
Case 0:
MsgBox "You need to select a shape to perform the operation"
Exit Sub
Case 1:
Set shp = ActiveWindow.Selection(1)
ActiveWindow.DeselectAll
ActiveWindow.Select shp, visSelect
ActiveWindow.Selection.Copy
On Error Resume Next
shp.ConvertToGroup
On Error GoTo 0
If shp.OneD = False Then
shp.OpenDrawWindow.Activate
ActiveWindow.Shape.Paste
ActiveWindow.SelectAll
Set shp2 = ActiveWindow.Selection(ActiveWindow.Selection.Count)
shp2.Cells("PinX").Formula = shp.NameU & "!width*0.5"
shp2.Cells("PinY").Formula = shp.NameU & "!height*0.5"
shp2.DeleteSection visSectionProp
shp2.SendToBack
ActiveWindow.Close
shp.DeleteSection visSectionFirstComponent
End If
If shp.SectionExists(visSectionProp, False) Then
listProps.Clear
For i = 0 To shp.Section(visSectionProp).Count - 1
listProps.AddItem shp.Section(visSectionProp).Row(i).Name
Next i
Else
MsgBox "Your shape does not have shape data"
Exit Sub
End If
Case Else:
MsgBox "please select only one shape"
Exit Sub
End Select
End Sub
Private Sub cmInsert_Click()
Dim shp As Shape, shp2 As Shape
Dim i As Integer
Select Case ActiveWindow.Selection.Count
Case 0:
MsgBox "You need to select a shape to perform the operation"
Exit Sub
Case 1:
Set shp = ActiveWindow.Selection(1)
If shp.SectionExists(visSectionProp, False) Then
For i = 0 To listProps.ListCount - 1
If listProps.Selected(i) Then
insertField shp, listProps.List(i)
End If
Next i
Else
MsgBox "Your shape does not have shape data"
Exit Sub
End If
Case Else:
MsgBox "please select only one shape"
Exit Sub
End Select
End Sub
Sub insertField(shp As Shape, field As String)
Dim shp2 As Shape
Dim shpChars As Visio.Characters
If Not shp.SectionExists(visSectionControls, False) Then
shp.AddSection visSectionControls
End If
shp.AddRow visSectionControls, visRowLast, visTagDefault
Set shp2 = shp.DrawRectangle(0, 0, 1, 1)
shp2.TextStyle = "Normal"
shp2.LineStyle = "Text Only"
shp2.FillStyle = "Text Only"
Set shpChars = shp2.Characters
shpChars.Begin = 0
shpChars.End = 0
shpChars.AddCustomFieldU "sheet." & shp.ID & "!prop." & field, visFmtNumGenNoUnits
shp2.Cells("PinX").Formula = "sheet." & shp.ID & "!controls.row_" & shp.RowCount(visSectionControls)
shp2.Cells("PinY").Formula = "sheet." & shp.ID & "!controls.row_" & shp.RowCount(visSectionControls) & ".Y"
shp2.Cells("Width").FormulaU = "textwidth(thetext)"
shp2.Cells("Height").FormulaU = "textheight(thetext, textwidth(thetext))"
End Sub

Download DisplayProps.vss

答案2

得分: 0

最后,我是这样让它工作的:

  • 创建一个新连接器
  • 将连接器转换为组
  • 创建文本字段
  • 将文本字段添加到组中
  • 将连接点添加到连接器(它们保持与末端的固定距离,这是UML箭头解决此问题的方式)
  • 使用形状表将文本字段绑定到连接点。
英文:

In the end I got it working like this:

  • Make a new connector
  • Convert connector to group
  • Make text fields
  • Add the text fields to the group
  • Add connection points to the connector (they stay at a fixed distance from the end, it's the way the UML arrows work around the issue)
  • Use the shapesheet to bind the textfields to the connection points.

huangapple
  • 本文由 发表于 2023年7月13日 21:12:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76679761.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定