Exemplo n.º 1
0
    def save(self, objects, leftSide, rightSide, path=None, iconPath=None):
        """
        Save the given objects to the location of the current mirror table.

        :type path: str
        :type objects: list[str]
        :type iconPath: str
        :rtype: None
        """
        if path and not path.endswith(".mirror"):
            path += ".mirror"

        logger.info("Saving: %s" % self.transferPath())

        tempDir = mutils.TempDir("Transfer", makedirs=True)
        tempPath = os.path.join(tempDir.path(), self.transferBasename())

        t = self.transferClass().fromObjects(objects,
                                             leftSide=leftSide,
                                             rightSide=rightSide)
        t.save(tempPath)

        studiolibrary.LibraryItem.save(self,
                                       path=path,
                                       contents=[tempPath, iconPath])
Exemplo n.º 2
0
    def save(self, objects, path=None, iconPath=None, **kwargs):
        """
        Save the data to the transfer path on disc.

        :type path: path
        :type objects: list
        :type iconPath: str
        :raise ValidateError:
        """
        logger.info(u'Saving: {0}'.format(path))

        contents = list()
        tempDir = mutils.TempDir("Transfer", clean=True)

        transferPath = tempDir.path() + "/" + self.transferBasename()
        t = self.transferClass().fromObjects(objects)
        t.save(transferPath, **kwargs)

        if iconPath:
            contents.append(iconPath)

        contents.append(transferPath)
        studiolibrary.LibraryItem.save(self, path=path, contents=contents)

        logger.info(u'Saved: {0}'.format(path))
Exemplo n.º 3
0
    def save(self,
             objects,
             path=None,
             contents=None,
             iconPath=None,
             startFrame=None,
             endFrame=None,
             bakeConnected=False):
        """
        :type contents: list[str]
        :type iconPath: str
        :type startFrame: int
        :type endFrame: int
        :type bakeConnected: bool
        :rtype: None
        """
        contents = contents or list()

        tempDir = mutils.TempDir("Transfer", clean=True)
        tempPath = tempDir.path() + "/transfer.anim"

        t = self.transferClass().fromObjects(objects)
        t.save(tempPath,
               time=[startFrame, endFrame],
               bakeConnected=bakeConnected)

        if iconPath:
            contents.append(iconPath)

        contents.extend(t.paths())

        self.metaFile().set("start", startFrame)
        self.metaFile().set("end", endFrame)
        studiolibrary.Record.save(self, path=path, contents=contents)
Exemplo n.º 4
0
    def save(self,
             objects,
             path="",
             iconPath="",
             contents=None,
             description="",
             **kwargs):
        """
        Save the data to the transfer path on disc.

        :type objects: list[str]
        :type path: str
        :type iconPath: str
        :type contents: list[str] or None
        :type description: str

        :rtype: None
        """
        logger.info(u'Saving: {0}'.format(path))

        tempDir = mutils.TempDir("Transfer", clean=True)
        tempPath = tempDir.path() + "/" + self.transferBasename()

        t = self.transferClass().fromObjects(objects)
        t.setMetadata("description", description)
        t.save(tempPath, **kwargs)

        contents = contents or list()
        if iconPath:
            contents.append(iconPath)
        contents.append(tempPath)

        studiolibrary.LibraryItem.save(self, path=path, contents=contents)

        logger.info(u'Saved: {0}'.format(path))
Exemplo n.º 5
0
    def save(
        self,
        objects,
        path="",
        contents=None,
        iconPath="",
        fileType="",
        startFrame=None,
        endFrame=None,
        bakeConnected=False,
        metadata=None,
    ):
        """
        :type path: str
        :type objects: list[str] or None
        :type contents: list[str] or None
        :type iconPath: str
        :type startFrame: int or None
        :type endFrame: int or None
        :type fileType: str
        :type bakeConnected: bool
        :type metadata: None or dict

        :rtype: None
        """
        if path and not path.endswith(".anim"):
            path += ".anim"

        contents = contents or list()

        # Remove and create a new temp directory
        tempDir = mutils.TempDir("Transfer", clean=True)
        tempPath = tempDir.path() + "/transfer.anim"

        # Save the animation to the temp location
        anim = self.transferClass().fromObjects(objects)
        anim.updateMetadata(metadata)
        anim.save(
            tempPath,
            fileType=fileType,
            time=[startFrame, endFrame],
            bakeConnected=bakeConnected,
        )

        if iconPath:
            contents.append(iconPath)

        contents.extend(anim.paths())

        # Move the animation data to the given path using the base class
        super(AnimItem, self).save(path, contents=contents)
Exemplo n.º 6
0
    def save(
        self,
        objects,
        path="",
        contents=None,
        iconPath="",
        fileType="",
        startFrame=None,
        endFrame=None,
        bakeConnected=False,
        description="",
    ):
        """
        :type path: str
        :type objects: list[str] or None
        :type contents: list[str] or None
        :type iconPath: str
        :type startFrame: int or None
        :type endFrame: int or None
        :type fileType: str
        :type bakeConnected: bool
        :type description: str

        :rtype: None
        """
        if path and not path.endswith(".anim"):
            path += ".anim"

        contents = contents or list()

        tempDir = mutils.TempDir("Transfer", clean=True)
        tempPath = tempDir.path() + "/transfer.anim"

        t = self.transferClass().fromObjects(objects)
        t.setMetadata("description", description)
        t.save(
            tempPath,
            fileType=fileType,
            time=[startFrame, endFrame],
            bakeConnected=bakeConnected,
        )

        if iconPath:
            contents.append(iconPath)

        contents.extend(t.paths())

        studiolibrary.LibraryItem.save(self, path=path, contents=contents)
Exemplo n.º 7
0
    def save(self, objects, leftSide, rightSide, path=None, iconPath=None):
        """
        :type path: str
        :type objects: list[str]
        :type iconPath: str
        :rtype: None

        """
        logger.info("Saving: %s" % self.transferPath())

        tempDir = mutils.TempDir("Transfer", makedirs=True)
        tempPath = os.path.join(tempDir.path(), self.transferBasename())

        t = self.transferClass().fromObjects(objects,
                                             leftSide=leftSide,
                                             rightSide=rightSide)
        t.save(tempPath)

        studiolibrary.Record.save(self,
                                  path=path,
                                  contents=[tempPath, iconPath])
Exemplo n.º 8
0
def saveAnim(
    path,
    objects=None,
    time=None,
    sampleBy=1,
    metadata=None,
    bakeConnected=False
):
    """
    Save the anim data for the given objects.

    Example:
        import mutils
        mutils.saveAnim(
            path="c:/example.anim", 
            time=(1, 20),
            metadata={'description': 'Example anim'}
            )
            
    :type path: str
    :type objects: None or list[str]
    :type time: None or int
    :type sampleBy: int
    :type metadata: dict or None
    :type bakeConnected: bool
    
    :rtype: mutils.Animation
    """
    step = 1
    objects = objects or maya.cmds.ls(selection=True) or []

    if os.path.exists(path):
        raise Exception("Cannot override an existing path. " + path)

    if not objects:
        raise Exception(
            "No objects selected. Please select at least one object."
        )

    if not time:
        time = mutils.selectedObjectsFrameRange(objects)

    start, end = time

    if start >= end:
        msg = "The start frame cannot be greater than or equal to the end frame!"
        raise AnimationTransferError(msg)

    tmpPath = mutils.TempDir("anim", clean=True).path()

    os.makedirs(tmpPath + '/sequence')

    iconPath = tmpPath + "/thumbnail.jpg"
    sequencePath = tmpPath + "/sequence/thumbnail.jpg"

    window = mutils.gui.thumbnailCapture(
        path=sequencePath,
        startFrame=start,
        endFrame=end,
        step=step,
        modifier=False,
    )

    if iconPath:
        shutil.copyfile(window.capturedPath(), iconPath)

    anim = mutils.Animation.fromObjects(objects)

    if metadata:
        anim.updateMetadata(metadata)

    anim.save(tmpPath, time=time, bakeConnected=bakeConnected, sampleBy=sampleBy)

    shutil.copytree(tmpPath, path)

    return mutils.Animation.fromPath(path)