前のトピック     次のトピック

第 19 章 VISIO ソリューションでの接続のオートメーション化

セクション 5   フローチャート内の図形の接続 : 例

次の Microsoft Visual Basic for Applications (VBA) プログラムでは、このプロシージャに引数として渡された配列に含まれるデータに基づいて、Visio® の図面ページ上に簡単なフローチャートを描画します。渡される配列は 2 次元で、最初の要素にはマスタシェイプの名前、2 番目の要素にはシェイプの文字が格納されています。プロシージャは、フローチャートを作成する前に配列データを読み込み、Visual Basicエディタのイミディエイト ウィンドウにその内容を表示します。

 



CreateFlowchart によって作成されたフローチャート

Public Sub CreateFlowchart(arrFlowChart () As String)
     Dim vPrevShape As Visio.Shape
     Dim vNextShape As Visio.Shape
     Dim vConnector As Visio.Shape
     Dim vFlowChartMaster As Visio.Master
     Dim vConnectorMaster As Visio.Master
     Dim vStencil As Visio.Document
     Dim dblXLocation As Double
     Dim dblYLocation As Double
     Dim bCell As Visio.Cell
     Dim eCell As Visio.Cell
     Dim iCount As Integer


'Shape that you're connecting from
'Shape that you're connecting to
'Shape representing the connection
'Reference to the flowchart master
'Reference to the connector master
'The stencil containing the masters
'Master's PinX location
'Master's PinY location
'Begin cell for connector
'End cell for connector

     On Error GoTo eHandler
     'Initialize X, Y location that we will pass to the Drop method
     dblXLocation = 4.25
     dblYLocation = 10.5
     'Print array to Immediate window
     For iCount = LBound(arrFlowData) To UBound(arrFlowData)
          Debug.Print arrFlowData(iCount, 0) & " "; arrFlowData(iCount, 1)
     Next
     'Open Flowchart stencil
     Set vStencil = Application.Documents.OpenEx _
          ("基本フローチャート.vss", visOpenDocked)
     'Add a shape to the drawing for each item in the array
     For iCount = LBound(arrFlowData) To UBound(arrFlowData)
          'Get the Master based on MasterName in the data array
          Set vFlowChartMaster = vStencil.Masters(arrFlowData(iCount, 0))
          'Add the shape to the page
          Set vNextShape = ActivePage.Drop(vFlowChartMaster, dblXLocation, _
               dblYLocation)
          'Set dropped shape text
          vNextShape.Text = arrFlowData(iCount, 1)
          'Connect to Previous shape dropped, if necessary
          If Not vPrevShape Is Nothing Then
               'Get Connector Master if necessary
               If vConnectorMaster Is Nothing Then
                    Set vConnectorMaster = vStencil.Masters("動的コネクタ")
               End If
               'Add Connector to the page (doesn't matter where for this example)
               Set vConnector = ActivePage.Drop(vConnectorMaster, 0, 0)
               'Connect Begin Point
               Set bCell = vConnector.Cells("BeginX")
               bCell.GlueTo vPrevShape.Cells("AlignBottom")
               'Connect End Point
               Set eCell = vConnector.Cells("EndX")
               eCell.GlueTo vNextShape.Cells("AlignTop")
               vConnector.SendToBack
          End If
          Set vPrevShape = vNextShape
          Set vNextShape = Nothing
          'Set Y location for next shape
          dblYLocation = dblYLocation - 1.5
     Next
     Exit Sub
     eHandler:
     Debug.Print Error
End Sub

Top