The following plugin zooms in or out so that the latent variables in the path diagram just fill the Amos Graphics window. If the path diagram contains no latent variables, no zoom is performed.
Imports Microsoft.VisualBasic
Imports Amos
<System.ComponentModel.Composition.Export(GetType(IPlugin))>
Public Class CustomCode
Implements IPlugin
Public Function Mainsub() As Integer Implements IPlugin.Mainsub
Dim ZTop As Object, ZBottom As Object
Dim ZLeft As Object, ZRight As Object
Dim E As PDElement
Dim Temp As Single
' 999999 inches is an impossible value
Const HugeNumber = 999999
ZLeft = HugeNumber
ZTop = HugeNumber
ZRight = -HugeNumber
ZBottom = -HugeNumber
For Each E In pd.PDElements
If E.IsLatentVariable Then
Temp = E.OriginX - E.Width / 2
If Temp < ZLeft Then ZLeft = Temp
Temp = E.OriginY - E.Height / 2
If Temp < ZTop Then ZTop = Temp
Temp = E.OriginX + E.Width / 2
If Temp > ZRight Then ZRight = Temp
Temp = E.OriginY + E.Height / 2
If Temp > ZBottom Then ZBottom = Temp
End If
Next
'If there are no latent variables, return without zooming
If ZLeft = HugeNumber Then Return 0
If ZTop = HugeNumber Then Return 0
If ZRight = -HugeNumber Then Return 0
If ZBottom = -HugeNumber Then Return 0
pd.DiagramZoom(ZLeft, ZTop, ZRight, ZBottom)
End Function
Public Function Name() As String Implements IPlugin.Name
End Function
Public Function Description() As String Implements IPlugin.Description
End Function
End Class