# Extract all opened LT views as images Use `CopyToClipboard` command to avoid the error in the file name handling in LT scripts. ``` import win32clipboard import io def get_clipboard_image(): win32clipboard.OpenClipboard() try: if win32clipboard.IsClipboardFormatAvailable(win32clipboard.CF_DIB): data = win32clipboard.GetClipboardData(win32clipboard.CF_DIB) image = Image.open(io.BytesIO(data)) return image finally: win32clipboard.CloseClipboard() return None timestr = time.strftime("%Y%m%d-%H-%M-%S") num_views, stat=lt.DbGet('Lens_Manager[1]', 'NumberOfViews') num_views = int(num_views) output_path = 'E:\\Wayne\\Temp\\20230810\\' lt.Message(f'{timestr}') for i in range(1, num_views + 1): #Generate a key for each view viewkey='View[' + str(i) + ']' #Get the name of the view viewname, stat=lt.ViewGet(viewkey,'Title') #Loop through all views if viewname != None: viewname = viewname.replace(' ', '_') stat = lt.Cmd(f'\\V{viewname}') view_stat = 'Success' if stat != 0: view_stat = 'Failed' stat = lt.Cmd(f'CopyToClipboard') copy_stat = 'Success' if stat != 0: copy_stat = 'Failed' print(f'view name:{viewname}, view change: {view_stat}, copy: {copy_stat}') # Get the image from the clipboard clipboard_image = get_clipboard_image() if isinstance(clipboard_image, Image.Image): # Save the image to a file clipboard_image.save(f'{output_path}{viewname}_{timestr}.png', "PNG") else: print("No image data found in the clipboard!") ```