def load(self, context, name, namespace, data): from avalon.maya.pipeline import containerise from pype.maya.lib import namespaced asset_name = context['asset']["name"] namespace = namespace or lib.unique_namespace( asset_name + "_", prefix="_" if asset_name[0].isdigit() else "", suffix="_", ) # Ensure V-Ray for Maya is loaded. cmds.loadPlugin("vrayformaya", quiet=True) with lib.maintained_selection(): cmds.namespace(addNamespace=namespace) with namespaced(namespace, new=False): nodes = self.create_vray_proxy(name, filename=self.fname) self[:] = nodes if not nodes: return return containerise(name=name, namespace=namespace, nodes=nodes, context=context, loader=self.__class__.__name__)
def process_reference(self, context, name, namespace, data): asset_name = context['asset']["name"] print("---", namespace) namespace = namespace or lib.unique_namespace( asset_name + "_", prefix="_" if asset_name[0].isdigit() else "", suffix="_", ) print(">>>", namespace) # Pre-run check if not cmds.objExists("vraySettings"): cmds.createNode("VRaySettingsNode", name="vraySettings") # Add namespace cmds.namespace(set=":") cmds.namespace(add=namespace) cmds.namespace(set=namespace) with lib.maintained_selection(): nodes = self.create_vray_proxy(name) self[:] = nodes # Make sure to restore the default namespace, or anything imported or # refereced after this gets added to this namespace cmds.namespace(set=":") return nodes
def load(self, context, name, namespace, data): from avalon.maya.pipeline import containerise from pype.maya.lib import namespaced try: family = context["representation"]["context"]["family"] except ValueError: family = "vrayproxy" asset_name = context['asset']["name"] namespace = namespace or lib.unique_namespace( asset_name + "_", prefix="_" if asset_name[0].isdigit() else "", suffix="_", ) # Ensure V-Ray for Maya is loaded. cmds.loadPlugin("vrayformaya", quiet=True) with lib.maintained_selection(): cmds.namespace(addNamespace=namespace) with namespaced(namespace, new=False): nodes = self.create_vray_proxy(name, filename=self.fname) self[:] = nodes if not nodes: return presets = config.get_presets(project=os.environ['AVALON_PROJECT']) colors = presets['plugins']['maya']['load']['colors'] c = colors.get(family) if c is not None: cmds.setAttr("{0}_{1}.useOutlinerColor".format(name, "GRP"), 1) cmds.setAttr("{0}_{1}.outlinerColor".format(name, "GRP"), c[0], c[1], c[2]) return containerise( name=name, namespace=namespace, nodes=nodes, context=context, loader=self.__class__.__name__)
def load(Loader, representation, name=None, namespace=None, data=None): """Load asset via database Deprecated; this functionality is replaced by `api.load()` Arguments: Loader (api.Loader): The loader to process in host Maya. representation (dict, io.ObjectId or str): Address to representation name (str, optional): Use pre-defined name namespace (str, optional): Use pre-defined namespace data (dict, optional): Additional settings dictionary """ from avalon.vendor import six from avalon import io from avalon.maya import lib from avalon.maya.pipeline import containerise assert representation is not None, "This is a bug" if isinstance(representation, (six.string_types, io.ObjectId)): representation = io.find_one({"_id": io.ObjectId(str(representation))}) version, subset, asset, project = io.parenthood(representation) assert all([representation, version, subset, asset, project]), ( "This is a bug" ) context = { "project": project, "asset": asset, "subset": subset, "version": version, "representation": representation, } # Ensure data is a dictionary when no explicit data provided if data is None: data = dict() assert isinstance(data, dict), "Data must be a dictionary" name = name or subset["name"] namespace = namespace or lib.unique_namespace( asset["name"] + "_", prefix="_" if asset["name"][0].isdigit() else "", suffix="_", ) # TODO(roy): add compatibility check, see `tools.cbloader.lib` Loader.log.info( "Running '%s' on '%s'" % (Loader.__name__, asset["name"]) ) try: loader = Loader(context) with lib.maintained_selection(): loader.process(name, namespace, context, data) except OSError as e: log.info("WARNING: %s" % e) return list() # Only containerize if any nodes were loaded by the Loader nodes = loader[:] if not nodes: return return containerise( name=name, namespace=namespace, nodes=loader[:], context=context, loader=Loader.__name__)