Jump to: Board index » General » Fusion

fusion:GetClipboard

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

john barclay

  • Posts: 8
  • Joined: Wed Nov 02, 2016 2:37 pm

fusion:GetClipboard

PostMon Mar 20, 2017 11:59 am

Hi,

I'm migrating some FU7 scripts to 8 (8.2 build 2) and here is my first problem.

The script below isn't working with the error

attempt to index a string value


Code: Select all
originalToolList = composition:GetToolList(true,"Loader")

composition:Copy(originalToolList)

clipb = fusion:GetClipboard()

dump(clipb["Tools"])


I read a post at Steakunderwater mentioning the clipboard stuff may be broken.

Cheers

J
Offline

John Tiefenbrunner

  • Posts: 45
  • Joined: Tue Mar 14, 2017 3:58 pm

Re: fusion:GetClipboard

PostTue Mar 21, 2017 5:50 pm

Tried it on a Mac and got no error message - it worked as expected. Here's the output I got (with one Loader selected in the Flow):
Code: Select all
Lua> originalToolList = composition:GetToolList(true,"Loader")
composition:Copy(originalToolList)
clipb = fusion:GetClipboard()
dump(clipb["Tools"])
table: 0x0479b498
   __flags = 2097152
   __idxtokey = table: 0x0479b4c0
      1 = __flags
      2 = Loader1
   Loader1 = table: 0x04792e20
      __ctor = Loader
      ViewInfo = table: 0x04794a10
         __ctor = OperatorInfo
         Pos = table: 0x04794a38
            1 = 779
            2 = 104
            __flags = 256
         __flags = 256
      Clips = table: 0x04792fd8
         1 = table: 0x04793000
            TimeCode = 0
            Filename = .......
            TrimIn = 0
            GlobalStart = 0
            __ctor = Clip
            Length = 40
            GlobalEnd = 39
            ExtendFirst = 0
            AspectMode = 0
            Depth = 0
            TrimOut = 39
            ID = Clip1
            FormatID = QuickTimeMovies
            Loop = 1
            ExtendLast = 0
            Multiframe = true
      Inputs = table: 0x04794800
         Gamut.SLogVersion = table: 0x04794828
            __ctor = Input
            __flags = 256
            Value = table: 0x04794888
               1 = SLog2
               __ctor = FuID
               __flags = 256
   __keytoidx = table: 0x04792d58
      __flags = 1
      Loader1 = 2
Offline

Stefan Kirste

  • Posts: 142
  • Joined: Wed Jul 30, 2014 8:45 am

Re: fusion:GetClipboard

PostMon Mar 27, 2017 1:59 pm

thats strange, it works on mac?

please can u try this:
Code: Select all
--[[--
hos_Macro2Group

A Tool script that converts a Macro to a Group and vice versa, depending on
    what type of operator/tool is selected

Note:
    This tool is not properly tested, it is a quick fix so you don't have to
    copy paste your Macro/Group in your text editor to change the operator
    type, so use at your own risk.
 
Requires   : Fusion 5.x or later
   
--]]--
version = "version 0.1 (July 10, 2012)"
--[[

 Written by Sven Neve (sven[AT]houseofsecrets[DOT]nl)
 Copyright (c) 2012 House of Secrets
 (http://www.svenneve.com)

 The authors hereby grant permission to use, copy, and distribute this
 software and its documentation for any purpose, provided that existing
 copyright notices are retained in all copies and that this notice is
 included verbatim in any distributions. Additionally, the authors grant
 permission to modify this software and its documentation for any
 purpose, provided that such modifications are not distributed without
 the explicit consent of the authors and that existing copyright notices
 are retained in all copies.

 IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR
 DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
 OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES
 THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF
 SUCH DAMAGE.

 THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
 THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND
 DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
 UPDATES, ENHANCEMENTS, OR MODIFICATIONS.

--]]
tool = comp.ActiveTool
attrs = tool:GetAttrs()
fusion = bmd.scriptapp("Fusion", "localhost")

if attrs.TOOLS_RegID == "MacroOperator" then
    comp:Copy(tool)
    macro = fusion.GetClipboard()

    if string.len(macro) == nil then
        print("Something went wrong")
        return
    end
    output = string.gsub(macro, '= MacroOperator {', '= GroupOperator {', 1)
elseif attrs.TOOLS_RegID == "GroupOperator" then
    comp:Copy(tool)
    group = getclipboard()

    if string.len(group) == nil then
        print("Something went wrong")
        return
    end
    output = string.gsub(group, '= GroupOperator {', '= MacroOperator {', 1)
else
    print("Select Macro or Group")
    return
end

setclipboard(output)
comp:SetActiveTool()
comp:Paste()

--TODO : Add some error handling, newTool and tool could be nil, so GetAttrs() could error out.
newTool = comp:ActiveTool()
newToolAttrs = newTool:GetAttrs()
toolAttrs = tool:GetAttrs()
if toolAttrs.TOOLI_Number_o_Inputs ~= newToolAttrs.TOOLI_Number_o_Inputs then
    fixNrOfInputs(toolAttrs.TOOLI_Number_o_Inputs, newToolAttrs.TOOLI_Number_o_Inputs, tool, newTool)
end
for j, input in pairs(tool:GetInputList()) do
    if input:GetAttrs().INPB_Connected then
        if newTool:GetInputList()[j] ~= nil then
            if newTool:GetInputList()[j]:GetAttrs().INPB_Connected then
            else
                newTool:GetInputList()[j]:ConnectTo(input:GetConnectedOutput())
                if(newTool:GetInputList()[j]:GetAttrs().INPB_Connected) then
                    --print("    connection successful")
                end
            end
        else
            print("Error, something blew up")
        end         
    end
end


it is a Lua Tool Script. Select a Macro, and then run the script. It works in Fu8 ?
Offline

John Tiefenbrunner

  • Posts: 45
  • Joined: Tue Mar 14, 2017 3:58 pm

Re: fusion:GetClipboard

PostTue Mar 28, 2017 8:39 pm

Oh dear!
Now I know why the first test script did work fine when I tried it: I ran it directly in the interactive console inside Fusion. When I run the same code by putting it in a script file and running it via the Script menu I get the same error as you did (the "attempt to index a string value" thing).

It seems the GetClipboard() is broken in the LuaJIT (I think Fusion is _always_ using the JustInTime compiler when it executes an external script but uses the "normal" interpreter when executing stuff interactively in the console).

Even a simple
Code: Select all
comp:Copy(comp.ActiveTool)
dump(fusion:GetClipboard())

Gives the same error ("attempt to index a string value") when run as an external script, but works fine when executed directly in the console...
Offline

john barclay

  • Posts: 8
  • Joined: Wed Nov 02, 2016 2:37 pm

Re: fusion:GetClipboard

PostMon Apr 03, 2017 10:46 am

Stefan Kirste wrote:thats strange, it works on mac?

please can u try this:

it is a Lua Tool Script. Select a Macro, and then run the script. It works in Fu8 ?


Hi,
Nope. I don't get the macro from the clipboard

Error: HOS_macro2group.lua:53: bad argument #1 to 'len' (string expected, got nil)

Sorry for the late response. I'm just getting back to this now.

J

Return to Fusion

Who is online

Users browsing this forum: No registered users and 16 guests