Adding Connection Points to the Connector based on its shape and length

Started by metuemre, January 27, 2021, 12:00:26 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

metuemre

Hi all,

I want to add connection points to a connector at 3 mm. intervals to the end of it. The problem is that connector doesn't have to be straight, it may have many direction changes. What should be the correct way to program it on vba?


wapperdude

Just some thoughts off top of my head...
For the connector selected, I'd
  1) determine how many rows in the Geometry section.
  2) step thru each row and determine the
         a) begin/end pts
         b) determine slope of segment
         c) generate formula for that line segment and use it to place points.
         d) somehow, keep track of point-to-point spacing between adjacent segments to maintain uniformity
       

alternative, quasi-code, shapesheet
   1) determine how many rows in Geometry section, set variable and push value into some shapesheet cell, perhaps n the User_section
   2) use conditional statement for each row...this might not be necessary.
   2) determine direction of segment, perhaps rectsect fcn.
   3) then use nearestpointonpath and pointalongpath to place points
Visio 2019 Pro

wapperdude

Here's link to adding connection points around a shape.  Not exactly the same task, but perhaps will suggest some approach ideas.

http://visguy.com/vgforum/index.php?topic=7543.0
Visio 2019 Pro

metuemre

Hi wapperdude,

Thanks for the link and ideas. Yesterday, I worked on the issue and came up with a solution as below. Main idea is similar to your first thought. Right now it covers the cases if the line segmens in the connector are either vertical or horizontal. I need to add the case if there are angled segments as well, then calculate the slope and add connection points at the same angle.


Sub ConnectionPointsAdd(shp As Visio.Shape)
On Error Resume Next

Dim LineCount As Integer
Dim Xi As Double, Yi As Double
Dim y As Integer, i As Integer
Dim interval As Integer

shp.DeleteSection visSectionConnectionPts

LineCount = shp.RowCount(visSectionFirstComponent) - 1

'Add Connection points to start/end and each corner points of the connector
For i = 1 To LineCount
    shp.AddRow visSectionConnectionPts, i, 0
    shp.CellsSRC(visSectionConnectionPts, i - 1, 0).Result("mm") = shp.CellsSRC(visSectionFirstComponent, i, 0).Result("mm")
    shp.CellsSRC(visSectionConnectionPts, i - 1, 1).Result("mm") = shp.CellsSRC(visSectionFirstComponent, i, 1).Result("mm")
Next

'Measure each line segment of the connector and add connection points at 3mm intervals
For i = 1 To LineCount
    Xi = shp.CellsSRC(visSectionConnectionPts, i, 0).Result("mm") - shp.CellsSRC(visSectionConnectionPts, i - 1, 0).Result("mm") 'measure the width of line segment
    Yi = shp.CellsSRC(visSectionConnectionPts, i, 1).Result("mm") - shp.CellsSRC(visSectionConnectionPts, i - 1, 1).Result("mm") 'measure the height of line segment

    If Yi = 0 Then 'Check if the line segment is horizontal
        If Xi < 0 Then 'Check if the orientation of the line segment is from right to left
            interval = Abs(Int(Xi / 3) + 1) 'Calculate the number of 3mm intervals
            For y = 1 To interval 'Add connection points at 3mm intervals
                shp.AddRow visSectionConnectionPts, visRowLast, 0
                shp.CellsSRC(visSectionConnectionPts, shp.RowCount(visSectionConnectionPts) - 1, 0).Result("mm") = shp.CellsSRC(visSectionConnectionPts, i - 1, 0).Result("mm") + y * -3
                shp.CellsSRC(visSectionConnectionPts, shp.RowCount(visSectionConnectionPts) - 1, 1).Result("mm") = shp.CellsSRC(visSectionConnectionPts, i, 1).Result("mm")
            Next
        Else 'If the orientation of the line segment is from left to right
            interval = Int(Xi / 3) 'Calculate the number of 3mm intervals
            For y = 1 To interval 'Add connection points at 3mm intervals
                shp.AddRow visSectionConnectionPts, visRowLast, 0
                shp.CellsSRC(visSectionConnectionPts, shp.RowCount(visSectionConnectionPts) - 1, 0).Result("mm") = shp.CellsSRC(visSectionConnectionPts, i - 1, 0).Result("mm") + y * 3
                shp.CellsSRC(visSectionConnectionPts, shp.RowCount(visSectionConnectionPts) - 1, 1).Result("mm") = shp.CellsSRC(visSectionConnectionPts, i, 1).Result("mm")
            Next
        End If
    ElseIf Xi = 0 Then 'Check if the line segment is vertical
        If Yi < 0 Then 'Check if the orientation of the line segment is from top to bottom
            interval = Abs(Int(Yi / 3) + 1) 'Calculate the number of 3mm intervals
            For y = 1 To interval 'Add connection points at 3mm intervals
                shp.AddRow visSectionConnectionPts, visRowLast, 0
                shp.CellsSRC(visSectionConnectionPts, shp.RowCount(visSectionConnectionPts) - 1, 0).Result("mm") = shp.CellsSRC(visSectionConnectionPts, i, 0).Result("mm")
                shp.CellsSRC(visSectionConnectionPts, shp.RowCount(visSectionConnectionPts) - 1, 1).Result("mm") = shp.CellsSRC(visSectionConnectionPts, i - 1, 1).Result("mm") + y * -3
            Next
        Else 'If the orientation of the line segment is from bottom to top
            interval = Int(Yi / 3) 'Calculate the number of 3mm intervals
            For y = 1 To interval 'Add connection points at 3mm intervals
                shp.AddRow visSectionConnectionPts, visRowLast, 0
                shp.CellsSRC(visSectionConnectionPts, shp.RowCount(visSectionConnectionPts) - 1, 0).Result("mm") = shp.CellsSRC(visSectionConnectionPts, i, 0).Result("mm")
                shp.CellsSRC(visSectionConnectionPts, shp.RowCount(visSectionConnectionPts) - 1, 1).Result("mm") = shp.CellsSRC(visSectionConnectionPts, i - 1, 1).Result("mm") + y * 3
            Next
        End If
    End If
Next
End Sub