Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- #SETMODE 777
- #----------------------------------------------------------------------------------------#
- #------------------------------------------------------------------------------ HEADER --#
- """
- :author:
- Kayla O'Neill
- :synopsis:
- This tool writes out an ABC cache to the disk. This tool can also import an ABC cache into the current maya scene.
- :description:
- To export an object to an alembic cache, this tool takes user inputs for the name of the object to be cached and
- for the name of the path the .abc file will be exported to. The cache length will be exported as the current length
- of the time slider in Maya. The cache file will export to a local temporary directory if a specific path is not
- input.
- To import an alembic cache file, this tool takes user input for the name of the path where the .abc file is located.
- The specified alembic cache file will be imported to the maya scene.
- :applications:
- Maya
- """
- #----------------------------------------------------------------------------------------#
- #----------------------------------------------------------------------------- IMPORTS --#
- # Default Python Imports
- import maya.cmds as cmds
- import tempfile
- # Imports That You Wrote
- #----------------------------------------------------------------------------------------#
- #--------------------------------------------------------------------------- FUNCTIONS --#
- #----------------------------------------------------------------------------------------#
- #----------------------------------------------------------------------------- CLASSES --#
- class ExportCache(object):
- """
- Caches out a specified object and then exports to either a default or specified path
- """
- def __init__(self, obj_name=None, file_path=None):
- self.cache_geo = obj_name
- self.path = file_path
- def export_cache(self):
- """
- Identifies the start and end frames for the cache. Then using the user input for obj_name and file_path,
- exports an alembic cache of the specified object to either a specified directory or a temporary directory.
- :return: The success of the operation.
- :type: bool
- """
- start_frame = cmds.playbackOptions(q=True, minTime=True)
- end_frame = cmds.playbackOptions(q=True, maxTime=True)
- path_command = "-frameRange %s %s -dataFormat ogawa -root %s -file %s" % \
- (start_frame, end_frame, self.cache_geo, self.path)
- zero_path_command = "-frameRange %s %s -dataFormat ogawa -root %s -file %s" % \
- (start_frame, end_frame, self.cache_geo, tempfile.mkdtemp())
- if self.path:
- cmds.AbcExport(j = path_command)
- else:
- cmds.AbcExport(j = zero_path_command)
- class ImportCache(object):
- """
- Imports a specified file into the current maya scene
- """
- def __init__(self, file_path=None):
- self.importCache = file_path
- def import_cache(self):
- """
- Uses the user input for file_path to import a specific .abc cache file
- :return: The success of the operation
- """
- import_command = "-mode cmds.import %s" % self.importCache
- cmds.AbcImport(import_command)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement