Ejemplo n.º 1
0
    def save(self, path):
        """
        Save the current metadata and object data to the given path.
        
        :type path: str
        :rtype: None
        """
        logger.info("Saving pose: %s" % path)

        encoding = locale.getpreferredencoding()
        user = getpass.getuser()
        if user:
            user = user.decode(encoding)

        ctime = str(time.time()).split(".")[0]
        references = mutils.getReferenceData(self.objects())

        self.setMetadata("user", user)
        self.setMetadata("ctime", ctime)
        self.setMetadata("version", "1.0.0")
        self.setMetadata("references", references)
        self.setMetadata("mayaVersion", maya.cmds.about(v=True))
        self.setMetadata("mayaSceneFile", maya.cmds.file(q=True, sn=True))

        # Move the metadata information to the top of the file
        metadata = {"metadata": self.metadata()}
        data = self.dump(metadata)[:-1] + ","

        logger.debug("Save objects")
        logger.debug(self.objects())
        # Move the objects information to after the metadata
        objects = {"objects": self.objects()}
        data += self.dump(objects)[1:]

        # Create the given directory if it doesn't exist
        dirname = os.path.dirname(path)
        if not os.path.exists(dirname):
            os.makedirs(dirname)

        with open(path, "w") as f:
            f.write(str(data))

        logger.info("Saved pose: %s" % path)
Ejemplo n.º 2
0
    def save(self, path):
        """
        Save the current metadata and object data to the given path.
        
        :type path: str
        :rtype: None
        """
        logger.info("Saving pose: %s" % path)

        encoding = locale.getpreferredencoding()
        user = getpass.getuser()
        if user:
            user = user.decode(encoding)

        ctime = str(time.time()).split(".")[0]
        references = mutils.getReferenceData(self.objects())

        self.setMetadata("user", user)
        self.setMetadata("ctime", ctime)
        self.setMetadata("version", "1.0.0")
        self.setMetadata("references", references)
        self.setMetadata("mayaVersion", maya.cmds.about(v=True))
        self.setMetadata("mayaSceneFile", maya.cmds.file(q=True, sn=True))

        # Move the metadata information to the top of the file
        metadata = {"metadata": self.metadata()}
        data = self.dump(metadata)[:-1] + ","

        # Move the objects information to after the metadata
        objects = {"objects": self.objects()}
        data += self.dump(objects)[1:]

        # Create the given directory if it doesn't exist
        dirname = os.path.dirname(path)
        if not os.path.exists(dirname):
            os.makedirs(dirname)

        with open(path, "w") as f:
            f.write(str(data))

        logger.info("Saved pose: %s" % path)