Page 1 of 1

Old Scripts not running in Fusion 8 or above

PostPosted: Tue Mar 21, 2017 3:45 pm
by vinayragbotra
Why scripts are not working properly in fusion 8 , as these are working fine in version 7 or previous.
i am using


readdir("d:\\*.*")


this is not working. not reading the folders in fusion 8.
plzzzz help me.

Re: Old Scripts not running in Fusion 8 or above

PostPosted: Tue Mar 21, 2017 6:04 pm
by Andrew Hazelden
Hi. The readdir command comes from the addon lua-fs library that is not available with the version of Lua that is included in Fusion 8.

You will have to re-write your Fusion 7 based Lua code to work around this limitation to make the script work in the current Fusion 8.2 release.

At the same time your older Fusion 7 scripts will also need to probably have the Lua ipairs code changed as well.

Re: Old Scripts not running in Fusion 8 or above

PostPosted: Wed Mar 22, 2017 5:08 am
by vinayragbotra
Hi sir
Thank you so much for your reply.


I dont have much knowledge in lua scripting.


I have used LUA ipairs and that is working now.

But what should i use to make "readdir" run in fusion 8.?

Re: Old Scripts not running in Fusion 8 or above

PostPosted: Wed Mar 22, 2017 11:20 am
by Andrew Hazelden
Are you trying to adapt one of the bundled Fusion 7 Lua scripts or something you've created on your own?

Re: Old Scripts not running in Fusion 8 or above

PostPosted: Wed Mar 22, 2017 4:00 pm
by vinayragbotra
i create this script.
Here is basic example.

Code: Select all
username =string.lower(os.getenv("USERNAME"))
print(username)


fusion = Fusion("localhost")
composition = fusion:GetCurrentComp()
SetActiveComp(composition)

   drive       =   "d:\\"

   dfolders    =   drive.."*.*"
   ddir      =   readdir(dfolders)
   ddircount    =    table.getn(ddir)

ndirs = {}

   for i = 1,ddircount do
         
         prj = string.upper(ddir[i].Name)   
         table.sort(ndirs)
         table.sort(ndirs)
         
   end
   
data = AskUser("Selector", {
                           {"name",   Name = "USERNAME", "Text",    Default = username,          Lines = 1},
                           {"fill01",  Name = "", "Position", Default = {1, 0.5},   Width = 1.5},
                           {"project", Name = "Select project",    "Dropdown", Options = ndirs, Default = 0},
                           })   
                           
                           
                           if data == nil then
                           return
                           end
                           
                           
                        --  if didnt entered name
                           
                           if data["name"] == "" or data["name"] == " " or data["name"] == "  " or data["name"] == "   " then                           
                           no_name = AskUser("Error", {
                                                   {"info", Name = "No Name", "Text", Lines = 2, Width = 1.5, ReadOnly = true, FontName = "Calibri", FontSize = 18, Default = "You did not entered your name,\nRun Script again and Enter name first"},   
                                                
                                                   })
                                                      
                           
                              if no_name == nil then                              
                              return
                              end
                           return
                           end


trn_name = string.lower(data["trainee"])

Re: Old Scripts not running in Fusion 8 or above

PostPosted: Wed Mar 22, 2017 4:58 pm
by Andrew Hazelden
Here is a Lua native code snippet example that works with Fusion 7 & 8 and lets you scan a folder for its contents on Windows/Mac/Linux. The directory contents are then filtered by filetype.

You can modify the code to wrap it in your own function to replace your legacy readdir based commands if you want.

Code: Select all
------------------------------------------------------------------------------
-- Scan a Directory Script for Fusion - 2017-03-22 01.53 PM
-- by Andrew Hazelden
-- www.andrewhazelden.com
-- andrew@andrewhazelden.com
------------------------------------------------------------------------------

-- Folder to scan for content
sourceFolder = '/FusionMedia/images/'

-- Find out the current operating system platform. The platform local variable should be set to either 'Windows', 'Mac', or 'Linux'.
local platform = ''
local osSeparator = ''
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'
  osSeparator = '\\'
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'
  osSeparator = '\\'
elseif string.find(comp:MapPath('Fusion:\\'), 'Applications', 1) then
  -- Check if the OS is Mac by searching for the Applications folder
  platform = 'Mac'
  osSeparator = '/'
else
  platform = 'Linux'
  osSeparator = '/'
end

-- Create a new LUA table for the files to process 
filesList = {}

-- Build the OS native scan a directory command string
dirCommand = ''
if platform == 'Windows' then
  -- The dir options '/b /ad' lists directories and '/b' lists just files
  dirCommand = 'dir ' .. sourceFolder .. ' /b'
else
  dirCommand = 'ls -a "' .. sourceFolder .. '"'
end

print('[Directory Listing]')
-- Search the selected directory for movie content
for files in io.popen(dirCommand):lines() do
  -- List the files
  -- print(files)
 
  -- Add another file to the filesList table
  fileNoCase = files.lower(files)
  if fileNoCase:match('.*%.tif') then
    table.insert(filesList, files)
  end
end

-- List what's in the table
print('[Movie Listing]')
dump(filesList)

print('\n')

Re: Old Scripts not running in Fusion 8 or above

PostPosted: Fri Mar 24, 2017 4:58 am
by vinayragbotra
Thank you much sir,


this code is working.
:)
My problem is sorted out