#import clr #clr.AddReference('Manifold.Interop') #from Manifold.Interop import ComponentType # enum (easier to .TypeName instead) # ***************************************************************************************************** def Main(): list_map_layers() # ***************************************************************************************************** def list_map_layers(): (map, message) = current_map() Application.History.Log(message + '\r\n') if map is None: Application.MessageBox('Open a map, or select a map in the Project pane\rbefore running the script.', 'Current map') else: # make list of dict layer_list = [{ 'Name': layer.Component.Name, 'Order': layer.Order, 'Opacity': layer.Opacity, 'Visible': layer.Visible, # also Clickable, Editable, Selectable, Snappable 'Path': project_path(layer.Component) } for layer in map.LayerSet] # sort list by field layer_list.sort(key = lambda item: item['Name']) # transform into output list output_list = [ str(item['Order']).rjust(width = len(str(map.LayerSet.Count - 1))) + ' ' + '[' + item['Name'] + '] ' + str(item['Opacity']) + '%' + ('' if item['Visible'] else ' (hidden)') + (' : root' if item['Path'] == '' else ' : ' + item['Path']) for item in layer_list ] # create new comments component (in same folder as map) comm = Document.NewComments(map.Name + ' layers', False) comm.Folder = map.Folder # fill comments comm.Text = '[' + map.Name + '] : ' + str(map.LayerSet.Count) + ' layers\r\n' + '\r\n'.join(output_list) Application.History.Log('\t-> [' + comm.Name + ']\r\n') # ***************************************************************************************************** def current_map(): # Map component open in current window # else selected in the Project pane # else None # (1) comp = None # first try the active window if Application.WindowSet.Count == 0: pass else: comp = Application.WindowSet.ActiveWindow.Component # if comp.Type == int(ComponentType.ComponentMap): if comp.TypeName == 'Map': msg = '[' + comp.Name + '] open in active window' else: comp = None # (2) # otherwise try the component selected in the Project pane if comp is None: name = Application.UserInterface.Panes('Project').ControlSet('TreeViewComponents').Text if name == '': # no component selected pass else: comp = Document.ComponentSet.Item(name) # if comp.Type == int(ComponentType.ComponentMap): if comp.TypeName == 'Map': msg = '[' + comp.Name + '] selected in Project pane' else: comp = None if comp is None: msg = '(No map active or selected)' return (comp, msg) # ***************************************************************************************************** def project_path(comp): node = comp roots = [] while node.Owner is not None: roots.append(node.Owner) node = node.Owner while node.Folder is not None: roots.append(node.Folder) node = node.Folder roots.reverse() return '.'.join(['[' + root.Name + ']' for root in roots]) # ***************************************************************************************************** Main()