Jump to: Board index » General » Fusion

settings = BS.SaveSettings() is different in lua and python

Learn about 3D compositing, animation, broadcast design and VFX workflows.
  • Author
  • Message
Offline

LeonhardRender

  • Posts: 92
  • Joined: Thu Feb 09, 2023 7:23 pm
  • Real Name: Leonhard Scarlet

settings = BS.SaveSettings() is different in lua and python

PostThu Sep 12, 2024 7:43 pm

In LUA,
Code: Select all
 settings = BS:SaveSettings()
returns
Code: Select all
table: 0x026ab338
table: 0x026934c0


But in python
Code: Select all
settings = BS.SaveSettings()
returns
Code: Select all
{'Tools': OrderedDict([('XYPath2X', {'__ctor': 'BezierSpline', 'SplineColor': {'__flags': 256, 'Red': 255, 'Green': 77, 'Blue': 0}, 'CtrlWZoom': False, 'NameSet': True, 'KeyFrames': {0.0: {'__flags': 256, 1: 0.0, 'RH': {'__flags': 256, 1: 0.6666666666666666, 2: 0.0}, 'Flags': {'__flags': 256, 'Linear': True}}, 2.0: {'__flags': 256, 1: 0.0, 'LH': {'__flags': 256, 1: 1.3333333333333333, 2: 0.0}, 'Flags': {'__flags': 256, 'Linear': True}}}})])}
{'Tools': OrderedDict([('XYPath2Y', {'__ctor': 'BezierSpline', 'SplineColor': {'__flags': 256, 'Red': 0, 'Green': 255, 'Blue': 76}, 'CtrlWZoom': False, 'NameSet': True, 'KeyFrames': {0.0: {'__flags': 256, 1: 0.0, 'RH': {'__flags': 256, 1: 0.6666666666666666, 2: 0.0}, 'Flags': {'__flags': 256, 'Linear': True}}, 2.0: {'__flags': 256, 1: 0.0, 'LH': {'__flags': 256, 1: 1.3333333333333333, 2: 0.0}, 'Flags': {'__flags': 256, 'Linear': True}}}})])}


The interesting thing is that
Code: Select all
print(BS)
in python and LUA return the same thing
Code: Select all
BezierSpline (0x000001A1EAF6C100) [App: 'Resolve' on 127.0.0.1, UUID: 3fe34d2b-4d2f-4f9d-bd61-915342420437]
BezierSpline (0x000001A1EAF6D0C0) [App: 'Resolve' on 127.0.0.1, UUID: 3fe34d2b-4d2f-4f9d-bd61-915342420437]


But settings = BS.SaveSettings() returns different for Python and LUA

I'm trying to get the same result from lua in python, because I need the following structure to make some modifications. I've been trying this for a few days, but to no avail.
Offline
User avatar

Andrew Hazelden

  • Posts: 592
  • Joined: Sat Dec 06, 2014 12:10 pm
  • Location: West Dover, Nova Scotia, Canada

Re: settings = BS.SaveSettings() is different in lua and pyt

PostThu Sep 12, 2024 9:08 pm

LeonhardRender wrote:I'm trying to get the same result from lua in python, because I need the following structure to make some modifications. I've been trying this for a few days, but to no avail.


Try looking for the term a "Lua table" structure when browsing through Lua scripting documentation. If you look at the Fusion 8 Scripting Manual PDF guide, it should also help you become more comfortable with Lua tables when accessing values on Fusion nodes.

If you want to look at the content held inside a Lua table you would use:

Code: Select all
==settings


or

Code: Select all
dump(settings)


The "dump()" function or the dump shortcut "==" will print out the contents of a Lua table. This data structure is similar in concept to a C-code structure, or a JSON array, Python dict, etc.

You can interate through the key/value pairs in a Lua table in several different ways. You can directly specify the index of the data field you want like "dump(settings[1])" or you can use pairs() or ipairs() to walk through the table data in a loop.

If you look through the Fusion 8 scripting guide you will also see another way to access node data by asking the node, or the comp, or fusion objects to report their attributes as a Lua table. Once you get the Lua table you can the operate on those key/value pair records.

Code: Select all
==Merge1:GetAttrs()
Mac Studio M2 Ultra / Threadripper 3990X | Fusion Studio 18.6.4 | Kartaverse 6
Offline

LeonhardRender

  • Posts: 92
  • Joined: Thu Feb 09, 2023 7:23 pm
  • Real Name: Leonhard Scarlet

Re: settings = BS.SaveSettings() is different in lua and pyt

PostThu Sep 12, 2024 9:25 pm

Andrew Hazelden wrote: it should also help you become more comfortable with Lua tables when accessing values on Fusion nodes.

Thanks Andrew, but I was trying to get the same result from LUA in Python. For example:
Code: Select all
table: 0x026ab338
table: 0x026934c0
instead of
Code: Select all
{'Tools': OrderedDict([('XYPath2X', {'__ctor': 'BezierSpline', 'SplineColor': {'__flags': 256, 'Red': 255, 'Green': 77, 'Blue': 0}, 'CtrlWZoom': False, 'NameSet': True, 'KeyFrames': {0.0: {'__flags': 256, 1: 0.0, 'RH': {'__flags': 256, 1: 0.6666666666666666, 2: 0.0}, 'Flags': {'__flags': 256, 'Linear': True}}, 2.0: {'__flags': 256, 1: 0.0, 'LH': {'__flags': 256, 1: 1.3333333333333333, 2: 0.0}, 'Flags': {'__flags': 256, 'Linear': True}}}})])}
{'Tools': OrderedDict([('XYPath2Y', {'__ctor': 'BezierSpline', 'SplineColor': {'__flags': 256, 'Red': 0, 'Green': 255, 'Blue': 76}, 'CtrlWZoom': False, 'NameSet': True, 'KeyFrames': {0.0: {'__flags': 256, 1: 0.0, 'RH': {'__flags': 256, 1: 0.6666666666666666, 2: 0.0}, 'Flags': {'__flags': 256, 'Linear': True}}, 2.0: {'__flags': 256, 1: 0.0, 'LH': {'__flags': 256, 1: 1.3333333333333333, 2: 0.0}, 'Flags': {'__flags': 256, 'Linear': True}}}})])}
Offline
User avatar

Andrew Hazelden

  • Posts: 592
  • Joined: Sat Dec 06, 2014 12:10 pm
  • Location: West Dover, Nova Scotia, Canada

Re: settings = BS.SaveSettings() is different in lua and pyt

PostThu Sep 12, 2024 10:08 pm

LeonhardRender wrote:
Andrew Hazelden wrote: it should also help you become more comfortable with Lua tables when accessing values on Fusion nodes.

Thanks Andrew, but I was trying to get the same result from LUA in Python. For example: [code]table:


Can you explain in more detail what you are hoping to do next? Then a more useful reply could be made.

Soo... In Lua the print command does not expand and list the contents of a Lua table held in a variable. You will have to decide of you want to see what data is stored in the table or not. I'd expect most users making non-trivial Lua scripts would need this capacity.

An ordered dict is not something that exists in Lua. You can export that ordered dict to JSON text or a Lua table if you want to bridge code and data between the Resolve/Fusion Lua and Python implementations.
Mac Studio M2 Ultra / Threadripper 3990X | Fusion Studio 18.6.4 | Kartaverse 6
Offline

LeonhardRender

  • Posts: 92
  • Joined: Thu Feb 09, 2023 7:23 pm
  • Real Name: Leonhard Scarlet

Re: settings = BS.SaveSettings() is different in lua and pyt

PostFri Sep 13, 2024 2:14 am

Andrew Hazelden wrote:Can you explain in more detail what you are hoping to do next? Then a more useful reply could be made.


I'm trying to convert the following LUA script to Python
Code: Select all
fu = Fusion()
composition =  fu:GetCurrentComp()
comp = composition

local PlainInput = comp.Transform1.Center
local KEY = {
   X = {
      [0] = { 0.3, RH = { 0.6, 0.3 } },
      [2] = { 0.5, LH = { 1.3, 0.5 } }
   },
   Y = {
      [0] = { 0.9, RH = { 0.6, 0.9 } },
      [2] = { 0.7, LH = { 1.3, 0.7 } }
   }
}


local BS = PlainInput:GetConnectedOutput():GetTool()

if BS.ID == "XYPath" then
   local XY = BS
   local Inputs = XY:GetInputList()
   if Inputs[1] ~= nil then
      for _, v in ipairs(Inputs) do
         if KEY[v.ID] then
            local bs = v:GetConnectedOutput()
            if bs ~= nil then
               local BS = bs:GetTool()
               if BS.ID == "BezierSpline" then
                  local name = BS.Name
                  local settings = BS:SaveSettings()
                  settings.Tools[name].KeyFrames = KEY[v.ID]
                  BS:LoadSettings(settings)
               end
            end
         end
      end
   end
end



This is the Python version of it that I'm converting

Code: Select all
resolve = bmd.scriptapp('Resolve')
fu = resolve.Fusion()

composition = fu.GetCurrentComp()
comp = composition

PlainInput = comp.Transform1.Center
KEY = {
    "X": {
        0: {"value": 0.3, "RH": {0.666666666666667: 0.3}},
        2: {"value": 0.5, "LH": {1.33333333333333: 0.5}}
    },
    "Y": {
        0: {"value": 0.9, "RH": {0.666666666666667: 0.9}},
        2: {"value": 0.7, "LH": {1.33333333333333: 0.7}}
    }
}


BS = PlainInput.GetConnectedOutput().GetTool()

if BS.ID == "XYPath":
    XY = BS
    Inputs = XY.GetInputList()
    if Inputs:
        for _, v in Inputs.items():
            if v.ID in KEY:
                bs = v.GetConnectedOutput()
                if bs is not None:
                    BS = bs.GetTool()
                    #print(BS)
                    if BS.ID == "BezierSpline":
                        name = BS.Name
                        settings = BS.SaveSettings()                   
                        settings['Tools'][name]['KeyFrames'] = KEY[v.ID]
                        BS.LoadSettings(settings)


But there's something wrong because this code conversion doesn't work, the only part where a variable returns something different from what is expected, compared to the original LUA, is the part:
Code: Select all
settings = BS.SaveSettings()


So I think this piece of code is wrong.

In lua this snippet returns:
Code: Select all
table: 0x026ab338
table: 0x026934c0


In python it returns:
Code: Select all
{'Tools': OrderedDict([('XYPath2X', {'__ctor': 'BezierSpline', 'SplineColor': {'__flags': 256, 'Red': 255, 'Green': 77, 'Blue': 0}, 'CtrlWZoom': False, 'NameSet': True, 'KeyFrames': {0.0: {'__flags': 256, 1: 0.0, 'RH': {'__flags': 256, 1: 0.6666666666666666, 2: 0.0}, 'Flags': {'__flags': 256, 'Linear': True}}, 2.0: {'__flags': 256, 1: 0.0, 'LH': {'__flags': 256, 1: 1.3333333333333333, 2: 0.0}, 'Flags': {'__flags': 256, 'Linear': True}}}})])}
{'Tools': OrderedDict([('XYPath2Y', {'__ctor': 'BezierSpline', 'SplineColor': {'__flags': 256, 'Red': 0, 'Green': 255, 'Blue': 76}, 'CtrlWZoom': False, 'NameSet': True, 'KeyFrames': {0.0: {'__flags': 256, 1: 0.0, 'RH': {'__flags': 256, 1: 0.6666666666666666, 2: 0.0}, 'Flags': {'__flags': 256, 'Linear': True}}, 2.0: {'__flags': 256, 1: 0.0, 'LH': {'__flags': 256, 1: 1.3333333333333333, 2: 0.0}, 'Flags': {'__flags': 256, 'Linear': True}}}})])}


Edit:

Return to Fusion

Who is online

Users browsing this forum: No registered users and 14 guests