Include "MapBasic.Def" DECLARE SUB Main SUB Main Dim num_windows,nLayer as integer num_windows = NumWindows() print (num_windows) Dim i, map_windowid, layout_windowid, legend_windowid, mapframe_id, map_layer_count as integer layout_windowid = FrontWindow() If layout_windowid = 0 Then Note "Please open a layout window!" Exit Sub End If If not WindowInfo(layout_windowid, WIN_INFO_TYPE) = WIN_LAYOUT_DESIGNER Then Note "Please make a layout window the active window!" Exit Sub End If mapframe_id = LayoutItemID(layout_windowid, "TheMapFrame", LAYOUT_ITEM_TYPE_MAPPER) If mapframe_id = -1 Then Note "The frame with the map not found. It should be named 'TheMapFrame'" Exit Sub End If Set Paper Units "in" map_windowid = LayoutItemInfo( layout_windowid, mapframe_id, LAYOUT_ITEM_INFO_WIN) Dim fFrameX, fFrameY, fFramePositionY, fFrameWidth, fFrameHeight As Float fFrameX = LayoutItemInfo( layout_windowid, mapframe_id, LAYOUT_ITEM_INFO_POS_X) fFrameY = LayoutItemInfo( layout_windowid, mapframe_id, LAYOUT_ITEM_INFO_POS_Y) fFrameWidth = LayoutItemInfo( layout_windowid, mapframe_id, LAYOUT_ITEM_INFO_WIDTH) fFrameHeight = LayoutItemInfo( layout_windowid, mapframe_id, LAYOUT_ITEM_INFO_HEIGHT) fFramePositionY = fFrameY map_layer_count = MapperInfo(map_windowid, MAPPER_INFO_LAYERS) ' print (map_layer_count) 'LayerListInfo(map_window_id, numeric_counter, attribute ) '**This is where we build the legend in the layout '**I'm just adding a static 2 inces to the position for each layer '**- that needs to depend on the size of the previous frame For nLayer = 1 to map_layer_count Print "Position (2.0, " & fFramePositionY & ")" If nLayer = 1 Then Create Designer Legend Custom Frame From Layer nLayer Position (fFrameX, fFramePositionY) Units "in" Using Label LayerInfo(map_windowid, nLayer, LAYER_INFO_ALIAS) legend_windowid = LayoutItemInfo(layout_windowid, LayoutInfo(layout_windowid, LAYOUT_INFO_NUM_ITEMS), LAYOUT_ITEM_INFO_LEGEND_DESIGNER_WINDOW) Else Add Designer Frame Window legend_windowid Custom Frame From Layer nLayer Position (fFrameX, fFramePositionY) Units "in" Using Label LayerInfo(map_windowid, nLayer, LAYER_INFO_ALIAS) End If fFramePositionY = fFramePositionY + LayoutItemInfo(layout_windowid, LayoutInfo(layout_windowid, LAYOUT_INFO_NUM_ITEMS), LAYOUT_ITEM_INFO_HEIGHT) Next 'nLayer print ("Collected layer/map info") End Sub