Fu fusion.setclipboard() not functional  [FIXED]

Moderator: Chad

User avatar
SecondMan
Site Admin
Posts: 3580
Joined: Thu Jul 31, 2014 5:31 pm
Answers: 5
Location: Vancouver, Canada
Been thanked: 104 times
Contact:

fusion.setclipboard() not functional

#1

Post by SecondMan » Sun Mar 12, 2017 2:42 pm

Fusion version:

8.2.1 build 6

Description of the bug:

fusion.setclipboard() is not working as described on page 122 of the Scripting Manual (in fact it's on there twice) - the function does nothing.

Severity (Trivial, Minor, Major, Critical)

Minor, there are workarounds like pushing the data into an AskUser dialog from which the data can be copied to the Clipboard, or running something like xclip through os.execute(), but there is no other native way available in Lua.

User avatar
AndrewHazelden
Fusionator
Posts: 1387
Joined: Fri Apr 03, 2015 3:20 pm
Answers: 4
Location: West Dover, Nova Scotia, Canada
Been thanked: 59 times
Contact:

Re: fusion.setclipboard() not functional

#2

Post by AndrewHazelden » Mon Mar 13, 2017 2:34 am

It's funny you mention xclip... That's the technique I've had to use for the last year and a bit. :popcorn:

Here is a Lua code block that might be helpful for other people if they want a cross-platform seamless way to use Fusion with xclip (Linux), clip (Windows), and pbcopy (macOS):

Code: Select all

------------------------------------------------------------------------------
-- Copy to Clipboard Script for Fusion - 2017-03-13 06.27 AM 
-- by Andrew Hazelden
-- www.andrewhazelden.com
-- andrew@andrewhazelden.com
------------------------------------------------------------------------------

-- Display the extra debugging verbosity detail in the console log
printStatus = true
-- printStatus = false

-- Find out if we are running Fusion 6, 7, or 8
local fu_major_version = math.floor(tonumber(eyeon._VERSION))

-- Find out the current operating system platform. The platform local variable should be set to either 'Windows', 'Mac', or 'Linux'.
local platform = ''
if string.find(comp:MapPath('Fusion:\\'), 'Program Files', 1) then
  -- Check if the OS is Windows by searching for the Program Files folder
  platform = 'Windows'
elseif string.find(comp:MapPath('Fusion:\\'), 'PROGRA~1', 1) then
  -- Check if the OS is Windows by searching for the Program Files folder
  platform = 'Windows'
elseif string.find(comp:MapPath('Fusion:\\'), 'Applications', 1) then
  -- Check if the OS is Mac by searching for the Applications folder
  platform = 'Mac'
else
  platform = 'Linux'
end


-- Copy text to the operating system's clipboard
-- Example: CopyToClipboard('Hello World!')
function CopyToClipboard(textString)
  -- The system temporary directory path (Example: $TEMP/DomemasterFusionMacros/)
  outputDirectory = comp:MapPath('Temp:\\DomemasterFusionMacros\\')
  clipboardTempFile = outputDirectory .. 'ClipboardText.txt'

  -- Create the temp folder if required
  os.execute('mkdir "' .. outputDirectory .. '"')

  -- Open up the file pointer for the output textfile
  outClipFile, err = io.open(clipboardTempFile,'w')
  if err then 
    print("[Error Opening Clipboard Temporary File for Writing]")
    return
  end

  outClipFile:write(textString,'\n')

  -- Close the file pointer on the output textfile
  outClipFile:close()

  if platform == 'Windows' then
    -- The Windows copy to clipboard command is "clip"
    command = 'clip < "' .. clipboardTempFile .. '"'
  elseif platform == 'Mac' then
    -- The Mac copy to clipboard command is "pbcopy"
    command = 'pbcopy < "' .. clipboardTempFile .. '"'
  elseif platform == 'Linux' then
    -- The Linux copy to clipboard command is "xclip"
    -- This requires a custom xclip tool install on Linux:
  
    -- Debian/Ubuntu:
    -- sudo apt-get install xclip
  
    -- Redhat/Centos/Fedora:
    -- yum install xclip
    command = 'cat "' .. clipboardTempFile .. '" | xclip -selection clipboard &'
  end

  if printStatus == 1 or printStatus == true then
    print('[Copy Text to Clipboard Command] ' .. command)
    print('[Clipboard] ' .. textString)
  end
  os.execute(command)
end

------------------------------------------------------------------------------
------------------------------------------------------------------------------

-- Copy Text to the clipboard
-- CopyToClipboard('Hello World!')

-- Copy the selected Loader node filepath to the clipboard
selectedNode = comp.ActiveTool
CopyToClipboard(selectedNode.Output[comp.CurrentTime].Metadata.Filename)


User avatar
PeterLoveday
Fusioneer
Posts: 155
Joined: Sun Sep 14, 2014 6:09 pm
Answers: 6
Been thanked: 17 times

Re: fusion.setclipboard() not functional

#3

Post by PeterLoveday » Tue Aug 22, 2017 1:31 am

bmd.get/setclipboard now work, as previously with eyeon.* ?

User avatar
AndrewHazelden
Fusionator
Posts: 1387
Joined: Fri Apr 03, 2015 3:20 pm
Answers: 4
Location: West Dover, Nova Scotia, Canada
Been thanked: 59 times
Contact:

Re: fusion.setclipboard() not functional  [FIXED]

#4

Post by AndrewHazelden » Wed Aug 23, 2017 2:23 pm

PeterLoveday wrote:bmd.get/setclipboard now work, as previously with eyeon.* ?
Thanks for the suggestion to check that out again in Fusion 9.

Here is a short Lua script snippet I created today that uses Fusion + Lua to copy the Linux/MacOS system environment variables into your clipboard buffer:

Code: Select all

local handler = io.popen('/usr/bin/env');local response = handler:read("*a");bmd.setclipboard(tostring(response))