Polar Array – Part 2

It has been almost two years since I blogged, so it is time to dust off the blog.

Today in the newsgroups someone asked about using the Polar Array VBA sample from the Visio MVP website, but rather than place a specific shapes multiple times, arrange the shapes that are selected.

As usual, the original credit goes to Chris

Sub PolarArray()
‘ by Chris Roth
Dim shp As Visio.Shape, shpObj As Visio.Shape, celObj As Visio.Cell
Dim iNum As Integer, i As Integer
Dim dRad As Double, dAngStart As Double, dAng As Double
Dim x As Double, y As Double
Dim VsoSelect As Visio.Selection
Dim VsoShape As Visio.Shape

‘ obtain the shape to be distributed
Set shp = Visio.ActiveWindow.Selection(1)

Const PI = 3.14159265358

Set VsoSelect = Visio.ActiveWindow.Selection

If VsoSelect.Count > 1 Then
    iNum = VsoSelect.Count
    dRad = InputBox(“Enter the radius for the polar array in inches:”, “Polar Array”)
    dAngStart = InputBox(“Enter the first angle in degrees (0 deg = 3 o’clock):”, “Polar Array”)
    dAngStart = dAngStart * PI / 180 ‘Convert to radians
   
    dAng = 2 * PI / iNum
    
    For i = 1 To iNum
    x = dRad * Cos(dAngStart + dAng * (i – 1)) + 4.25
    y = dRad * Sin(dAngStart + dAng * (i – 1)) + 5.5
    Set VsoShape = VsoSelect(i)
‘    Set shpObj = Visio.ActivePage.Drop(shp, x, y)
    VsoShape.Cells(“Pinx”).Formula = x
    VsoShape.Cells(“piny”).Formula = y
    ‘ rotate the shape – This only makes sense if this is a group of chairs around a table
‘    Set celObj = VsoShape.Cells(“Angle”)
‘    celObj.Formula = Str(Int((i – 1) * 360 / iNum)) + “deg.”
    Next i
   
Else   ‘ if only one shape is selected, then
    iNum = InputBox(“Enter the number of items in the array:”, “Polar Array”)
    dRad = InputBox(“Enter the radius for the polar array in inches:”, “Polar Array”)
    dAngStart = InputBox(“Enter the first angle in degrees (0 deg = 3 o’clock):”, “Polar Array”)
    dAngStart = dAngStart * PI / 180 ‘Convert to radians
   
    dAng = 2 * PI / iNum
   
    For i = 1 To iNum
    x = dRad * Cos(dAngStart + dAng * (i – 1)) + 4.25
    y = dRad * Sin(dAngStart + dAng * (i – 1)) + 5.5
    Set shpObj = Visio.ActivePage.Drop(shp, x, y)
    shpObj.Text = i
    ‘ rotate the shape
    Set celObj = shpObj.Cells(“Angle”)
    celObj.Formula = Str(Int((i – 1) * 360 / iNum)) + “deg.”
    Next i
End If
End Sub

Leave a Reply

Your email address will not be published. Required fields are marked *