Advertisement
Guest User

Untitled

a guest
Feb 17th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. #!/usr/bin/env python
  2. #SETMODE 777
  3.  
  4. #----------------------------------------------------------------------------------------#
  5. #------------------------------------------------------------------------------ HEADER --#
  6.  
  7. """
  8. :author:
  9. Kayla O'Neill
  10.  
  11. :synopsis:
  12. This tool writes out an ABC cache to the disk. This tool can also import an ABC cache into the current maya scene.
  13.  
  14. :description:
  15. To export an object to an alembic cache, this tool takes user inputs for the name of the object to be cached and
  16. for the name of the path the .abc file will be exported to. The cache length will be exported as the current length
  17. of the time slider in Maya. The cache file will export to a local temporary directory if a specific path is not
  18. input.
  19.  
  20. To import an alembic cache file, this tool takes user input for the name of the path where the .abc file is located.
  21. The specified alembic cache file will be imported to the maya scene.
  22.  
  23. :applications:
  24. Maya
  25.  
  26. """
  27.  
  28. #----------------------------------------------------------------------------------------#
  29. #----------------------------------------------------------------------------- IMPORTS --#
  30.  
  31. # Default Python Imports
  32.  
  33. import maya.cmds as cmds
  34. import tempfile
  35.  
  36. # Imports That You Wrote
  37.  
  38. #----------------------------------------------------------------------------------------#
  39. #--------------------------------------------------------------------------- FUNCTIONS --#
  40.  
  41. #----------------------------------------------------------------------------------------#
  42. #----------------------------------------------------------------------------- CLASSES --#
  43.  
  44. class ExportCache(object):
  45. """
  46. Caches out a specified object and then exports to either a default or specified path
  47. """
  48. def __init__(self, obj_name=None, file_path=None):
  49. self.cache_geo = obj_name
  50. self.path = file_path
  51.  
  52. def export_cache(self):
  53. """
  54. Identifies the start and end frames for the cache. Then using the user input for obj_name and file_path,
  55. exports an alembic cache of the specified object to either a specified directory or a temporary directory.
  56.  
  57. :return: The success of the operation.
  58. :type: bool
  59. """
  60. start_frame = cmds.playbackOptions(q=True, minTime=True)
  61. end_frame = cmds.playbackOptions(q=True, maxTime=True)
  62. path_command = "-frameRange %s %s -dataFormat ogawa -root %s -file %s" % \
  63. (start_frame, end_frame, self.cache_geo, self.path)
  64. zero_path_command = "-frameRange %s %s -dataFormat ogawa -root %s -file %s" % \
  65. (start_frame, end_frame, self.cache_geo, tempfile.mkdtemp())
  66. if self.path:
  67. cmds.AbcExport(j = path_command)
  68. else:
  69. cmds.AbcExport(j = zero_path_command)
  70.  
  71.  
  72. class ImportCache(object):
  73. """
  74. Imports a specified file into the current maya scene
  75. """
  76. def __init__(self, file_path=None):
  77. self.importCache = file_path
  78.  
  79. def import_cache(self):
  80. """
  81. Uses the user input for file_path to import a specific .abc cache file
  82.  
  83. :return: The success of the operation
  84. """
  85. import_command = "-mode cmds.import %s" % self.importCache
  86. cmds.AbcImport(import_command)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement