Viewer LUT info via script

User avatar
ISOTRON
Fusioneer
Posts: 143
Joined: Mon Aug 04, 2014 11:54 am
Location: Germany, Munich
Contact:

Viewer LUT info via script

#1

Post by ISOTRON » Fri Apr 20, 2018 3:39 am

Hi,

anyone knows a command to get the used LUT in the viewer? I only find "GLImageView.IsLUTEnable()" but i need the info which lut is selected.

User avatar
Greg Bovine
Double M
Posts: 112
Joined: Fri Feb 02, 2018 6:07 am
Location: Oslo, Norway
Been thanked: 29 times
Contact:

Re: Viewer LUT info via script

#2

Post by Greg Bovine » Fri Apr 20, 2018 7:51 am

ISOTRON wrote:
Fri Apr 20, 2018 3:39 am
anyone knows a command to get the used LUT in the viewer? I only find "GLImageView.IsLUTEnable()" but i need the info which lut is selected.
You could always do it brute force style by reading the current .comp file on disk as a Lua table to get that setting. :D

This is a simplified view of a .comp file's Left viewer Lua table layout:

Code: [Select all] [Expand/Collapse] [Download] (viewer contents.comp)
  1. Composition {
  2.     Prefs = {
  3.         Comp = {
  4.             Views = {
  5.                 Left = {
  6.                     Viewer = {
  7.                         EnableLUTs = true,
  8.                         LUTPlugin = "ViewLUTMacro.BrightLUT",
  9.                         ScaleMode = 1,
  10.                         LUTSelected = "Bright LUT"
  11.                     },
  12.                 },
  13.             },
  14.         },
  15.     },
  16. }
This example Lua script shows how to walk through a .comp file's table structure so you can access the viewer elements and read the active LUT name:

left viewer settings.png
Code: [Select all] [Expand/Collapse] [Download] (Probe Composite Viewer Table.lua)
  1. compFile = comp:GetAttrs().COMPS_FileName
  2. if compFile then
  3.     compData = bmd.readfile(fusion:MapPath(compFile))
  4.     if compData then
  5.         -- Dump the full .comp file table into the Console view
  6.         -- dump(compData)
  7.        
  8.         -- Check if the viewer windows were found
  9.         if compData and compData.Prefs and compData.Prefs.Comp and compData.Prefs.Comp.Views and compData.Prefs.Comp.Views then
  10.             views = compData.Prefs.Comp.Views
  11.             -- Dump the viewer contents
  12.             -- dump(views)
  13.            
  14.             -- Check for the viewer contexts
  15.             if views and views.Left and views.Left.Viewer and views.Left.Viewer then
  16.                 leftViewer = views.Left.Viewer
  17.                 print('\n\n[left Viewer]')
  18.                 dump(leftViewer)
  19.             end
  20.             if views and views.Right and views.Right.Viewer and views.Right.Viewer then
  21.                 rightViewer = views.Right.Viewer
  22.                 print('\n\n[Right Viewer]')
  23.                 dump(rightViewer)
  24.             end
  25.         else
  26.             print('[Viewer Prefs Warning] The Viewer window prefs are nil.')
  27.         end
  28.     else
  29.         print('[Comp Data Warning] The .comp file contents is nil.')
  30.     end
  31. else
  32.     print('[Please save the Fusion composite to disk] The filename is nil.')
  33. end

Here is a short code snippet with the Fusion v7-9, and Resolve 15 "CurrentViewer" attributes specified for when you want to load in a new LUT:

Code: [Select all] [Expand/Collapse] [Download] (ViewerLut.lua)
  1. -- Load a lut into the viewer window and show the edit settings
  2.  
  3. -- Note: Fu 7 used this legacy view format:
  4. -- view = comp.CurrentFrame.LeftView.CurrentViewer
  5.  
  6. -- Note: Fu 8/9 uses this view format:
  7. view = comp:GetPreviewList().Left.View.CurrentViewer
  8.  
  9. -- Resolve 15 uses this view format:
  10. -- view = comp:GetPreviewList().LeftView.View.CurrentViewer
  11.  
  12. -- Change the Lut
  13. filename = comp:MapPath("LUTs:/Bright LUT.setting")
  14. view:LoadLUTFile(filename)
  15. view:EnableLUT(true)
  16. view:ShowLUTEditor()
And for reference, here is the old Eyeon Fusion 7 era "Create3DLUT.eyeonscript" Lua script example for interacting with LUTs:
Code: [Select all] [Expand/Collapse] [Download] (Create3DLUT.eyeonscript)
  1. -- Converts a sequence of selected colour tools into a 3D LUT
  2. -- Last updated: 14-Sept-09
  3.  
  4. -- Get a handy 2D viewer
  5. view = comp.CurrentFrame.LeftView.CurrentViewer
  6. if view == nil or view:GetID() ~= "GLImageViewer" then
  7.    comp.CurrentFrame:ViewOn(1)
  8.     view = comp.CurrentFrame.LeftView.CurrentViewer
  9. end
  10.  
  11. if view == nil or view:GetID() ~= "GLImageViewer" then
  12.    print("Error - bad tool selected\n")
  13.    exit(10)
  14. end
  15.  
  16. -- Get temporary settings filename
  17. filename = comp:MapPath("Temp:TempLUTConversion.setting")
  18.  
  19. -- Copy selected tools to a table
  20. seltools = comp:CopySettings()  -- save selected tools
  21.  
  22. -- Save to settings file
  23. if eyeon.writefile(filename, seltools) == false then
  24.    print("Error saving selected tools\n");
  25.    exit(10)
  26. end
  27.  
  28. -- Save the existing LUT setup first
  29. oldLUTfilename = comp:MapPath("Temp:TempLUTBackup.viewlut")
  30. view:SaveLUTFile(oldLUTfilename)
  31.  
  32. -- Load the saved tool settings as a LUT macro
  33. if view:LoadLUTFile(filename) == false then
  34.     print("Error loading saved tools as a LUT\n")
  35.     exit(10)
  36. end
  37.  
  38. wasEnabled = view:IsLUTEnabled()
  39. view:EnableLUT(true)
  40.  
  41. -- Do the export
  42. ok, resultfilename = view:ExportTo3DLUT()   -- show UI
  43.  
  44. if resultfilename then
  45.     resultfilename = " to "..resultfilename
  46. else
  47.     resultfilename = ""
  48. end
  49.    
  50. if ok then
  51.     print("Success: LUT exported"..resultfilename.."");
  52. else
  53.     print("No LUT exported.");
  54. end
  55.  
  56. -- restore the old LUT settings
  57. view:LoadLUTFile(oldLUTfilename)
  58. view:EnableLUT(wasEnabled)
  59.  
  60. os.remove(filename)
  61. os.remove(oldLUTfilename)
You do not have the required permissions to view the files attached to this post.

User avatar
ISOTRON
Fusioneer
Posts: 143
Joined: Mon Aug 04, 2014 11:54 am
Location: Germany, Munich
Contact:

Re: Viewer LUT info via script

#3

Post by ISOTRON » Tue Apr 24, 2018 3:38 am

thanks, that looks good.