Page tree
Skip to end of metadata
Go to start of metadata

Often you want a script to work on the active layout window. To get this you can use the following function:

 Function awrGetActiveLayout() as Layout
  Dim sch As Schematic
  Dim w As Window
  If Not (Project.Schematics Is Nothing) And Not (Project.Schematics.ActiveSchematic Is Nothing) Then
    Set sch = Project.Schematics.ActiveSchematic
    ' unfortunately this does not tell us if the active window is a schematic or a layout.  ActiveSchematic will
    ' return the schematic for a layout if a layout window is active so we need to make sure the active window
    ' is actually a layout
    For Each w In sch.Windows
      If w.Active=True And w.Type<>mwWT_SchematicLayout Then
        'active window is not a Layout
        Set sch=Nothing
      End If
    Next w

    If Not (sch Is Nothing)  Then
      Set awrGetActiveLayout = sch.Layout
    End If
  End If
End Function


which is used like this:

  Dim activeLayout As Layout

  Set activeLayout = awrGetActiveLayout()
  If Not (activeLayout Is Nothing) Then