export-toonz.lua 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. export = {}; -- create a new export object
  2. -- return label
  3. function export:label()
  4. return "Toonz";
  5. end
  6. -- return category
  7. function export:category()
  8. return "2D";
  9. end
  10. -- return argument list
  11. function export:options()
  12. groups = {};
  13. for a,actor in magpie.getactors() do
  14. for g,group in magpie.getgroups(actor) do
  15. table.insert(groups, group);
  16. end
  17. end
  18. return {
  19. {"group", "Group", "choice", table.concat(groups, "|")},
  20. {"toonz_output_file", "Output File", "output_file", "Text files (*.tls)\tAll files (*.*)"}
  21. };
  22. end
  23. -- perform the export
  24. function export:run(from, to, options)
  25. -- open output file
  26. fd = io.open(options.toonz_output_file, "wt");
  27. if (fd == nil) then
  28. return string.format("could not open '%s'", options.toonz_output_file);
  29. end
  30. -- write header line to file
  31. fd:write("Toonz\n");
  32. -- create an array of all the poses that are being exported
  33. line = "";
  34. poses = magpie.getposes(options.group);
  35. for p,pose in poses do
  36. line = string.gsub(pose, "[^%.]+%.", "");
  37. fd:write(line, "\n");
  38. line = "";
  39. end
  40. -- write data to file
  41. for frame = from, to do
  42. line = "";
  43. line = frame + magpie.getframeoffset();
  44. k = nil;
  45. k = magpie.getgroupvalue(frame, options.group);
  46. if (k ~= nil) then
  47. k = string.gsub(k, "[^%.]+%.", ""); -- remove actor and group name from string
  48. end
  49. if (k == nil) then
  50. k = "<none>";
  51. end
  52. if (line ~= "") then
  53. line = line .. "|";
  54. end
  55. line = line .. k;
  56. if (line ~= "") then
  57. line = line .. "|";
  58. end
  59. comment = magpie.getframecomment(frame);
  60. if (comment ~= "") then
  61. is_empty = false;
  62. else
  63. comment = "<none>";
  64. end
  65. line = line .. comment;
  66. fd:write(line, "\n");
  67. -- update progress bar in main window
  68. magpie.progress("Exporting...", (frame - from) / (to - from));
  69. end
  70. magpie.progress("", 0); -- close progress bar
  71. fd:close(); -- close output file
  72. end