def get_renderer_variables(renderlayer=None): """Retrieve the extension which has been set in the VRay settings Will return None if the current renderer is not VRay For Maya 2016.5 and up the renderSetup creates renderSetupLayer node which start with `rs`. Use the actual node name, do NOT use the `nice name` Args: renderlayer (str): the node name of the renderlayer. Returns: dict """ renderer = lib.get_renderer(renderlayer or lib.get_current_renderlayer()) render_attrs = lib.RENDER_ATTRS.get(renderer, lib.RENDER_ATTRS["default"]) padding = cmds.getAttr("{}.{}".format(render_attrs["node"], render_attrs["padding"])) filename_0 = cmds.renderSettings(fullPath=True, firstImageName=True)[0] if renderer == "vray": # Maya's renderSettings function does not return V-Ray file extension # so we get the extension from vraySettings extension = cmds.getAttr("vraySettings.imageFormatStr") # When V-Ray image format has not been switched once from default .png # the getAttr command above returns None. As such we explicitly set # it to `.png` if extension is None: extension = "png" filename_prefix = "<Scene>/<Scene>_<Layer>/<Layer>" else: # Get the extension, getAttr defaultRenderGlobals.imageFormat # returns an index number. filename_base = os.path.basename(filename_0) extension = os.path.splitext(filename_base)[-1].strip(".") filename_prefix = cmds.getAttr("defaultRenderGlobals.imageFilePrefix") return { "ext": extension, "filename_prefix": filename_prefix, "padding": padding, "filename_0": filename_0 }
def get_renderer_variables(renderlayer=None): """Retrieve the extension which has been set in the VRay settings. Will return None if the current renderer is not VRay For Maya 2016.5 and up the renderSetup creates renderSetupLayer node which start with `rs`. Use the actual node name, do NOT use the `nice name` Args: renderlayer (str): the node name of the renderlayer. Returns: dict """ renderer = lib.get_renderer(renderlayer or lib.get_current_renderlayer()) render_attrs = lib.RENDER_ATTRS.get(renderer, lib.RENDER_ATTRS["default"]) padding = cmds.getAttr("{}.{}".format(render_attrs["node"], render_attrs["padding"])) filename_0 = cmds.renderSettings(fullPath=True, gin="#" * int(padding), lut=True, layer=renderlayer or lib.get_current_renderlayer())[0] filename_0 = filename_0.replace('_<RenderPass>', '_beauty') prefix_attr = "defaultRenderGlobals.imageFilePrefix" if renderer == "vray": # Maya's renderSettings function does not return V-Ray file extension # so we get the extension from vraySettings extension = cmds.getAttr("vraySettings.imageFormatStr") # When V-Ray image format has not been switched once from default .png # the getAttr command above returns None. As such we explicitly set # it to `.png` if extension is None: extension = "png" if extension == "exr (multichannel)" or extension == "exr (deep)": extension = "exr" prefix_attr = "vraySettings.fileNamePrefix" elif renderer == "renderman": prefix_attr = "rmanGlobals.imageFileFormat" elif renderer == "redshift": # mapping redshift extension dropdown values to strings ext_mapping = ["iff", "exr", "tif", "png", "tga", "jpg"] extension = ext_mapping[cmds.getAttr("redshiftOptions.imageFormat")] else: # Get the extension, getAttr defaultRenderGlobals.imageFormat # returns an index number. filename_base = os.path.basename(filename_0) extension = os.path.splitext(filename_base)[-1].strip(".") filename_prefix = cmds.getAttr(prefix_attr) return { "ext": extension, "filename_prefix": filename_prefix, "padding": padding, "filename_0": filename_0 }