예제 #1
0
def createAndImportWeightsFromShapes(filePath, shapes):
    """Loads the skin data from the filePath and loads it on the shapeNodes.

    If any of the shapes have existing skinClusters then the weights will be replaced.
    Otherwise a skin cluster will be created.

    :param filePath: The json file to load, must be in the same format as the return data of :func:`serialzieSkinWeightsFromShapes`
    :type filePath: str
    :param shapes: list of om2.MObjects representing the geometry shape nodes to load the data onto
    :type shapes: [type]
    """

    # read in the json
    skinInfo = filesystem.loadJson(filePath)
    if not skinInfo:
        logger.error("Failed to load skin file: {}".format(filePath))
        raise RuntimeError("Failed to load skin file: {}".format(filePath))

    # ok now grab the mapping between the dataFile and the shape nodes this is done by name
    # :todo: custom mapping
    for shape in shapes:
        path = om2.MDagPath.getAPathTo(shape)
        name = generic.stripNamespaceFromName(path.fullPathName())
        mappedInfo = skinInfo.get(name)
        if mappedInfo is None:
            print "Skipping: {} since it doesn't exist"
            continue
        applyWeightsFromData(mappedInfo, path)
예제 #2
0
    def test_shapeSaveToLibrary(self):
        circle = cmds.circle(ch=False)[0]
        self.data, self.shapePath = shapelib.saveToLib(nodes.asMObject(circle),
                                                       "circleTest")
        data = filesystem.loadJson(self.shapePath)

        for shapeName, shapeData in iter(data.items()):
            self.assertTrue("cvs" in shapeData)
            self.assertTrue("degree" in shapeData)
            self.assertTrue("form" in shapeData)
            self.assertTrue("knots" in shapeData)
            self.assertTrue("overrideColorRGB" in shapeData)
            self.assertTrue("overrideEnabled" in shapeData)
            self.assertTrue(shapeName in cmds.listRelatives(circle, s=True)[0])
            self.assertEquals(len(shapeData["cvs"]),
                              len(self.data[shapeName]["cvs"]))
            self.assertEquals(len(shapeData["knots"]),
                              len(self.data[shapeName]["knots"]))
            self.assertEquals(shapeData["degree"],
                              self.data[shapeName]["degree"])
            self.assertEquals(shapeData["form"], self.data[shapeName]["form"])
            self.assertEquals(tuple(shapeData["knots"]),
                              self.data[shapeName]["knots"])
            self.assertEquals(shapeData["overrideColorRGB"],
                              self.data[shapeName]["overrideColorRGB"])
            self.assertEquals(shapeData["overrideEnabled"],
                              self.data[shapeName]["overrideEnabled"])
예제 #3
0
 def open(self, root, relativePath, extension=None):
     relativePath = path.Path(relativePath)
     if not relativePath.getExtension(True):
         relativePath = relativePath.setExtension(extension or self.extension)
     fullPath = root / relativePath
     if not os.path.exists(fullPath):
         raise InvalidSettingsPath(fullPath)
     data = filesystem.loadJson(fullPath)
     return SettingObject(root, relativePath, **data)
예제 #4
0
def highlighterFromJson(filePath, document):
    """Generate's a python syntaxHighlighter from a json file containing the syntax and color information

    :param filePath: Absolute path to the json file
    :type filePath: str
    :param document: The Document instance to apply to
    :type document: :class:`QtGui.QTextDocument`
    :rtype: :class:`PythonHighlighter`
    """
    if not filePath:
        return
    syntaxData = filesystem.loadJson(filePath)
    return PythonHighlighter(document, syntaxData)
예제 #5
0
 def load(self, configPaths):
     data = {}
     self.configPaths = configPaths
     for config in configPaths:
         if not os.path.exists(config) or not config.endswith(".json"):
             continue
         userData = filesystem.loadJson(config)
         general.merge(data, userData)
         rules = userData.get("rules")
         tokens = userData.get("tokens")
         if rules:
             data["rules"].update(rules)
         if tokens:
             data["tokens"].update(tokens)
     self.config = data
예제 #6
0
    def registerLayoutByEnv(self, env):
        """Recursively Registers all layout files with the extension .mmlayout and loads the json data with a layout
        instance then adds to the layouts cache

        :param env: the environment variable pointing to the parent directory
        :type env: str
        """
        paths = os.environ.get(env, "").split(os.pathsep)
        for p in paths:
            if os.path.isdir(p):
                for root, dirs, files in os.walk(p):
                    for f in files:
                        layoutFile = os.path.join(root, f)
                        try:
                            if f.endswith(".mmlayout"):
                                data = filesystem.loadJson(layoutFile)
                                self.layouts[data["id"]] = Layout(**data)
                        # If the Json data is invalid(formatted) it will raise a valueError without a file location
                        # so raise something useful
                        except ValueError:
                            raise InvalidJsonFileFormat(
                                "Layout file: {} is invalid possibly due to the "
                                "formatting.".format(layoutFile),
                                exc_info=True)
            elif p.endswith("mmlayout"):
                try:
                    if p.endswith(".mmlayout"):
                        data = filesystem.loadJson(p)
                        self.layouts[data["id"]] = Layout(**data)
                # If the Json data is invalid(formatted) it will raise a valueError without a file location
                # so raise something useful
                except ValueError:
                    raise InvalidJsonFileFormat(
                        "Layout file: {} is invalid possibly due to the "
                        "formatting.".format(p),
                        exc_info=True)
예제 #7
0
def loadFromLib(shapeName, parent=None):
    """Loads the data for the given shape Name

    :param shapeName: The shape name from the library, excluding the extension
    :type shapeName: str
    :param parent: if specified then this function will also create the shapes under the parent
    :type parent: MObject
    :return: A 2 tuple the first element is the MObject of the parent and the second is a list /
    of mobjects represents the shapes created
    :rtype: tuple(MObject, list(MObject))
    :raises: ValueError
    """
    lib = os.path.abspath(
        os.path.join(os.path.dirname(os.path.realpath(__file__))))
    for f in iter(os.listdir(lib)):
        if not f.endswith("shape"):
            continue
        name = os.path.splitext(f)[0]
        if name == shapeName:
            data = filesystem.loadJson(os.path.join(os.path.normpath(lib), f))
            if data:
                return data
    raise ValueError(
        "The shape name '{}' doesn't exist in the library".format(shapeName))