예제 #1
0
    def setTextures(self, fileNames):
        """ 
        Specifies the textures to be used in the UV viewer.
        File ranges (eg. diffuse.(1001-1020)#.tx) will be expanded
        As will non-limited file ranges (eg. diffuse.#.tx) 
        """
        del self.__fileNames[:]

        # insert individual files into self.__fileNames
        for file in fileNames:
            if file == None:
                continue

            fsPlugin = AssetAPI.GetDefaultFileSequencePlugin()
            if fsPlugin.isFileSequence(file):
                fs = fsPlugin.getFileSequence(file)
                frames = fs.getFrameList()
                if len(frames) > 0:
                    # Limited frame range
                    for frame in frames:
                        path = fs.getResolvedPath(frame)
                        if os.path.exists(path):
                            self.__fileNames.append(path)
                else:
                    # Unlimited frame range
                    paths = self.__getPathsFromUnlimitedSequence(file)
                    self.__fileNames.extend(paths)

            else:
                self.__fileNames.append(file)
예제 #2
0
    def resolvePath(self, assetId, frame):  # TODO -- This may need some work to work properly. How do Shotgun and Katana work with file sequences?
        """
        Resolves the given asset ID and if it comes as a file
        sequence then we will resolve that file sequence to the specified
        frame using the currently selected FileSequence plug-in
        """
        resolvedAsset = self.resolveAsset(assetId)
        if not resolvedAsset:
            return

        # Get the fileSequence plug-in and if the resolvedAsset is a file sequence
        # path, then use frame to resolve it
        fileSequencePlugin = AssetAPI.GetDefaultFileSequencePlugin()
        if fileSequencePlugin:
            if fileSequencePlugin.isFileSequence(resolvedAsset):
                # Get the FileSequence object and resolve the sequence with frame
                fileSequence = fileSequencePlugin.getFileSequence(resolvedAsset)
                resolvedAsset = fileSequence.getResolvedPath(frame)

        return resolvedAsset
예제 #3
0
 def resolvePath(self, assetId, frame):
     """
     Resolves the asset ID and inserts the specified frame using the
     currently selected FileSequence plug-in.
     """        
     if self.isAssetId(assetId):
         # Resolve the asset
         resolvedAsset = self.resolveAsset(assetId)
     else:
         resolvedAsset = assetId
     
     # Get the fileSequence plug-in and if the resolvedAsset is a file 
     # sequence path, then use frame to resolve it
     fileSequencePlugin = AssetAPI.GetDefaultFileSequencePlugin()
     if fileSequencePlugin:
         if fileSequencePlugin.isFileSequence(resolvedAsset):
             # Get the FileSequence object and resolve the sequence with 
             # the frame passed to this function.
             fileSequence = fileSequencePlugin.getFileSequence(resolvedAsset)
             resolvedAsset = fileSequence.getResolvedPath(frame)
     
     return resolvedAsset
예제 #4
0
    def createAssetAndPath(self, txn, assetType, fields, args,
                           createDirectory):
        """
        Builds an asset ID using the fields provided and prepares to publish
        an asset of a given asset type. This is the first step of publishing
        and Katana will use the resolved value of the asset ID returned by this
        as the location to write out the asset.
        
        Returns "None" for unsupported asset types or if this step fails (for
        example when the directory structure could not be written to).  
        """
        # Create the asset filename and attributes dict.
        assetFile = None

        # The postCreateAsset() call will set "published" to True. We will save
        # "published" as an attribute so that we can save it in the asset.info
        # file in the same way as the other attributes
        attrs = {"published": "False"}
        attrs["comment"] = args.get("comment", "")

        # In some cases Katana will provide "versionUp" as a boolean argument.
        # If it is "True" then we will increase whatever version is provided
        # by the assetId. In a real asset management system this feature could
        # be implemented by increasing the latest available version for the
        # provided asset.
        self._incrementVersion(fields, args)

        # Get the string that contains the fields joined by "/"
        fieldsStr = self._getFieldsStrFromFields(fields)
        if not fieldsStr:
            log.warning("createAssetAndPath(): no fieldsStr! Aborting")
            return None

        # This section will look into the different Asset Types.
        # For most asset types  an argument called "file" can optionally be
        # specified with an explicit file name that will be set in the asset's
        # directory or an absolute path to a file outside the database's
        # directories
        if assetType == AssetAPI.kAssetTypeKatanaScene:
            assetFile = args.get("file", "scene.katana")

        elif assetType == AssetAPI.kAssetTypeImage:
            ext = args.get("ext", "exr")
            colorspace = args.get("colorspace", "lnf")
            res = args.get("res", "misc")

            attrs["ext"] = ext
            attrs["colorspace"] = colorspace
            attrs["res"] = res

            # Images published for the catalog are handled differently.
            if args.get("context") == AssetAPI.kAssetContextCatalog:
                # The filename of the exported sequences is passed to
                # postCreateAsset and handled there.
                assetFile = ""

            else:
                # Now we are going to build the asset filename
                assetFile = None

                # Check if we can get how to represent a file sequence path
                # using the currently selected FileSequence plug-in
                fileSequencePlugin = AssetAPI.GetDefaultFileSequencePlugin()
                if fileSequencePlugin:
                    # Get the prefix and suffix of the sequence string
                    assetFileName = str("image_%s." % colorspace)
                    assetExtension = str(".%s" % ext)

                    assetFile = fileSequencePlugin.buildFileSequenceString(
                        assetFileName, assetExtension, 4)
                else:
                    log.warning("createAssetAndPath(): No FileSequencePlugin "
                                "found! Aborting.")
                    return None

        elif assetType == AssetAPI.kAssetTypeLookFile:
            assetFile = args.get("file", "lookfile.klf")

        elif assetType == AssetAPI.kAssetTypeFCurveFile:
            assetFile = "fcurve.xml"

        elif assetType == AssetAPI.kAssetTypeGafferRig:
            assetFile = "rig.gprig"

        elif assetType == AssetAPI.kAssetTypeGafferThreeRig:
            assetFile = "rig.rig"

        elif assetType == AssetAPI.kAssetTypeScenegraphXml:
            assetFile = args.get("file", "scene.xml")

        elif assetType == AssetAPI.kAssetTypeScenegraphBookmarks:
            assetFile = args.get("file", "scenegraph_bookmarks.xml")

        elif assetType == AssetAPI.kAssetTypeLookFileMgrSettings:
            assetFile = args.get("file", "lfmsettings.lfmexport")

        elif assetType == AssetAPI.kAssetTypeMacro:
            assetFile = args.get("file", "node.macro")

        else:
            log.error("createAssetAndPath(): Invalid asset type: \"%s\"" %
                      assetType)
            return None

        # We don't pay attention to 'createDirectory' because we always have to
        # create the dir to keep the info file at least.
        dir = os.path.join(self._getBaseDir(), fieldsStr)
        if not os.path.exists(dir):
            os.makedirs(dir)

        # Create the info file that will keep the filename, asset type and the
        # extra attributes of the asset.
        self._writeAssetInfoFile(dir, assetFile, assetType, attrs)

        resultAssetId = self.buildAssetId(fields)

        return resultAssetId
예제 #5
0
                            fieldsStr += "/v"

                        fieldsStr += fields.get(AssetAPI.kAssetFieldVersion)

        return fieldsStr

    def _replaceTagsWithNumbers(self, assetId):
        """
        Convert the tags in the asset id in to version numbers.
        """
        version = self.resolveAssetVersion(assetId)
        fields = self.getAssetFields(assetId, False)
        fields[AssetAPI.kAssetFieldVersion] = version
        assetId = self.buildAssetId(fields)
        return assetId

    def _incrementVersion(self, fields, args):
        """
        Increments the version by 1 in a given fields dictionary.
        """
        if "versionUp" in args and args["versionUp"] == "True":
            version = int(fields[AssetAPI.kAssetFieldVersion])
            fields[AssetAPI.kAssetFieldVersion] = str(version + 1)


#///////////////////////////////////////////////////////////////////////////////

# Register the plug-in calling it "PyMockAsset".
# This name will be shown in Katana's Project Settings tab.
AssetAPI.RegisterAssetPlugin("PyMockAsset", MockAsset())
예제 #6
0
            self.logger.warn(
                "getAssetFields: Couldn't find fields in asset ID: %s",
                assetId,
            )
        return fieldDict

    def __getAssetPublishType(self, assetId):
        '''
        Returns the publish "type" of the asset. This is used to work out the Shotgun template to use.
        '''
        fullDict = eval(str(assetId)) # TODO: Not cool, but works in this case. Switch to json?
        templateType = fullDict.get("template") or None
        if not templateType:
            self.logger.warn(
                "getAssetFields: Couldn't find template type in asset ID: %s",
                assetId,
            )
        return templateType

    def createTransaction(self):
        """
        Creates a transaction object
        """
        # In this example plug-in we do not support transactions
        return None


# Register the "Shotgun" plug-in - this is the name that will be
# shown in Katana's Project Settings tab
AssetAPI.RegisterAssetPlugin("Shotgun", ShotgunAssetPlugin())
예제 #7
0
        if self.__range:
            return self.__range[0]
        else:
            return 0

    def getLastFrame(self):
        if self.__range:
            return self.__range[1]
        else:
            return 0

    def getNearestFrames(self, frame):
        left = None
        right = None
        if self.__range:
            if frame > self.__range[0]:
                left = min(frame - 1, self.__range[1])
            if frame < self.__range[1]:
                right = max(frame + 1, self.__range[0])
        return (left, right)

    def getFrameList(self):
        if self.__range:
            return range(self.__range[0], self.__range[1] + 1)
        else:
            return []


# Register the plugin
AssetAPI.RegisterFileSequencePlugin("PyMockFileSeq", MockFileSequencePlugin())
예제 #8
0
        if self.__range:
            return self.__range[0]
        else:
            return 0

    def getLastFrame(self):
        if self.__range:
            return self.__range[1]
        else:
            return 0

    def getNearestFrames(self, frame):
        left = None
        right = None
        if self.__range:
            if frame > self.__range[0]:
                left = min(frame - 1, self.__range[1])
            if frame < self.__range[1]:
                right = max(frame + 1, self.__range[0])
        return (left, right)

    def getFrameList(self):
        if self.__range:
            return range(self.__range[0], self.__range[1] + 1)
        else:
            return []


# Register the plugin
AssetAPI.RegisterFileSequencePlugin("FileSeq", FileSequencePlugin())