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" Set CoordSys Layout Units "in" map_windowid = LayoutItemInfo( layout_windowid, mapframe_id, LAYOUT_ITEM_INFO_WIN) Dim fFrameX, fFrameY, fFramePositionY, fFrameWidth, fFrameHeight, legend_width, legend_width_max 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) legend_width = LayoutItemInfo(layout_windowid, LayoutInfo(layout_windowid, LAYOUT_INFO_NUM_ITEMS), LAYOUT_ITEM_INFO_WIDTH) legend_width_max = Maximum(legend_width_max, legend_width) print "Max Legend width: " & legend_width_max Next 'nLayer print ("Created Legend...creating frame") ' // Create frame to sit behind legend and create white space 'legend_width_max=2 'this should be max of the widths of every legend item. 'print (legend_width_max) Create Rect (fFrameX, fFrameY) (fFrameX+legend_width_max,fFramePositionY) Pen (1,2,0) Brush (2,16777215,16777215) Priority 1 print ("Collected layer/map info") End Sub