Esempio n. 1
0
 def get_defaultrenderglobals(self, layer):
     scene_info_common_dict = collections.OrderedDict()
     default_globals = pm.PyNode("defaultRenderGlobals")
     scene_info_common_dict['renderer'] = str(self.GetCurrentRenderer())
     scene_info_common_dict['image_file_prefix'] = str(
         self.GetMayaOutputPrefix(layer))
     scene_info_common_dict['start'] = str(
         int(cmds.getAttr("defaultRenderGlobals.startFrame")))
     scene_info_common_dict['end'] = str(
         int(cmds.getAttr("defaultRenderGlobals.endFrame")))
     scene_info_common_dict['by_frame'] = str(
         int(cmds.getAttr("defaultRenderGlobals.byFrame")))
     scene_info_common_dict['all_camera'] = cmds.ls(type="camera")
     scene_info_common_dict['render_camera'] = [
         i.name() for i in pm.ls(type="camera") if i.renderable.get()
     ]
     scene_info_common_dict["renumber_frames"] = str(
         default_globals.modifyExtension.get())
     scene_info_common_dict['width'] = str(
         int(cmds.getAttr("defaultResolution.width")))
     scene_info_common_dict['height'] = str(
         int(cmds.getAttr("defaultResolution.height")))
     scene_info_common_dict["image_format"] = str(self.GetOutputExt())
     scene_info_common_dict["animation"] = str(
         default_globals.animation.get())
     scene_info_common_dict["file_name"] = str(
         pm.renderSettings(fin=1, cam='', lyr=layer))
     # self["renderSettings"]['all_layer'] = ",".join([i.name() for i in pm.PyNode("renderLayerManager.renderLayerId").outputs() if i.type() == "renderLayer"])
     # self["renderSettings"]['render_layer'] = ",".join([i.name() for i in pm.PyNode("renderLayerManager.renderLayerId").outputs() if i.type() == "renderLayer" if i.renderable.get()])
     self.getMel()
     return scene_info_common_dict
Esempio n. 2
0
	def dpaf_outputsFix(self, layer):
		"""fix image output path if renderer is vray

		:param layer: maya renderLayer name
		:return outputs_Fixed: correct image output path
		"""
		outputs_Fixed = ''
		currentRenderer = pm.PyNode('defaultRenderGlobals').getAttr('currentRenderer')

		# get current maya image format setting
		tmp_OutFormatControl = pm.getAttr('defaultRenderGlobals.outFormatControl') if currentRenderer == 'vray' else ''
		imgPrefix_vray = pm.getAttr('vraySettings.fileNamePrefix') if currentRenderer == 'vray' else ''
		imgPrefix_maya = pm.getAttr('defaultRenderGlobals.imageFilePrefix') if currentRenderer == 'vray' else ''
		imageFormatStr = ('.' + ('png' if not pm.getAttr('vraySettings.imageFormatStr') else pm.getAttr('vraySettings.imageFormatStr'))) if currentRenderer == 'vray' else ''
		
		if currentRenderer == 'vray':
			# change current setting for fixing vray output path
			pm.setAttr('defaultRenderGlobals.outFormatControl', 1)
			pm.setAttr('defaultRenderGlobals.imageFilePrefix', imgPrefix_vray if imgPrefix_vray else '', type= 'string') if imgPrefix_vray else None

		# write output path
		outputs_Fixed = pm.renderSettings(layer= layer, fullPath= 1, firstImageName= 1, lastImageName= 1)
		outputs_Fixed[0] = os.path.normpath(outputs_Fixed[0]) + imageFormatStr
		outputs_Fixed[1] = os.path.normpath(outputs_Fixed[1]) + imageFormatStr
		outputs_Fixed = ','.join(outputs_Fixed)

		if currentRenderer == 'vray':
			# restore previous setting for good
			pm.setAttr('defaultRenderGlobals.imageFilePrefix', imgPrefix_maya if imgPrefix_maya else '', type= 'string') if imgPrefix_vray else None
			pm.setAttr('defaultRenderGlobals.outFormatControl', tmp_OutFormatControl)

		return outputs_Fixed
Esempio n. 3
0
def getGenericImageName(layer=None,
                        camera=None,
                        resolveAOVs=True,
                        framePadder='?'):
    gins = []

    path = None

    # if currentRenderer() == 'redshift':
    #     path = pc.PyNode('redshiftOptions').imageFilePrefix.get()

    if path is None:
        if layer is None and camera is None:
            fin = pc.renderSettings(fin=True, lut=True)
        elif layer is None:
            fin = pc.renderSettings(fin=True, lut=True, camera=camera)
        elif camera is None:
            fin = pc.renderSettings(fin=True, lut=True, layer=layer)
        else:
            fin = pc.renderSettings(fin=True,
                                    lut=True,
                                    layer=layer,
                                    camera=camera)
        path = fin[0]

    if resolveAOVs:
        if not camera:
            cams = getCameras(True, False)
            if cams:
                camera = cams[0]
        gins = resolveAOVsInPath(
            path, layer if layer else pc.editRenderLayerGlobals(q=1, crl=1),
            camera if camera else '', framePadder)

    if not gins:
        gins = [path]
    if isAnimationOn():
        gins = [removeLastNumber(gin, framePadder)[0] for gin in gins]

    return gins
Esempio n. 4
0
    def getParm(self,flag,ropver):
        my_window.resize(360,680)
        
        if ropver == 'arnold':
            fStat = self.openFile('arnold')
        elif ropver == 'Redshift_ROP':
            fStat = self.openFile('Redshift_ROP')
        
        if fStat != "NEW_FILE":
            splitArgs = fStat.split("?")
            self.mw.lbl_r_rop.setText("ROP: " + splitArgs[1])
            self.mw.lbl_r_loc.setText("Location: " + splitArgs[2])
            self.mw.lbl_r_name.setText("Name: " + splitArgs[3])
            self.mw.lbl_r_frange.setText("Frame Range: " + splitArgs[4])

            if ropver == 'arnold':
                self.mw.lbl_w_rop.setText("ROP: "+"arnold")
                wRop = 'arnold' 
            else:
                self.mw.lbl_w_rop.setText("ROP: "+ "redshift")
                wRop = 'redshift'
            fi = pm.renderSettings(fullPath=True, firstImageName=True, imageGenericName=True)
            locA = os.path.dirname(fi[0])
            wName = fi[1]
            #%4n.%e
            reName = re.sub("%.n","$F",wName)
            reName = re.sub("%e","*",reName)
            locB = os.path.join(locA + "/" +reName)
            self.mw.lbl_w_loc.setText("Location: "+ locB)
            self.mw.lbl_w_name.setText("Name: " + reName)
            self.mw.bttn_lock.setEnabled(True)
            global wVars
            wVars = "Maya?" + wRop + "?" + locB + "?" + reName + "?" #Add missing frame range
            
            

        else:
            self.mw.lbl_fileType.setText("File Did not exist so it was created.")
            self.resetAll()
Esempio n. 5
0
 def get_default_render_globals(self, layer):
     scene_info_common_dict = collections.OrderedDict()
     default_globals = pm.PyNode("defaultRenderGlobals")
     scene_info_common_dict['renderer'] = str(self.GetCurrentRenderer())
     scene_info_common_dict['image_file_prefix'] = str(self.GetMayaOutputPrefix(layer))
     if self.is_absolute_path(scene_info_common_dict['image_file_prefix']):
         self.writing_error(25002, "renderlayer: %s --- %s" % (layer, scene_info_common_dict['image_file_prefix']))
     scene_info_common_dict['start'] = str(int(cmds.getAttr("defaultRenderGlobals.startFrame")))
     scene_info_common_dict['end'] = str(int(cmds.getAttr("defaultRenderGlobals.endFrame")))
     scene_info_common_dict['by_frame'] = str(int(cmds.getAttr("defaultRenderGlobals.byFrame")))
     if layer == "defaultRenderLayer":
         pass
     else:
         if pm.mel.eval('editRenderLayerAdjustment -remove "defaultRenderGlobals.endFrame";') or pm.mel.eval(
                 'editRenderLayerAdjustment -remove "defaultRenderGlobals.startFrame";') or pm.mel.eval(
                 'editRenderLayerAdjustment -remove "defaultRenderGlobals.byFrame";'):
             self.writing_error(25015,
                                "render layer: %s \'s startFrame/endFrame/byFrame has Layer Override attribute ,advice Layered submitting" % (
                                layer))
     scene_info_common_dict['all_camera'] = self.GetRenderableCameras(False)
     scene_info_common_dict['render_camera'] = [i.name() for i in pm.ls(type="camera") if i.renderable.get()]
     if not scene_info_common_dict['render_camera']:
         self.writing_error(25011, "render layer: %s  there is  no camera  " % (layer))
     scene_info_common_dict["renumber_frames"] = str(default_globals.modifyExtension.get())
     if default_globals.modifyExtension.get():
         self.writing_error(25001)
     scene_info_common_dict['width'] = str(int(cmds.getAttr("defaultResolution.width")))
     scene_info_common_dict['height'] = str(int(cmds.getAttr("defaultResolution.height")))
     scene_info_common_dict["image_format"] = str(self.GetOutputExt())
     scene_info_common_dict["animation"] = str(default_globals.animation.get())
     scene_info_common_dict["file_name"] = str(pm.renderSettings(fin=1, cam='', lyr=layer))
     if len(str(int(default_globals.endFrame.get()))) > default_globals.extensionPadding.get():
         self.writing_error(25010)
     # self["renderSettings"]['all_layer'] = ",".join([i.name() for i in pm.PyNode("renderLayerManager.renderLayerId").outputs() if i.type() == "renderLayer"])
     # self["renderSettings"]['render_layer'] = ",".join([i.name() for i in pm.PyNode("renderLayerManager.renderLayerId").outputs() if i.type() == "renderLayer" if i.renderable.get()])
     # self.scene_info_dict[layer]["common"] = scene_info_common_dict
     return scene_info_common_dict
Esempio n. 6
0
def setupCamera(fov, punch, view, frames):
    # set hdri image
    pm.mel.eval('redshiftCreateDomeLight;')
    pm.mel.eval('MASHnewNodeCallback( "rsDomeLightShape1");')
    pm.mel.eval(
        'setAttr -type "string" rsDomeLightShape1.tex0 "path/name.exr";')
    pm.mel.eval('currentTime 1;')
    pm.mel.eval('setAttr "rsDomeLight1.rotateY" 0;')
    pm.mel.eval('setKeyframe { "rsDomeLight1.r" };')
    pm.mel.eval('currentTime {0};'.format(frames))
    pm.mel.eval('setAttr "rsDomeLight1.rotateY" 360;')
    pm.mel.eval('setKeyframe { "rsDomeLight1.r" };')

    # ui input
    isTopView = view
    # get bbox
    geo = pm.ls(type='dagContainer')
    geo = geo[0]
    centerPivot(geo)
    print "imported  ", geo
    #    assignShaderToObj(geo)
    # get bbox
    bbox = geo.boundingBox()
    # Create a camera and get the shape name.
    cameraName = pm.camera()
    cameraShape = cameraName[1]
    print "camera{0} looking at{1}\n".format(cameraShape, geo)
    # create locator and parent to geo
    locator = pm.spaceLocator()
    # set rotation
    locator.rotateY.setKey(t=0, v=0)
    locator.rotateY.setKey(t=frames, v=360)

    # set usr fov , get vertical fov
    cameraShape.setHorizontalFieldOfView(fov)
    vfov = cameraShape.getVerticalFieldOfView()
    print "vfov:", vfov

    cameraShape.displayCameraFrustum.set(1)
    # bbox width,height horizontal
    # y = abs(bbox[0][2])
    # x = abs(bbox[0][0])

    y_v = abs(bbox[1][1])  # vertical height
    x_v = abs(bbox[0][0])  # vertical width
    z_v = abs(bbox[1][2])  # vertical depth
    print "vertical size:", y_v, x_v, z_v
    #  math stuff
    # calc horizontal radius
    #   h_r = calcDiag(y, x)
    # calc dist
    #    h_dist = calcDist(h_r, fov)

    v_r = calcDiag(y_v, x_v)
    v_dist = calcDist(v_r, vfov)

    print "vDiag:{0},vDist:{1}".format(v_r, v_dist)

    #  if top view enabled, rotate cam then dolly in viewing dir
    if isTopView:
        print "top", isTopView
        rot_mat = cameraName[0].getRotation()
        rot_mat[0] = -90
        cameraName[0].setRotation(rot_mat)

    ##  translate camera
    #  @note temporarily using dolly cuz its faster
    cameraShape.dolly(v_dist)

    #  check if camera is inside bbox
    camPos = cameraName[0].getTranslation()
    print "campos:", camPos, z_v

    # if camera is inside bbox even after dolly, reposition
    if z_v >= camPos[2]:
        print "cam inside bbox"
        # calculate new distance based on bbox Z
        newDiag = calcDiag(z_v, x_v)
        newDist2 = calcDist(newDiag, vfov)
        print "new", newDist2
        cameraShape.dolly(v_dist * newDist2)
    """"
    after done calculating camera distance from obj bbox,
    parent obj to locator for rotation
    parenting duplicates the object in the outliner,creating 
    empty referenced group 
    """
    geo = pm.parent(geo, locator)
    print "parented", geo, "to", locator

    #  set render cam
    if cameraShape.getAttr('renderable') == False:
        cameraShape.setAttr('renderable', True)
        print "setting {0} as renderable".format(cameraShape)
    pm.renderSettings(cam=cameraShape)

    # create proxy
    pm.select(clear=True)
    proxy = pm.mel.eval("redshiftCreateProxy")
    proxyNode = pm.ls(proxy)[0]
    proxyNode.setAttr('fileName', str(geo))

    # scale props
    prop = pm.ls("props_GRP")
    grd = pm.ls("groundPlane_GEO")
    grd[0].setTranslation([0, -51, 0])
    offsetZ = v_r
    offsetY = v_r * 0.50
    offsetX = v_r * 0.70
    s = float(v_r)
    su = float(s / 100)  # to unit scale
    prop[0].setScale([su, su, su])
    prop[0].setTranslation([offsetX, offsetY, offsetZ])

    pm.group(cameraShape,
             locator,
             proxy,
             'redshiftProxyPlaceholder1',
             n="deleteMe")
    def process(self, context):

        # Collect sets named starting with "remote".
        remote_members = []
        for object_set in pm.ls(type="objectSet"):

            if object_set.name().lower().startswith("remote"):
                remote_members.extend(object_set.members())

        # Getting render layers data.
        data = {}
        render_cams = []
        drg = pm.PyNode("defaultRenderGlobals")
        for layer in pm.ls(type="renderLayer"):

            # skipping defaultRenderLayers
            if layer.name().endswith("defaultRenderLayer"):
                continue

            layer_data = {}
            render_cams = []
            if layer.adjustments.get(multiIndices=True):
                for count in layer.adjustments.get(multiIndices=True):
                    if not layer.adjustments[count].plug.connections():
                        continue

                    if layer.adjustments[count].plug.connections()[0] == drg:
                        attr = layer.adjustments[count].plug
                        attr = attr.connections(plugs=True)[0]
                        layer_value = layer.adjustments[count].value.get()
                        layer_data[attr.name(includeNode=False)] = layer_value

                    plug = layer.adjustments[count].plug
                    for cam_attr in plug.connections(plugs=True,
                                                     type="camera"):
                        renderable = cam_attr.endswith("renderable")
                        layer_value = layer.adjustments[count].value.get()
                        if renderable and layer_value == 1.0:
                            name = cam_attr.split(".")[0]
                            render_cams.append(pm.PyNode(name))

                render_pass = layer.connections(type="renderPass")
                layer_data["renderpasses"] = render_pass
            else:
                render_pass = layer.connections(type="renderPass")
                layer_data["renderpasses"] = render_pass

            layer_data["cameras"] = render_cams
            data[layer.name()] = layer_data

        # Create instances
        for layer in data:

            node = pm.PyNode(layer)

            # Checking instance type.
            instance_type = "local"
            if node in remote_members:
                instance_type = "remote"

            instance = context.create_instance(name=layer)
            instance.data["families"] = ["renderlayer", instance_type, "img"]
            instance.data["family"] = "img"

            instance.data.update(data[layer])
            instance.add(node)

            publish_state = pm.PyNode(layer).renderable.get()
            instance.data["publish"] = publish_state

            label = "{0} - renderlayer - {1}".format(layer, instance_type)
            instance.data["label"] = label

            # Generate collection
            first_image, last_image = pm.renderSettings(firstImageName=True,
                                                        lastImageName=True,
                                                        fullPath=True,
                                                        layer=layer)

            # Special case for vray that has it own extention setting
            renderer = drg.currentRenderer.get()

            if "currentRenderer" in data[layer]:
                renderer = data[layer]["currentRenderer"]

            if renderer == "vray":
                render_settings = pm.PyNode("vraySettings")

                # Assuming ".png" if nothing is set.
                # This happens when vray is initialized with the scene.
                ext = ".png"
                if render_settings.imageFormatStr.get():
                    ext = "."
                    ext += render_settings.imageFormatStr.get().split(" ")[0]

                first_image = os.path.splitext(first_image)[0] + ext

            # Adding renderer as family
            instance.data["families"] += [renderer]
            instance.data["renderer"] = renderer

            # Adding collection
            collections = clique.assemble([first_image], minimum_items=1)[0]
            ext = os.path.splitext(first_image)[1]
            collection = collections[0]
            for col in collections:
                if col.tail == ext:
                    collection = col

            render_globals = pm.PyNode("defaultRenderGlobals")
            start_frame = int(render_globals.startFrame.get())
            end_frame = int(render_globals.endFrame.get())
            step_frame = int(render_globals.byFrameStep.get())

            if "endFrame" in data[layer]:
                end_frame = int(data[layer]["endFrame"] * self.getFPS())
            if "startFrame" in data[layer]:
                start_frame = int(data[layer]["startFrame"] * self.getFPS())

            fmt = collection.format("{head}{padding}{tail}")
            for count in range(start_frame, end_frame + 1, step_frame):
                f = fmt % count
                collection.add(f)

            instance.data["endFrame"] = end_frame
            instance.data["startFrame"] = start_frame
            instance.data["stepFrame"] = step_frame
            instance.data["collection"] = collection
    def process(self, context):

        # getting output path
        render_globals = pm.PyNode('defaultRenderGlobals')

        projectPath = str(pm.system.Workspace.getPath().expand())


        # getting render layers data
        data = {}
        for layer in pm.ls(type='renderLayer'):

            # skipping non renderable layers
            if not layer.renderable.get():
                continue

            # skipping defaultRenderLayers
            if 'defaultRenderLayer' in layer.name():
                continue

            layer_data = {}
            if layer.adjustments.get(multiIndices=True):
                for count in layer.adjustments.get(multiIndices=True):
                    if layer.adjustments[count].plug.connections()[0] == render_globals:
                        attr = layer.adjustments[count].plug.connections(plugs=True)[0]
                        layer_data[attr.name(includeNode=False)] = layer.adjustments[count].value.get()
                data[layer.name()] = layer_data
            else:
                data[layer.name()] = {}

        # getting frames
        start_frame = int(render_globals.startFrame.get())
        end_frame = int(render_globals.endFrame.get())
        by_frame = int(render_globals.byFrameStep.get())

        frames = '{}-{}x{}'.format(start_frame, end_frame, by_frame)

        padding = render_globals.extensionPadding.get()
        padString = '#' * padding

        for layer in data:

            path = pm.renderSettings(fp=True, gin=padString, lyr=layer)[0]

            #create instance

            instance = context.create_instance(name=layer)
            instance.data['startFrame'] = int(start_frame)
            instance.data['endFrame'] = int(end_frame)
            instance.data['byFrame'] = by_frame
            instance.data['family'] = 'render'
            instance.data['families'] = ['deadline', 'render']
            instance.data['data'] = data[layer]
            instance.data["publish"] = False
            instance.data['projectPath'] = projectPath

            # getting job data
            job_data = {}
            if context.has_data('deadlineData'):
                job_data = context.data('deadlineData')['job'].copy()

            # setting job data
            safe_layer_name = layer.replace(':', '_')
            outputFile = path.format(layer=safe_layer_name)
            job_data['OutputFilename0'] = outputFile
            job_data['Frames'] = frames

            # setting plugin_data
            plugin_data = {}

            plugin_data['RenderLayer'] = layer
            try:
                plugin_data['Renderer'] = data[layer]['currentRenderer']
            except:
                plugin_data['Renderer'] = render_globals.currentRenderer.get()

            # add deadline data
            deadline_data = {'job': job_data, 'plugin': plugin_data}
            instance.data['deadlineData'] = deadline_data

            # adding ftrack data to activate processing
            instance.data['ftrackComponents'] = {}
            instance.data['ftrackAssetType'] = 'render'
Esempio n. 9
0
    def launch(self, *args, **kwargs):
        """launch renderer command
        """
        # do nothing if there is no window (called externally)
        if not self.window:
            return

        # warn the user about the ignore settings
        try:
            dAO = pm.PyNode('defaultArnoldRenderOptions')

            ignore_attrs = [
                'ignoreSubdivision', 'ignoreDisplacement', 'ignoreBump',
                'ignoreMotionBlur'
            ]

            attr_values = [dAO.getAttr(attr) for attr in ignore_attrs]

            if any(attr_values):
                msg_text = '<br>'.join(
                    map(lambda x, y: '%s: %s' % (x, y), ignore_attrs,
                        attr_values))

                response = pm.confirmDialog(
                    title='Ignore These Settings?',
                    message=
                    'You have ignored:<br><br>%s<br><br><b>Is that ok?</b>' %
                    msg_text,
                    button=['Yes', 'No'],
                    defaultButton='No',
                    cancelButton='No',
                    dismissString='No')

                if response == 'No':
                    return
        except pm.MayaNodeError:
            # no Arnold
            pass

        # check if rendering with persp camera
        try:
            wrong_camera_names = [
                'perspShape',
                'topShape',
                'sideShape',
                'fontShape',
                'persp1Shape',
                'perspShape1',
            ]
            renderable_cameras = [
                node for node in pm.ls(type='camera')
                if node.getAttr('renderable')
            ]
            if any(
                    map(lambda x: x.name() in wrong_camera_names,
                        renderable_cameras)):
                response = pm.confirmDialog(
                    title='Rendering with Persp?',
                    message=
                    'You are rendering with <b>Persp Camera<b><br><br>Is that ok?</b>',
                    button=['Yes', 'No'],
                    defaultButton='No',
                    cancelButton='No',
                    dismissString='No')

                if response == 'No':
                    return

            if len(renderable_cameras) > 1:
                response = pm.confirmDialog(
                    title='Rendering more than one Camera?',
                    message=
                    'You are rendering <b>more than one camera<b><br><br>Is that ok?</b>',
                    button=['Yes', 'No'],
                    defaultButton='No',
                    cancelButton='No',
                    dismissString='No')

                if response == 'No':
                    return

        except pm.MayaNodeError:
            # no default render globals node
            pass

        # get values
        start_frame = pm.intField('cgru_afanasy__start_frame', q=1, v=1)
        end_frame = pm.intField('cgru_afanasy__end_frame', q=1, v=1)
        frames_per_task = \
            pm.intField('cgru_afanasy__frames_per_task', q=1, v=1)
        by_frame = pm.intField('cgru_afanasy__by_frame', q=1, v=1)
        hosts_mask = pm.textField('cgru_afanasy__hosts_mask', q=1, text=True)
        hosts_exclude = pm.textField('cgru_afanasy__hosts_exclude',
                                     q=1,
                                     text=True)
        separate_layers = \
            pm.checkBox('cgru_afanasy__separate_layers', q=1, v=1)
        pause = pm.checkBox('cgru_afanasy__paused', q=1, v=1)

        # check values
        if start_frame > end_frame:
            temp = end_frame
            end_frame = start_frame
            start_frame = temp

        frames_per_task = max(1, frames_per_task)
        by_frame = max(1, by_frame)

        # store field values
        pm.optionVar['cgru_afanasy__start_frame_ov'] = start_frame
        pm.optionVar['cgru_afanasy__end_frame_ov'] = end_frame
        pm.optionVar['cgru_afanasy__frames_per_task_ov'] = frames_per_task
        pm.optionVar['cgru_afanasy__by_frame_ov'] = by_frame
        pm.optionVar['cgru_afanasy__hosts_mask_ov'] = hosts_mask
        pm.optionVar['cgru_afanasy__hosts_exclude_ov'] = hosts_exclude
        pm.optionVar['cgru_afanasy__separate_layers'] = separate_layers

        # get paths
        scene_name = pm.sceneName()
        datetime = '%s%s' % (time.strftime('%y%m%d-%H%M%S-'),
                             str(time.time() - int(time.time()))[2:5])

        filename = '%s.%s.mb' % (scene_name, datetime)

        project_path = pm.workspace(q=1, rootDirectory=1)

        outputs = ','.join(
            pm.renderSettings(fullPath=1, firstImageName=1, lastImageName=1))

        job_name = os.path.basename(scene_name)

        logger.debug('%ss %se %sr' % (start_frame, end_frame, by_frame))
        logger.debug('scene        = %s' % scene_name)
        logger.debug('file         = %s' % filename)
        logger.debug('job_name     = %s' % job_name)
        logger.debug('project_path = %s' % project_path)
        logger.debug('outputs      = %s' % outputs)

        if pm.checkBox('cgru_afanasy__close', q=1, v=1):
            pm.deleteUI(self.window)

        cmd_buffer = [
            '"%(filename)s"', '%(start)s', '%(end)s', '-by %(by_frame)s',
            '-hostsmask %(msk)s', '-hostsexcl %(exc)s', '-fpt %(fpt)s',
            '-name "%(name)s"', '-pwd "%(pwd)s"', '-proj "%(proj)s"',
            '-images "%(images)s"', '-deletescene'
        ]

        kwargs = {
            'filename': filename,
            'start': start_frame,
            'end': end_frame,
            'by_frame': by_frame,
            'msk': hosts_mask,
            'exc': hosts_exclude,
            'fpt': frames_per_task,
            'name': job_name,
            'pwd': project_path,
            'proj': project_path,
            'images': outputs
        }

        drg = pm.PyNode('defaultRenderGlobals')
        render_engine = drg.getAttr('currentRenderer')
        if render_engine == 'mentalRay':
            cmd_buffer.append('-type maya_mental')
        elif render_engine == 'arnold':
            cmd_buffer.append('-type maya_arnold')
            # set the verbosity level to warnin+info
            aro = pm.PyNode('defaultArnoldRenderOptions')
            aro.setAttr('log_verbosity', 1)

        if pause:
            cmd_buffer.append('-pause')

        # set output to console
        dARO = pm.PyNode('defaultArnoldRenderOptions')
        dARO.setAttr("log_to_console", 1)

        # save file
        pm.saveAs(filename, force=1, type='mayaBinary')

        # rename back to original name
        pm.renameFile(scene_name)

        # disable set output to console
        dARO.setAttr("log_to_console", 0)

        cmds = []

        # submit renders
        if separate_layers:
            # render each layer separately
            rlm = pm.PyNode('renderLayerManager')
            layers = [
                layer for layer in rlm.connections() if layer.renderable.get()
            ]

            for layer in layers:
                layer_name = layer.name()
                kwargs['name'] = '%s:%s' % (job_name, layer_name)

                tmp_cmd_buffer = copy.copy(cmd_buffer)
                tmp_cmd_buffer.append('-take %s' % layer.name())

                # create one big command
                afjob_cmd = ' '.join([
                    os.environ['CGRU_PYTHONEXE'],
                    '"%s/python/afjob.py"' % os.environ['AF_ROOT'],
                    '%s' % ' '.join(tmp_cmd_buffer) % kwargs
                ])
                cmds.append(afjob_cmd)

        else:
            # create one big command
            afjob_cmd = ' '.join([
                os.environ['CGRU_PYTHONEXE'],
                '%s/python/afjob.py' % os.environ['AF_ROOT'],
                '%s' % ' '.join(cmd_buffer) % kwargs
            ])
            cmds.append(afjob_cmd)

        # call each command separately
        for cmd in cmds:
            print(cmds)

            os.system(cmd)
Esempio n. 10
0
    def launch(self, *args, **kwargs):
        """launch renderer command
		"""
        # do nothing if there is no window (called externally)
        if not self.window:
            return

        # get values
        start_frame = pm.intField('cgru_afanasy__start_frame', q=1, v=1)
        end_frame = pm.intField('cgru_afanasy__end_frame', q=1, v=1)
        frames_per_task = \
         pm.intField('cgru_afanasy__frames_per_task', q=1, v=1)
        by_frame = pm.intField('cgru_afanasy__by_frame', q=1, v=1)
        hosts_mask = pm.textField('cgru_afanasy__hosts_mask', q=1, text=True)
        hosts_exclude = pm.textField('cgru_afanasy__hosts_exclude',
                                     q=1,
                                     text=True)
        separate_layers = \
         pm.checkBox('cgru_afanasy__separate_layers', q=1, v=1)
        pause = pm.checkBox('cgru_afanasy__paused', q=1, v=1)

        # check values
        if start_frame > end_frame:
            temp = end_frame
            end_frame = start_frame
            start_frame = temp

        frames_per_task = max(1, frames_per_task)
        by_frame = max(1, by_frame)

        # store field values
        pm.optionVar['cgru_afanasy__start_frame_ov'] = start_frame
        pm.optionVar['cgru_afanasy__end_frame_ov'] = end_frame
        pm.optionVar['cgru_afanasy__frames_per_task_ov'] = frames_per_task
        pm.optionVar['cgru_afanasy__by_frame_ov'] = by_frame
        pm.optionVar['cgru_afanasy__hosts_mask_ov'] = hosts_mask
        pm.optionVar['cgru_afanasy__hosts_exclude_ov'] = hosts_exclude
        pm.optionVar['cgru_afanasy__separate_layers'] = separate_layers

        # get paths
        scene_name = pm.sceneName()
        datetime = '%s%s' % (time.strftime('%y%m%d-%H%M%S-'),
                             str(time.time() - int(time.time()))[2:5])

        filename = '%s.%s.mb' % (scene_name, datetime)

        project_path = pm.workspace(q=1, rootDirectory=1)

        outputs = ','.join(
            pm.renderSettings(fullPath=1, firstImageName=1, lastImageName=1))

        job_name = os.path.basename(scene_name)

        logger.debug('%ss %se %sr' % (start_frame, end_frame, by_frame))
        logger.debug('scene        = %s' % scene_name)
        logger.debug('file         = %s' % filename)
        logger.debug('job_name     = %s' % job_name)
        logger.debug('project_path = %s' % project_path)
        logger.debug('outputs      = %s' % outputs)

        if pm.checkBox('cgru_afanasy__close', q=1, v=1):
            pm.deleteUI(self.window)

        cmd_buffer = [
            '"%(filename)s"', '%(start)s', '%(end)s', '-by %(by_frame)s',
            '-hostsmask %(msk)s', '-hostsexcl %(exc)s', '-fpt %(fpt)s',
            '-name "%(name)s"', '-proj "%(proj)s"', '-images "%(images)s"',
            '-deletescene'
        ]

        kwargs = {
            'filename': filename,
            'start': start_frame,
            'end': end_frame,
            'by_frame': by_frame,
            'msk': hosts_mask,
            'exc': hosts_exclude,
            'fpt': frames_per_task,
            'name': job_name,
            'proj': project_path,
            'images': outputs
        }

        drg = pm.PyNode('defaultRenderGlobals')
        if drg.getAttr('currentRenderer') == 'mentalRay':
            cmd_buffer.append('-type maya_mental')

        if pause:
            cmd_buffer.append('-pause')

        # save file
        pm.saveAs(filename, force=1, type='mayaBinary')

        # rename back to original name
        pm.renameFile(scene_name)

        cmds = []

        # submit renders
        if separate_layers:
            # render each layer separately
            rlm = pm.PyNode('renderLayerManager')
            layers = [
                layer for layer in rlm.connections() if layer.renderable.get()
            ]

            for layer in layers:
                layer_name = layer.name()
                kwargs['name'] = '%s:%s' % (job_name, layer_name)

                tmp_cmd_buffer = copy.copy(cmd_buffer)
                tmp_cmd_buffer.append('-take %s' % layer.name())

                # create one big command
                afjob_cmd = ' '.join([
                    os.environ['CGRU_PYTHONEXE'],
                    '"%s/python/afjob.py"' % os.environ['AF_ROOT'],
                    '%s' % ' '.join(tmp_cmd_buffer) % kwargs
                ])
                cmds.append(afjob_cmd)

        else:
            # create one big command
            afjob_cmd = ' '.join([
                os.environ['CGRU_PYTHONEXE'],
                '%s/python/afjob.py' % os.environ['AF_ROOT'],
                '%s' % ' '.join(cmd_buffer) % kwargs
            ])
            cmds.append(afjob_cmd)

        # call each command separately
        for cmd in cmds:
            print(cmds)

            os.system(cmd)
Esempio n. 11
0
    def launch(self, *args, **kwargs):
        """launch renderer command
        """
        # do nothing if there is no window (called externally)
        if not self.window:
            return

        # warn the user about the ignore settings
        try:
            dAO = pm.PyNode('defaultArnoldRenderOptions')

            ignore_attrs = [
                'ignoreSubdivision', 'ignoreDisplacement', 'ignoreBump',
                'ignoreMotionBlur'
            ]

            attr_values = [(attr, dAO.getAttr(attr)) for attr in ignore_attrs
                           if dAO.getAttr(attr) is True]

            if any(attr_values):
                msg_text = '<br>'.join(
                    map(lambda x: '%s: %s' % (x[0], x[1]), attr_values))

                response = pm.confirmDialog(
                    title='Ignore These Settings?',
                    message=
                    'You have ignored:<br><br>%s<br><br><b>Is that ok?</b>' %
                    msg_text,
                    button=['Yes', 'No'],
                    defaultButton='No',
                    cancelButton='No',
                    dismissString='No')

                if response == 'No':
                    return
        except (pm.MayaNodeError, pm.MayaAttributeError):
            # no Arnold
            pass

        # check if rendering with persp camera
        try:
            wrong_camera_names = [
                'perspShape',
                'topShape',
                'sideShape',
                'fontShape',
                'persp1Shape',
                'perspShape1',
            ]
            renderable_cameras = [
                node for node in pm.ls(type='camera')
                if node.getAttr('renderable')
            ]
            if any(
                    map(lambda x: x.name() in wrong_camera_names,
                        renderable_cameras)):
                response = pm.confirmDialog(
                    title='Rendering with Persp?',
                    message=
                    'You are rendering with <b>Persp Camera<b><br><br>Is that ok?</b>',
                    button=['Yes', 'No'],
                    defaultButton='No',
                    cancelButton='No',
                    dismissString='No')

                if response == 'No':
                    return

            if len(renderable_cameras) > 1:
                response = pm.confirmDialog(
                    title='Rendering more than one Camera?',
                    message=
                    'You are rendering <b>more than one camera<b><br><br>Is that ok?</b>',
                    button=['Yes', 'No'],
                    defaultButton='No',
                    cancelButton='No',
                    dismissString='No')

                if response == 'No':
                    return
            elif len(renderable_cameras) == 0:
                pm.confirmDialog(
                    title='No <b>Renderable</b> camera!!!',
                    message='There is no <b>renderable camera<b>!!!',
                    button=['Ok'],
                    defaultButton='Ok',
                    cancelButton='Ok',
                    dismissString='Ok')
                return

        except pm.MayaNodeError:
            # no default render globals node
            pass

        drg = pm.PyNode('defaultRenderGlobals')
        render_engine = drg.getAttr('currentRenderer')
        # RENDERER SPECIFIC CHECKS

        if render_engine == 'redshift':
            # if the renderer is RedShift
            # check if unifiedDisableDivision is 1 which will take too much time
            # to render
            dro = pm.PyNode('redshiftOptions')
            if dro.unifiedDisableDivision.get() == 1:
                response = pm.confirmDialog(
                    title=
                    "Enabled **Don't Automatically Reduce Samples of Other Effects**",
                    message=
                    'It is not allowed to render with the following option is enabled:<br>'
                    '<br>'
                    "Don't Automatically Reduce Samples of Other Effects: Enabled<br>"
                    "<br>"
                    "Please DISABLE it!",
                    button=['OK'],
                    defaultButton='OK',
                    cancelButton='OK',
                    dismissString='OK')
                return

            # Check dome light backgrounds
            domes_to_fix = []
            rs_domes = pm.ls(type='RedshiftDomeLight')
            if rs_domes:
                for rs_dome in rs_domes:
                    if rs_dome.getAttr('background_enable') == 1 \
                       or rs_dome.getAttr('backPlateEnabled') == 1:
                        domes_to_fix.append(rs_dome.name())

            if domes_to_fix:
                message = 'Some DomeLights have <b>BackGround Render ' \
                          'Enabled</b>:' \
                          '<br><br>%s<br><br>' \
                          'Are you Sure?' % '<br>'.join(domes_to_fix)

                response = pm.confirmDialog(
                    title='Dome Lights with Background Enabled?',
                    message=message,
                    button=['Yes', 'No'],
                    defaultButton='No',
                    cancelButton='No',
                    dismissString='No')
                if response == 'No':
                    return

            # abort on license fail
            dro.abortOnLicenseFail.set(1)

        elif render_engine == 'arnold':
            # check if the samples are too high
            dAO = pm.PyNode('defaultArnoldRenderOptions')

            aa_samples = dAO.AASamples.get()
            diff_samples = dAO.GIDiffuseSamples.get()
            try:
                glossy_samples = dAO.GIGlossySamples.get()
            except AttributeError:
                glossy_samples = dAO.GISpecularSamples.get()
            if int(pm.about(v=1)) >= 2017:
                sss_samples = dAO.GISssSamples.get()
            else:
                sss_samples = dAO.sssBssrdfSamples.get()

            total_diff_samples = aa_samples**2 * diff_samples**2
            total_glossy_samples = aa_samples**2 * glossy_samples**2
            total_sss_samples = aa_samples**2 * sss_samples**2

            max_allowed_diff_samples = 225
            max_allowed_glossy_samples = 100
            max_allowed_sss_samples = 800

            if total_diff_samples > max_allowed_diff_samples:
                pm.confirmDialog(
                    title="Too Much Diffuse Samples!!!",
                    message='You are using too much DIFFUSE SAMPLES (>%s)<br>'
                    '<br>'
                    'Please either reduce AA samples of Diffuse '
                    'Samples!!!' % max_allowed_diff_samples,
                    button=['OK'],
                    defaultButton='OK',
                    cancelButton='OK',
                    dismissString='OK')
                return

            if total_glossy_samples > max_allowed_glossy_samples:
                pm.confirmDialog(
                    title="Too Much Glossy Samples!!!",
                    message='You are using too much GLOSSY SAMPLES (>%s)<br>'
                    '<br>'
                    'Please either reduce AA samples of Glossy '
                    'Samples!!!' % max_allowed_glossy_samples,
                    button=['OK'],
                    defaultButton='OK',
                    cancelButton='OK',
                    dismissString='OK')
                return

            if total_sss_samples > max_allowed_sss_samples:
                pm.confirmDialog(
                    title="Too Much SSS Samples!!!",
                    message='You are using too much SSS SAMPLES (>%s)<br>'
                    '<br>'
                    'Please either reduce AA samples of SSS '
                    'Samples!!!' % max_allowed_sss_samples,
                    button=['OK'],
                    defaultButton='OK',
                    cancelButton='OK',
                    dismissString='OK')
                return

            # check Light Samples
            # check point lights with zero radius but more than one samples
            all_point_lights = pm.ls(type='pointLight')
            ridiculous_point_lights = []
            for point_light in all_point_lights:
                if point_light.aiRadius.get(
                ) < 0.1 and point_light.aiSamples.get() > 1:
                    ridiculous_point_lights.append(point_light)

            if ridiculous_point_lights:
                pm.confirmDialog(
                    title="Unnecessary Samples on Point Lights!!!",
                    message='You are using too much SAMPLES (>1)<br>'
                    '<br>'
                    'on <b>Point lights with zero radius</b><br>'
                    '<br>'
                    'Please reduce the samples to 1',
                    button=['OK'],
                    defaultButton='OK',
                    cancelButton='OK',
                    dismissString='OK')
                return

            # Check area lights with more than 2 samples
            all_area_lights = pm.ls(type=['areaLight', 'aiAreaLight'])
            ridiculous_area_lights = []
            for area_light in all_area_lights:
                if area_light.aiSamples.get() > 2:
                    ridiculous_area_lights.append(area_light)

            if ridiculous_area_lights:
                pm.confirmDialog(
                    title="Unnecessary Samples on Area Lights!!!",
                    message='You are using too much SAMPLES (>2) on<br>'
                    '<br>'
                    '<b>Area Lights</b><br>'
                    '<br>'
                    'Please reduce the samples to 2',
                    button=['OK'],
                    defaultButton='OK',
                    cancelButton='OK',
                    dismissString='OK')
                return

            # Check directional lights with angle == 0 and samples > 1
            all_directional_lights = pm.ls(type='directionalLight')
            ridiculous_directional_lights = []
            dir_sample_attr_name = 'aiSamples'
            # if pm.about(v=1) == "2014":
            #     dir_sample_attr_name = 'aiSamples'

            for directional_light in all_directional_lights:
                if directional_light.aiAngle.get(
                ) == 0 and directional_light.attr(
                        dir_sample_attr_name).get() > 1:
                    ridiculous_directional_lights.append(directional_light)

            if ridiculous_directional_lights:
                pm.confirmDialog(
                    title="Unnecessary Samples on Directional Lights!!!",
                    message='You are using too much SAMPLES (>1) on <br>'
                    '<br>'
                    '<b>Directional lights with zero angle</b><br>'
                    '<br>'
                    'Please reduce the samples to 1',
                    button=['OK'],
                    defaultButton='OK',
                    cancelButton='OK',
                    dismissString='OK')
                return

        # get values
        start_frame = pm.intField('cgru_afanasy__start_frame', q=1, v=1)
        end_frame = pm.intField('cgru_afanasy__end_frame', q=1, v=1)
        frames_per_task = \
            pm.intField('cgru_afanasy__frames_per_task', q=1, v=1)
        by_frame = pm.intField('cgru_afanasy__by_frame', q=1, v=1)
        depend_mask_global = pm.textField('cgru_afanasy__depend_mask_global',
                                          q=1,
                                          text=True)
        hosts_mask = pm.textField('cgru_afanasy__hosts_mask', q=1, text=True)
        hosts_exclude = pm.textField('cgru_afanasy__hosts_exclude',
                                     q=1,
                                     text=True)
        separate_layers = \
            pm.radioButtonGrp('cgru_afanasy__separate_layers', q=1, sl=1)
        pause = pm.checkBox('cgru_afanasy__paused', q=1, v=1)
        life_time = pm.intField('cgru_afanasy__life_time', q=1, v=1)
        annotation = pm.textField('cgru_afanasy__annotation', q=1, text=True)
        submit_multiple_times = pm.intField(
            'cgru_afanasy__submit_multiple_times', q=1, v=1)
        errors_avoid_host = pm.intField('cgru_afanasy__errors_avoid_host',
                                        q=1,
                                        v=1)
        errors_retries = pm.intField('cgru_afanasy__errors_retries', q=1, v=1)
        errors_task_same_host = pm.intField(
            'cgru_afanasy__errors_task_same_host', q=1, v=1)
        errors_forgive_time = pm.intField('cgru_afanasy__errors_forgive_time',
                                          q=1,
                                          v=1)

        generate_previews = pm.checkBox('cgru_afanasy__generate_previews',
                                        q=1,
                                        v=1)

        # check values
        if start_frame > end_frame:
            temp = end_frame
            end_frame = start_frame
            start_frame = temp

        frames_per_task = max(1, frames_per_task)
        by_frame = max(1, by_frame)

        # store without quota sign
        depend_mask_global = depend_mask_global.replace('"', '')
        hosts_mask = hosts_mask.replace('"', '')
        hosts_exclude = hosts_exclude.replace('"', '')

        # store field values
        pm.optionVar['cgru_afanasy__start_frame_ov'] = start_frame
        pm.optionVar['cgru_afanasy__end_frame_ov'] = end_frame
        pm.optionVar['cgru_afanasy__frames_per_task_ov'] = frames_per_task
        pm.optionVar['cgru_afanasy__by_frame_ov'] = by_frame
        pm.optionVar['cgru_afanasy__depend_mask_global_ov'] = \
            depend_mask_global
        pm.optionVar['cgru_afanasy__hosts_mask_ov'] = hosts_mask
        pm.optionVar['cgru_afanasy__hosts_exclude_ov'] = hosts_exclude
        pm.optionVar['cgru_afanasy__separate_layers_ov'] = separate_layers
        pm.optionVar['cgru_afanasy__life_time_ov'] = life_time
        pm.optionVar['cgru_afanasy__annotation_ov'] = annotation

        pm.optionVar[
            'cgru_afanasy__submit_multiple_times_ov'] = submit_multiple_times
        pm.optionVar['cgru_afanasy__errors_avoid_host_ov'] = errors_avoid_host
        pm.optionVar['cgru_afanasy__errors_retries_ov'] = errors_retries
        pm.optionVar[
            'cgru_afanasy__errors_task_same_host_ov'] = errors_task_same_host
        pm.optionVar[
            'cgru_afanasy__errors_errors_forgive_time_ov'] = errors_forgive_time
        pm.optionVar['cgru_afanasy__paused_ov'] = pause

        pm.optionVar['cgru_afanasy__generate_previews_ov'] = generate_previews

        # get paths
        scene_name = pm.sceneName()
        datetime = '%s%s' % (time.strftime('%y%m%d-%H%M%S-'),
                             str(time.time() - int(time.time()))[2:5])

        filename = '%s.%s.mb' % (scene_name, datetime)

        project_path = pm.workspace(q=1, rootDirectory=1)

        # outputs = \
        #     pm.renderSettings(fullPath=1, firstImageName=1, lastImageName=1)

        # get output paths, set the RenderPass token to Beauty,
        # this will at least guarantee to get something
        outputs = \
            pm.renderSettings(
                fullPath=1, firstImageName=1, lastImageName=1,
                leaveUnmatchedTokens=1, customTokenString="RenderPass=Beauty"
            )

        # job_name = os.path.basename(scene_name)
        job_name = self.generate_job_name()

        logger.debug('%ss %se %sr' % (start_frame, end_frame, by_frame))
        logger.debug('scene                 = %s' % scene_name)
        logger.debug('file                  = %s' % filename)
        logger.debug('job_name              = %s' % job_name)
        logger.debug('project_path          = %s' % project_path)
        logger.debug('outputs               = %s' % outputs)
        logger.debug('annotation            = %s' % annotation)
        logger.debug('separate_layers       = %s' % separate_layers)
        logger.debug('errors_avoid_host     = %s' % errors_avoid_host)
        logger.debug('errors_retries        = %s' % errors_retries)
        logger.debug('errors_task_same_host = %s' % errors_task_same_host)
        logger.debug('errors_forgive_time   = %s' % errors_forgive_time)
        logger.debug('generate_previews     = %s' % generate_previews)

        if pm.checkBox('cgru_afanasy__close', q=1, v=1):
            pm.deleteUI(self.window)

        stored_log_level = None
        if render_engine == 'arnold':
            # set the verbosity level to warning+info
            aro = pm.PyNode('defaultArnoldRenderOptions')
            stored_log_level = aro.getAttr('log_verbosity')
            aro.setAttr('log_verbosity', 2)
            # set output to console
            aro.setAttr("log_to_console", 1)
        elif render_engine == 'redshift':
            # set the verbosity level to detailed+info
            redshift = pm.PyNode('redshiftOptions')
            stored_log_level = redshift.logLevel.get()
            redshift.logLevel.set(2)

        # save file
        pm.saveAs(filename, force=1, type='mayaBinary')

        # rename back to original name
        pm.renameFile(scene_name)

        # create the render command
        mrc = MayaRenderCommandBuilder(name=job_name,
                                       file_full_path=filename,
                                       render_engine=render_engine,
                                       project=project_path,
                                       by_frame=by_frame)

        # submit renders
        jobs = []
        blocks = []

        #
        # separate_layers:
        # 1 -> None  -> submit one job with a single block with all layers
        # 2 -> Block -> submit one job with multiple blocks
        # 3 -> Job   -> submit multiple jobs with a single block per layer
        #
        if separate_layers in [1, 2]:
            job = af.Job(job_name)
            jobs.append(job)

        if separate_layers in [2, 3]:
            # render each layer separately
            rlm = pm.PyNode('renderLayerManager')
            layers = [
                layer for layer in rlm.connections(type=pm.nt.RenderLayer)
                if layer.renderable.get()
            ]

            for layer in layers:
                mrc_layer = copy.copy(mrc)
                layer_name = layer.name()
                mrc_layer.name = layer_name
                mrc_layer.render_layer = layer_name

                # create a new block for this layer
                block = af.Block(
                    layer_name,
                    renderer_to_block_type.get(render_engine, 'maya'))

                # Fix the output path for this layer
                # by replacing the "masterLayer" with the layer name
                # without rs_ at the beginning
                layer_outputs = outputs
                if layer_name != 'defaultRenderLayer':
                    layer_outputs[0] = outputs[0].replace(
                        'masterLayer', layer_name.replace('rs_', ''))
                    layer_outputs[1] = outputs[1].replace(
                        'masterLayer', layer_name.replace('rs_', ''))

                if generate_previews:
                    outputs_split = afcommon.patternFromDigits(
                        afcommon.patternFromStdC(
                            afcommon.patternFromPaths(
                                layer_outputs[0],
                                layer_outputs[1]))).split(';')
                    block.setFiles(outputs_split)

                block.setNumeric(start_frame, end_frame, frames_per_task,
                                 by_frame)
                command = mrc_layer.build_command()

                block.setErrorsAvoidHost(errors_avoid_host)
                block.setErrorsRetries(errors_retries)
                block.setErrorsTaskSameHost(errors_task_same_host)
                block.setErrorsForgiveTime(errors_forgive_time)

                block.setCommand(command)

                if separate_layers == 2:
                    blocks.append(block)
                else:
                    job = af.Job('%s - %s' % (job_name, layer_name))
                    # add blocks
                    job.blocks = [block]
                    jobs.append(job)

        else:
            # create only one block
            block = af.Block('All Layers',
                             renderer_to_block_type.get(render_engine, 'maya'))

            if generate_previews:
                block.setFiles(
                    afcommon.patternFromDigits(
                        afcommon.patternFromStdC(
                            afcommon.patternFromPaths(outputs[0],
                                                      outputs[1]))).split(';'))

            block.setNumeric(start_frame, end_frame, frames_per_task, by_frame)
            command = mrc.build_command()
            block.setCommand(command)

            blocks.append(block)

        for job in jobs:
            job.setAnnotation(annotation)
            job.setFolder('input', os.path.dirname(filename))
            job.setFolder('output', os.path.dirname(outputs[0]))
            job.setDependMaskGlobal(depend_mask_global)
            job.setHostsMask(hosts_mask)
            job.setHostsMaskExclude(hosts_exclude)
            if life_time > 0:
                job.setTimeLife(life_time * 3600)
            else:
                job.setTimeLife(240 * 3600)

            job.setCmdPost('deletefiles -s "%s"' % os.path.abspath(filename))
            if pause:
                job.offline()

            # add blocks
            if separate_layers in [1, 2]:
                job.blocks.extend(blocks)

            for i in range(submit_multiple_times):
                orig_job_name = job.data['name']
                job.setName('%s - %03i' % (orig_job_name, i + 1))
                status, data = job.send()

                # restore job name
                job.setName(orig_job_name)
                if not status:
                    pm.PopupError('Something went wrong!')

        # restore log level
        if render_engine == 'arnold':
            aro = pm.PyNode('defaultArnoldRenderOptions')
            aro.setAttr('log_verbosity', stored_log_level)
            # disable set output to console
            aro.setAttr("log_to_console", 0)
        elif render_engine == 'redshift':
            redshift = pm.PyNode('redshiftOptions')
            redshift.logLevel.set(stored_log_level)

            # disable abort on license fail
            redshift.abortOnLicenseFail.set(0)
Esempio n. 12
0
    def launch(self, *args, **kwargs):
        """launch renderer command
        """
        # do nothing if there is no window (called externally)
        if not self.window:
            return

        # warn the user about the ignore settings
        try:
            dAO = pm.PyNode('defaultArnoldRenderOptions')

            ignore_attrs = [
                'ignoreSubdivision',
                'ignoreDisplacement',
                'ignoreBump',
                'ignoreMotionBlur'
            ]

            attr_values = [
                (attr, dAO.getAttr(attr))
                for attr in ignore_attrs
                if dAO.getAttr(attr) is True
            ]

            if any(attr_values):
                msg_text = '<br>'.join(
                    map(
                        lambda x: '%s: %s' % (x[0], x[1]),
                        attr_values
                    )
                )

                response = pm.confirmDialog(
                    title='Ignore These Settings?',
                    message='You have ignored:<br><br>%s<br><br><b>Is that ok?</b>' % msg_text,
                    button=['Yes', 'No'],
                    defaultButton='No',
                    cancelButton='No',
                    dismissString='No'
                )

                if response == 'No':
                    return
        except pm.MayaNodeError:
            # no Arnold
            pass

        # check if rendering with persp camera
        try:
            wrong_camera_names = [
                'perspShape',
                'topShape',
                'sideShape',
                'fontShape',

                'persp1Shape',
                'perspShape1',
            ]
            renderable_cameras = [node for node in pm.ls(type='camera') if node.getAttr('renderable')]
            if any(map(lambda x: x.name() in wrong_camera_names, renderable_cameras)):
                response = pm.confirmDialog(
                    title='Rendering with Persp?',
                    message='You are rendering with <b>Persp Camera<b><br><br>Is that ok?</b>',
                    button=['Yes', 'No'],
                    defaultButton='No',
                    cancelButton='No',
                    dismissString='No'
                )

                if response == 'No':
                    return

            if len(renderable_cameras) > 1:
                response = pm.confirmDialog(
                    title='Rendering more than one Camera?',
                    message='You are rendering <b>more than one camera<b><br><br>Is that ok?</b>',
                    button=['Yes', 'No'],
                    defaultButton='No',
                    cancelButton='No',
                    dismissString='No'
                )

                if response == 'No':
                    return
            elif len(renderable_cameras) == 0:
                pm.confirmDialog(
                    title='No <b>Renderable</b> camera!!!',
                    message='There is no <b>renderable camera<b>!!!',
                    button=['Ok'],
                    defaultButton='Ok',
                    cancelButton='Ok',
                    dismissString='Ok'
                )
                return

        except pm.MayaNodeError:
            # no default render globals node
            pass

        drg = pm.PyNode('defaultRenderGlobals')
        render_engine = drg.getAttr('currentRenderer')
        # RENDERER SPECIFIC CHECKS

        if render_engine == 'redshift':
            # if the renderer is RedShift
            # check if unifiedDisableDivision is 1 which will take too much time
            # to render
            dro = pm.PyNode('redshiftOptions')
            if dro.unifiedDisableDivision.get() == 1:
                response = pm.confirmDialog(
                    title="Enabled **Don't Automatically Reduce Samples of Other Effects**",
                    message='It is not allowed to render with the following option is enabled:<br>'
                            '<br>'
                            "Don't Automatically Reduce Samples of Other Effects: Enabled<br>"
                            "<br>"
                            "Please DISABLE it!",
                    button=['OK'],
                    defaultButton='OK',
                    cancelButton='OK',
                    dismissString='OK'
                )
                return

        elif render_engine == 'arnold':
            # check if the samples are too high
            dAO = pm.PyNode('defaultArnoldRenderOptions')


            aa_samples = dAO.AASamples.get()
            diff_samples = dAO.GIDiffuseSamples.get()
            glossy_samples = dAO.GIGlossySamples.get()
            if int(pm.about(v=1)) >= 2017:
                sss_samples = dAO.GISssSamples.get()
            else:
                sss_samples = dAO.sssBssrdfSamples.get()

            total_diff_samples = aa_samples**2 * diff_samples**2
            total_glossy_samples = aa_samples**2 * glossy_samples**2
            total_sss_samples = aa_samples**2 * sss_samples**2

            max_allowed_diff_samples = 225
            max_allowed_glossy_samples = 100
            max_allowed_sss_samples = 450

            if total_diff_samples > max_allowed_diff_samples:
                pm.confirmDialog(
                    title="Too Much Diffuse Samples!!!",
                    message='You are using too much DIFFUSE SAMPLES (>%s)<br>'
                            '<br>'
                            'Please either reduce AA samples of Diffuse '
                            'Samples!!!' % max_allowed_diff_samples,
                    button=['OK'],
                    defaultButton='OK',
                    cancelButton='OK',
                    dismissString='OK'
                )
                return

            if total_glossy_samples > max_allowed_glossy_samples:
                pm.confirmDialog(
                    title="Too Much Glossy Samples!!!",
                    message='You are using too much GLOSSY SAMPLES (>%s)<br>'
                            '<br>'
                            'Please either reduce AA samples of Glossy '
                            'Samples!!!' % max_allowed_glossy_samples,
                    button=['OK'],
                    defaultButton='OK',
                    cancelButton='OK',
                    dismissString='OK'
                )
                return

            if total_sss_samples > max_allowed_sss_samples:
                pm.confirmDialog(
                    title="Too Much SSS Samples!!!",
                    message='You are using too much SSS SAMPLES (>%s)<br>'
                            '<br>'
                            'Please either reduce AA samples of SSS '
                            'Samples!!!' % max_allowed_sss_samples,
                    button=['OK'],
                    defaultButton='OK',
                    cancelButton='OK',
                    dismissString='OK'
                )
                return

            # check Light Samples
            # check point lights with zero radius but more than one samples
            all_point_lights = pm.ls(type='pointLight')
            ridiculous_point_lights = []
            for point_light in all_point_lights:
                if point_light.aiRadius.get() < 0.1 and point_light.aiSamples.get() > 1:
                    ridiculous_point_lights.append(point_light)

            if ridiculous_point_lights:
                pm.confirmDialog(
                    title="Unnecessary Samples on Point Lights!!!",
                    message='You are using too much SAMPLES (>1)<br>'
                            '<br>'
                            'on <b>Point lights with zero radius</b><br>'
                            '<br>'
                            'Please reduce the samples to 1',
                    button=['OK'],
                    defaultButton='OK',
                    cancelButton='OK',
                    dismissString='OK'
                )
                return

            # Check area lights with more than 2 samples
            all_area_lights = pm.ls(type=['areaLight', 'aiAreaLight'])
            ridiculous_area_lights = []
            for area_light in all_area_lights:
                if area_light.aiSamples.get() > 2:
                    ridiculous_area_lights.append(area_light)

            if ridiculous_area_lights:
                pm.confirmDialog(
                    title="Unnecessary Samples on Area Lights!!!",
                    message='You are using too much SAMPLES (>2) on<br>'
                            '<br>'
                            '<b>Area Lights</b><br>'
                            '<br>'
                            'Please reduce the samples to 2',
                    button=['OK'],
                    defaultButton='OK',
                    cancelButton='OK',
                    dismissString='OK'
                )
                return

            # Check directional lights with angle == 0 and samples > 1
            all_directional_lights = pm.ls(type='directionalLight')
            ridiculous_directional_lights = []
            for directional_light in all_directional_lights:
                if directional_light.aiAngle.get() == 0 and directional_light.aiSample.get() > 1:
                    ridiculous_directional_lights.append(directional_light)

            if ridiculous_directional_lights:
                pm.confirmDialog(
                    title="Unnecessary Samples on Directional Lights!!!",
                    message='You are using too much SAMPLES (>1) on <br>'
                            '<br>'
                            '<b>Directional lights with zero angle</b><br>'
                            '<br>'
                            'Please reduce the samples to 1',
                    button=['OK'],
                    defaultButton='OK',
                    cancelButton='OK',
                    dismissString='OK'
                )
                return

        # get values
        start_frame = pm.intField('cgru_afanasy__start_frame', q=1, v=1)
        end_frame = pm.intField('cgru_afanasy__end_frame', q=1, v=1)
        frames_per_task = \
            pm.intField('cgru_afanasy__frames_per_task', q=1, v=1)
        by_frame = pm.intField('cgru_afanasy__by_frame', q=1, v=1)
        hosts_mask = pm.textField('cgru_afanasy__hosts_mask', q=1, text=True)
        hosts_exclude = pm.textField('cgru_afanasy__hosts_exclude', q=1, text=True)
        separate_layers = \
            pm.checkBox('cgru_afanasy__separate_layers', q=1, v=1)
        pause = pm.checkBox('cgru_afanasy__paused', q=1, v=1)
        life_time = pm.intField('cgru_afanasy__life_time', q=1, v=1)

        # check values
        if start_frame > end_frame:
            temp = end_frame
            end_frame = start_frame
            start_frame = temp

        frames_per_task = max(1, frames_per_task)
        by_frame = max(1, by_frame)

        # store without quota sign
        hosts_mask = hosts_mask.replace('"', '')
        hosts_exclude = hosts_exclude.replace('"', '')

        # store field values
        pm.optionVar['cgru_afanasy__start_frame_ov'] = start_frame
        pm.optionVar['cgru_afanasy__end_frame_ov'] = end_frame
        pm.optionVar['cgru_afanasy__frames_per_task_ov'] = frames_per_task
        pm.optionVar['cgru_afanasy__by_frame_ov'] = by_frame
        pm.optionVar['cgru_afanasy__hosts_mask_ov'] = hosts_mask
        pm.optionVar['cgru_afanasy__hosts_exclude_ov'] = hosts_exclude
        pm.optionVar['cgru_afanasy__separate_layers_ov'] = separate_layers
        pm.optionVar['cgru_afanasy__life_time_ov'] = life_time

        # get paths
        scene_name = pm.sceneName()
        datetime = '%s%s' % (
            time.strftime('%y%m%d-%H%M%S-'),
            str(time.time() - int(time.time()))[2:5]
        )

        filename = '%s.%s.mb' % (scene_name, datetime)

        project_path = pm.workspace(q=1, rootDirectory=1)

        outputs = \
            pm.renderSettings(fullPath=1, firstImageName=1, lastImageName=1)

        # job_name = os.path.basename(scene_name)
        job_name = self.generate_job_name()

        logger.debug('%ss %se %sr' % (start_frame, end_frame, by_frame))
        logger.debug('scene        = %s' % scene_name)
        logger.debug('file         = %s' % filename)
        logger.debug('job_name     = %s' % job_name)
        logger.debug('project_path = %s' % project_path)
        logger.debug('outputs      = %s' % outputs)

        if pm.checkBox('cgru_afanasy__close', q=1, v=1):
            pm.deleteUI(self.window)



        job = af.Job(job_name)

        stored_log_level = None
        if render_engine == 'arnold':
            # set the verbosity level to warning+info
            aro = pm.PyNode('defaultArnoldRenderOptions')
            stored_log_level = aro.getAttr('log_verbosity')
            aro.setAttr('log_verbosity', 1)
            # set output to console
            aro.setAttr("log_to_console", 1)
        elif render_engine == 'redshift':
            # set the verbosity level to detailed+info
            redshift = pm.PyNode('redshiftOptions')
            stored_log_level = redshift.logLevel.get()
            redshift.logLevel.set(2)

        # save file
        pm.saveAs(
            filename,
            force=1,
            type='mayaBinary'
        )

        # rename back to original name
        pm.renameFile(scene_name)

        # create the render command
        mrc = MayaRenderCommandBuilder(
            name=job_name, file_full_path=filename,
            render_engine=render_engine, project=project_path,
            by_frame=by_frame
        )

        # submit renders
        blocks = []
        if separate_layers:
            # render each layer separately
            rlm = pm.PyNode('renderLayerManager')
            layers = [layer for layer in rlm.connections()
                      if layer.renderable.get()]

            for layer in layers:
                mrc_layer = copy.copy(mrc)
                layer_name = layer.name()
                mrc_layer.name = layer_name
                mrc_layer.render_layer = layer_name

                # create a new block for this layer
                block = af.Block(
                    layer_name,
                    renderer_to_block_type.get(render_engine, 'maya')
                )

                block.setFiles(
                    afcommon.patternFromDigits(
                        afcommon.patternFromStdC(
                            afcommon.patternFromPaths(outputs[0], outputs[1])
                        )
                    ).split(';')
                )
                block.setNumeric(
                    start_frame, end_frame, frames_per_task, by_frame
                )
                block.setCommand(mrc_layer.build_command())

                blocks.append(block)
        else:
            # create only one block
            block = af.Block(
                'All Layers',
                renderer_to_block_type.get(render_engine, 'maya')
            )

            block.setFiles(
                afcommon.patternFromDigits(
                    afcommon.patternFromStdC(
                        afcommon.patternFromPaths(outputs[0], outputs[1])
                    )
                ).split(';')
            )
            block.setNumeric(
                start_frame, end_frame, frames_per_task, by_frame
            )
            block.setCommand(mrc.build_command())

            blocks.append(block)

        job.setFolder('input', os.path.dirname(filename))
        job.setFolder('output', os.path.dirname(outputs[0]))
        job.setHostsMask(hosts_mask)
        job.setHostsMaskExclude(hosts_exclude)
        if life_time > 0:
            job.setTimeLife(life_time * 3600)

        job.setCmdPost('deletefiles "%s"' % os.path.abspath(filename))
        if pause:
            job.offline()

        # add blocks
        job.blocks.extend(blocks)

        status, data = job.send()
        if not status:
            pm.PopupError('Something went wrong!')
        print('data: %s' % data)

        # restore log level
        if render_engine == 'arnold':
            aro = pm.PyNode('defaultArnoldRenderOptions')
            aro.setAttr('log_verbosity', stored_log_level)
            # disable set output to console
            aro.setAttr("log_to_console", 0)
        elif render_engine == 'redshift':
            redshift = pm.PyNode('redshiftOptions')
            redshift.logLevel.set(stored_log_level)
Esempio n. 13
0
    def launch(self, *args, **kwargs):
        """launch renderer command
        """
        # do nothing if there is no window (called externally)
        if not self.window:
            return

        # warn the user about the ignore settings
        try:
            dAO = pm.PyNode('defaultArnoldRenderOptions')

            ignore_attrs = [
                'ignoreSubdivision',
                'ignoreDisplacement',
                'ignoreBump',
                'ignoreMotionBlur'
            ]

            attr_values = [
                (attr, dAO.getAttr(attr))
                for attr in ignore_attrs
                if dAO.getAttr(attr) is True
            ]

            if any(attr_values):
                msg_text = '<br>'.join(
                    map(
                        lambda x: '%s: %s' % (x[0], x[1]),
                        attr_values
                    )
                )

                response = pm.confirmDialog(
                    title='Ignore These Settings?',
                    message='You have ignored:<br><br>%s<br><br><b>Is that ok?</b>' % msg_text,
                    button=['Yes', 'No'],
                    defaultButton='No',
                    cancelButton='No',
                    dismissString='No'
                )

                if response == 'No':
                    return
        except pm.MayaNodeError:
            # no Arnold
            pass

        # check if rendering with persp camera
        try:
            wrong_camera_names = [
                'perspShape',
                'topShape',
                'sideShape',
                'fontShape',

                'persp1Shape',
                'perspShape1',
            ]
            renderable_cameras = [node for node in pm.ls(type='camera') if node.getAttr('renderable')]
            if any(map(lambda x: x.name() in wrong_camera_names, renderable_cameras)):
                response = pm.confirmDialog(
                    title='Rendering with Persp?',
                    message='You are rendering with <b>Persp Camera<b><br><br>Is that ok?</b>',
                    button=['Yes', 'No'],
                    defaultButton='No',
                    cancelButton='No',
                    dismissString='No'
                )

                if response == 'No':
                    return

            if len(renderable_cameras) > 1:
                response = pm.confirmDialog(
                    title='Rendering more than one Camera?',
                    message='You are rendering <b>more than one camera<b><br><br>Is that ok?</b>',
                    button=['Yes', 'No'],
                    defaultButton='No',
                    cancelButton='No',
                    dismissString='No'
                )

                if response == 'No':
                    return
            elif len(renderable_cameras) == 0:
                pm.confirmDialog(
                    title='No <b>Renderable</b> camera!!!',
                    message='There is no <b>renderable camera<b>!!!',
                    button=['Ok'],
                    defaultButton='Ok',
                    cancelButton='Ok',
                    dismissString='Ok'
                )
                return

        except pm.MayaNodeError:
            # no default render globals node
            pass

        # get values
        start_frame = pm.intField('cgru_afanasy__start_frame', q=1, v=1)
        end_frame = pm.intField('cgru_afanasy__end_frame', q=1, v=1)
        frames_per_task = \
            pm.intField('cgru_afanasy__frames_per_task', q=1, v=1)
        by_frame = pm.intField('cgru_afanasy__by_frame', q=1, v=1)
        hosts_mask = pm.textField('cgru_afanasy__hosts_mask', q=1, text=True)
        hosts_exclude = pm.textField('cgru_afanasy__hosts_exclude', q=1, text=True)
        separate_layers = \
            pm.checkBox('cgru_afanasy__separate_layers', q=1, v=1)
        pause = pm.checkBox('cgru_afanasy__paused', q=1, v=1)
        life_time = pm.intField('cgru_afanasy__life_time', q=1, v=1)

        # check values
        if start_frame > end_frame:
            temp = end_frame
            end_frame = start_frame
            start_frame = temp

        frames_per_task = max(1, frames_per_task)
        by_frame = max(1, by_frame)

        # store without quota sign
        hosts_mask = hosts_mask.replace('"', '')
        hosts_exclude = hosts_exclude.replace('"', '')

        # store field values
        pm.optionVar['cgru_afanasy__start_frame_ov'] = start_frame
        pm.optionVar['cgru_afanasy__end_frame_ov'] = end_frame
        pm.optionVar['cgru_afanasy__frames_per_task_ov'] = frames_per_task
        pm.optionVar['cgru_afanasy__by_frame_ov'] = by_frame
        pm.optionVar['cgru_afanasy__hosts_mask_ov'] = hosts_mask
        pm.optionVar['cgru_afanasy__hosts_exclude_ov'] = hosts_exclude
        pm.optionVar['cgru_afanasy__separate_layers_ov'] = separate_layers
        pm.optionVar['cgru_afanasy__life_time_ov'] = life_time

        # get paths
        scene_name = pm.sceneName()
        datetime = '%s%s' % (
            time.strftime('%y%m%d-%H%M%S-'),
            str(time.time() - int(time.time()))[2:5]
        )

        filename = '%s.%s.mb' % (scene_name, datetime)

        project_path = pm.workspace(q=1, rootDirectory=1)

        # get output paths, set the RenderPass token to Beauty,
        # this will at least guarantee to get something
        outputs = \
            pm.renderSettings(
                fullPath=1, firstImageName=1, lastImageName=1,
                leaveUnmatchedTokens=1, customTokenString="RenderPass=Beauty"
            )

        job_name = os.path.basename(scene_name)

        logger.debug('%ss %se %sr' % (start_frame, end_frame, by_frame))
        logger.debug('scene        = %s' % scene_name)
        logger.debug('file         = %s' % filename)
        logger.debug('job_name     = %s' % job_name)
        logger.debug('project_path = %s' % project_path)
        logger.debug('outputs      = %s' % outputs)

        if pm.checkBox('cgru_afanasy__close', q=1, v=1):
            pm.deleteUI(self.window)

        drg = pm.PyNode('defaultRenderGlobals')
        render_engine = drg.getAttr('currentRenderer')

        job = af.Job(job_name)

        stored_log_level = None
        if render_engine == 'arnold':
            # set the verbosity level to warning+info
            aro = pm.PyNode('defaultArnoldRenderOptions')
            stored_log_level = aro.getAttr('log_verbosity')
            aro.setAttr('log_verbosity', 1)
            # set output to console
            aro.setAttr("log_to_console", 1)
        elif render_engine == 'redshift':
            # set the verbosity level to detailed+info
            redshift = pm.PyNode('redshiftOptions')
            stored_log_level = redshift.logLevel.get()
            redshift.logLevel.set(2)

        # save file
        pm.saveAs(
            filename,
            force=1,
            type='mayaBinary'
        )

        # rename back to original name
        pm.renameFile(scene_name)

        # create the render command
        mrc = MayaRenderCommandBuilder(
            name=job_name, file_full_path=filename,
            render_engine=render_engine, project=project_path,
            by_frame=by_frame
        )

        # submit renders
        blocks = []
        if separate_layers:
            # render each layer separately
            rlm = pm.PyNode('renderLayerManager')
            layers = [layer for layer in rlm.connections()
                      if layer.renderable.get()]

            for layer in layers:
                mrc_layer = copy.copy(mrc)
                layer_name = layer.name()
                mrc_layer.name = layer_name
                mrc_layer.render_layer = layer_name

                # create a new block for this layer
                block = af.Block(
                    layer_name,
                    renderer_to_block_type.get(render_engine, 'maya')
                )

                block.setFiles(
                    afcommon.patternFromDigits(
                        afcommon.patternFromStdC(
                            afcommon.patternFromPaths(outputs[0], outputs[1])
                        )
                    ).split(';')
                )
                block.setNumeric(
                    start_frame, end_frame, frames_per_task, by_frame
                )
                block.setCommand(mrc_layer.build_command())

                blocks.append(block)
        else:
            # create only one block
            block = af.Block(
                'All Layers',
                renderer_to_block_type.get(render_engine, 'maya')
            )

            block.setFiles(
                afcommon.patternFromDigits(
                    afcommon.patternFromStdC(
                        afcommon.patternFromPaths(outputs[0], outputs[1])
                    )
                ).split(';')
            )
            block.setNumeric(
                start_frame, end_frame, frames_per_task, by_frame
            )
            block.setCommand(mrc.build_command())

            blocks.append(block)

        job.setFolder('input', os.path.dirname(filename))
        job.setFolder('output', os.path.dirname(outputs[0]))
        job.setHostsMask(hosts_mask)
        job.setHostsMaskExclude(hosts_exclude)
        if life_time > 0:
            job.setTimeLife(life_time * 3600)

        job.setCmdPost('deletefiles "%s"' % os.path.abspath(filename))
        if pause:
            job.offline()

        # add blocks
        job.blocks.extend(blocks)

        status, data = job.send()
        if not status:
            pm.PopupError('Something went wrong!')
        print('data: %s' % data)

        # restore log level
        if render_engine == 'arnold':
            aro = pm.PyNode('defaultArnoldRenderOptions')
            aro.setAttr('log_verbosity', stored_log_level)
            # disable set output to console
            aro.setAttr("log_to_console", 0)
        elif render_engine == 'redshift':
            redshift = pm.PyNode('redshiftOptions')
            redshift.logLevel.set(stored_log_level)
Esempio n. 14
0
def render_sequence(start_frame, end_frame, renderlayer_name=None):
    # Evaluate pre render mel.
    pre_mel = cmds.getAttr("defaultRenderGlobals.preMel")
    if pre_mel:
        print("Evaluating Pre Render MEL:\n{}".format(pre_mel))
        mel.eval(pre_mel)

    # Setting output to local temp directory.
    output_path = os.path.join(cmds.workspace(query=True, rootDirectory=True),
                               pm.workspace.fileRules["images"]).replace(
                                   "\\", "/")

    temp_path = tempfile.mkdtemp().replace("\\", "/")
    pm.workspace.fileRules["images"] = temp_path

    # Get all renderable layers.
    render_setup = renderSetup.instance()
    render_layers = render_setup.getRenderLayers()

    renderable_layers = []
    for layer in render_layers:
        # Add all render layers when none is specified.
        if renderlayer_name is None and layer.isRenderable():
            renderable_layers.append(layer)

        # Only add the render layer if its requested.
        if ("rs_" + layer.name()) == renderlayer_name:
            renderable_layers.append(layer)

    print("Renderable layers: {}".format([x.name()
                                          for x in renderable_layers]))

    for layer in renderable_layers:
        print("Switching to: {}".format(layer.name()))
        render_setup.switchToLayer(layer)
        for count in range(start_frame, end_frame + 1):
            print("Rendering frame: {}".format(count))
            render_frame(count)

        # Move renders to expected output path.
        first_image = pm.renderSettings(firstImageName=True, fullPath=True)[0]
        expected_output_path = os.path.join(
            cmds.workspace(query=True, rootDirectory=True),
            pm.workspace.fileRules["images"])
        prefix_directories = os.path.dirname(first_image).replace(
            expected_output_path, "")

        renderer = cmds.getAttr("defaultRenderGlobals.currentRenderer")
        actual_prefix_directories = os.path.dirname(first_image).replace(
            expected_output_path, "")
        # Maya Hardware seems to always have "masterLayer" as the layer name.
        if renderer == "mayaHardware2":
            actual_prefix_directories = actual_prefix_directories.replace(
                layer.name(), "masterLayer")

        actual_output_path = (os.path.join(expected_output_path, "tmp") +
                              actual_prefix_directories)

        for f in os.listdir(actual_output_path):
            source = os.path.join(actual_output_path, f).replace("\\", "/")

            # Rendering through Arnold adds "_1" to the file name.
            destination_filename = f.replace("_1", "")
            # Rendering through Maya Hardware seems to always be "masterLayer"
            # as the layer name.
            destination_filename = destination_filename.replace(
                "masterLayer", layer.name())

            destination = os.path.join(
                expected_output_path + prefix_directories,
                destination_filename).replace("\\", "/")

            destination = destination.replace(temp_path, output_path)

            if not os.path.exists(os.path.dirname(destination)):
                os.makedirs(os.path.dirname(destination))

            print("Moving \"{}\" to \"{}\"".format(source, destination))

            shutil.move(source, destination)

    # Clean up.
    print("Cleaning up: {}".format(temp_path))
    shutil.rmtree(temp_path)

    pm.workspace.fileRules["images"] = output_path
Esempio n. 15
0
    def launch(self, *args, **kwargs):
        """launch renderer command
        """
        # do nothing if there is no window (called externally)
        if not self.window:
            return

        # warn the user about the ignore settings
        try:
            dAO = pm.PyNode('defaultArnoldRenderOptions')

            ignore_attrs = [
                'ignoreSubdivision',
                'ignoreDisplacement',
                'ignoreBump',
                'ignoreMotionBlur'
            ]

            attr_values = [dAO.getAttr(attr) for attr in ignore_attrs]

            if any(attr_values):
                msg_text = '<br>'.join(
                    map(
                        lambda x, y: '%s: %s' % (x, y),
                        ignore_attrs,
                        attr_values
                    )
                )

                response = pm.confirmDialog(
                    title='Ignore These Settings?',
                    message='You have ignored:<br><br>%s<br><br><b>Is that ok?</b>' % msg_text,
                    button=['Yes', 'No'],
                    defaultButton='No',
                    cancelButton='No',
                    dismissString='No'
                )

                if response == 'No':
                    return
        except pm.MayaNodeError:
            # no Arnold
            pass

        # check if rendering with persp camera
        try:
            wrong_camera_names = [
                'perspShape',
                'topShape',
                'sideShape',
                'fontShape',

                'persp1Shape',
                'perspShape1',
            ]
            renderable_cameras = [node for node in pm.ls(type='camera') if node.getAttr('renderable')]
            if any(map(lambda x: x.name() in wrong_camera_names, renderable_cameras)):
                response = pm.confirmDialog(
                    title='Rendering with Persp?',
                    message='You are rendering with <b>Persp Camera<b><br><br>Is that ok?</b>',
                    button=['Yes', 'No'],
                    defaultButton='No',
                    cancelButton='No',
                    dismissString='No'
                )

                if response == 'No':
                    return

            if len(renderable_cameras) > 1:
                response = pm.confirmDialog(
                    title='Rendering more than one Camera?',
                    message='You are rendering <b>more than one camera<b><br><br>Is that ok?</b>',
                    button=['Yes', 'No'],
                    defaultButton='No',
                    cancelButton='No',
                    dismissString='No'
                )

                if response == 'No':
                    return

        except pm.MayaNodeError:
            # no default render globals node
            pass

        # get values
        start_frame = pm.intField('cgru_afanasy__start_frame', q=1, v=1)
        end_frame = pm.intField('cgru_afanasy__end_frame', q=1, v=1)
        frames_per_task = \
            pm.intField('cgru_afanasy__frames_per_task', q=1, v=1)
        by_frame = pm.intField('cgru_afanasy__by_frame', q=1, v=1)
        hosts_mask = pm.textField('cgru_afanasy__hosts_mask', q=1, text=True)
        hosts_exclude = pm.textField('cgru_afanasy__hosts_exclude', q=1, text=True)
        separate_layers = \
            pm.checkBox('cgru_afanasy__separate_layers', q=1, v=1)
        pause = pm.checkBox('cgru_afanasy__paused', q=1, v=1)

        # check values
        if start_frame > end_frame:
            temp = end_frame
            end_frame = start_frame
            start_frame = temp

        frames_per_task = max(1, frames_per_task)
        by_frame = max(1, by_frame)

        # store field values
        pm.optionVar['cgru_afanasy__start_frame_ov'] = start_frame
        pm.optionVar['cgru_afanasy__end_frame_ov'] = end_frame
        pm.optionVar['cgru_afanasy__frames_per_task_ov'] = frames_per_task
        pm.optionVar['cgru_afanasy__by_frame_ov'] = by_frame
        pm.optionVar['cgru_afanasy__hosts_mask_ov'] = hosts_mask
        pm.optionVar['cgru_afanasy__hosts_exclude_ov'] = hosts_exclude
        pm.optionVar['cgru_afanasy__separate_layers'] = separate_layers

        # get paths
        scene_name = pm.sceneName()
        datetime = '%s%s' % (
            time.strftime('%y%m%d-%H%M%S-'),
            str(time.time() - int(time.time()))[2:5]
        )

        filename = '%s.%s.mb' % (scene_name, datetime)

        project_path = pm.workspace(q=1, rootDirectory=1)

        outputs = ','.join(
            pm.renderSettings(fullPath=1, firstImageName=1, lastImageName=1)
        )

        job_name = os.path.basename(scene_name)

        logger.debug('%ss %se %sr' % (start_frame, end_frame, by_frame))
        logger.debug('scene        = %s' % scene_name)
        logger.debug('file         = %s' % filename)
        logger.debug('job_name     = %s' % job_name)
        logger.debug('project_path = %s' % project_path)
        logger.debug('outputs      = %s' % outputs)

        if pm.checkBox('cgru_afanasy__close', q=1, v=1):
            pm.deleteUI(self.window)

        cmd_buffer = [
            '"%(filename)s"',
            '%(start)s',
            '%(end)s',
            '-by %(by_frame)s',
            '-hostsmask %(msk)s',
            '-hostsexcl %(exc)s',
            '-fpt %(fpt)s',
            '-name "%(name)s"',
            '-pwd "%(pwd)s"',
            '-proj "%(proj)s"',
            '-images "%(images)s"',
            '-deletescene'
        ]

        kwargs = {
            'filename': filename,
            'start': start_frame,
            'end': end_frame,
            'by_frame': by_frame,
            'msk': hosts_mask,
            'exc': hosts_exclude,
            'fpt': frames_per_task,
            'name': job_name,
            'pwd': project_path,
            'proj': project_path,
            'images': outputs
        }

        drg = pm.PyNode('defaultRenderGlobals')
        render_engine = drg.getAttr('currentRenderer')
        if render_engine == 'mentalRay':
            cmd_buffer.append('-type maya_mental')
        elif render_engine == 'arnold':
            cmd_buffer.append('-type maya_arnold')
            # set the verbosity level to warnin+info
            aro = pm.PyNode('defaultArnoldRenderOptions')
            aro.setAttr('log_verbosity', 1)

        if pause:
            cmd_buffer.append('-pause')

        # set output to console
        dARO = pm.PyNode('defaultArnoldRenderOptions')
        dARO.setAttr("log_to_console", 1)

        # save file
        pm.saveAs(
            filename,
            force=1,
            type='mayaBinary'
        )

        # rename back to original name
        pm.renameFile(scene_name)

        # disable set output to console
        dARO.setAttr("log_to_console", 0)

        cmds = []

        # submit renders
        if separate_layers:
            # render each layer separately
            rlm = pm.PyNode('renderLayerManager')
            layers = [layer for layer in rlm.connections()
                      if layer.renderable.get()]

            for layer in layers:
                layer_name = layer.name()
                kwargs['name'] = '%s:%s' % (job_name, layer_name)

                tmp_cmd_buffer = copy.copy(cmd_buffer)
                tmp_cmd_buffer.append(
                    '-take %s' % layer.name()
                )

                # create one big command
                afjob_cmd = ' '.join([
                    os.environ['CGRU_PYTHONEXE'],
                    '"%s/python/afjob.py"' % os.environ['AF_ROOT'],
                    '%s' % ' '.join(tmp_cmd_buffer) % kwargs
                ])
                cmds.append(afjob_cmd)

        else:
            # create one big command
            afjob_cmd = ' '.join([
                os.environ['CGRU_PYTHONEXE'],
                '%s/python/afjob.py' % os.environ['AF_ROOT'],
                '%s' % ' '.join(cmd_buffer) % kwargs
            ])
            cmds.append(afjob_cmd)

        # call each command separately
        for cmd in cmds:
            print(cmds)

            os.system(cmd)
Esempio n. 16
0
def set_render_settings():

    print "Setting up render"
    pm.renderSettings(camera="dog_lightscamera:camera2")
def set_render_settings():

    print 'Setting up render'
    pm.renderSettings(camera='dog_lightscamera:camera2')
Esempio n. 18
0
	def launch(self, *args, **kwargs):
		"""launch renderer command
		"""
		# do nothing if there is no window (called externally)
		if not self.window:
			return

		# get values
		start_frame = pm.intField('cgru_afanasy__start_frame', q=1, v=1)
		end_frame = pm.intField('cgru_afanasy__end_frame', q=1, v=1)
		frames_per_task = \
			pm.intField('cgru_afanasy__frames_per_task', q=1, v=1)
		by_frame = pm.intField('cgru_afanasy__by_frame', q=1, v=1)
		hosts_mask = pm.textField('cgru_afanasy__hosts_mask', q=1, text=True)
		hosts_exclude = pm.textField('cgru_afanasy__hosts_exclude', q=1, text=True)
		separate_layers = \
			pm.checkBox('cgru_afanasy__separate_layers', q=1, v=1)
		pause = pm.checkBox('cgru_afanasy__paused', q=1, v=1)

		# check values
		if start_frame > end_frame:
			temp = end_frame
			end_frame = start_frame
			start_frame = temp

		frames_per_task = max(1, frames_per_task)
		by_frame = max(1, by_frame)

		# store field values
		pm.optionVar['cgru_afanasy__start_frame_ov'] = start_frame
		pm.optionVar['cgru_afanasy__end_frame_ov'] = end_frame
		pm.optionVar['cgru_afanasy__frames_per_task_ov'] = frames_per_task
		pm.optionVar['cgru_afanasy__by_frame_ov'] = by_frame
		pm.optionVar['cgru_afanasy__hosts_mask_ov'] = hosts_mask
		pm.optionVar['cgru_afanasy__hosts_exclude_ov'] = hosts_exclude
		pm.optionVar['cgru_afanasy__separate_layers'] = separate_layers

		# get paths
		scene_name = pm.sceneName()
		datetime = '%s%s' % (
			time.strftime('%y%m%d-%H%M%S-'),
			str(time.time() - int(time.time()))[2:5]
		)

		filename = '%s.%s.mb' % (scene_name, datetime)

		project_path = pm.workspace(q=1, rootDirectory=1)

		outputs = ','.join(
			pm.renderSettings(fullPath=1, firstImageName=1, lastImageName=1)
		)

		job_name = os.path.basename(scene_name)

		logger.debug('%ss %se %sr' % (start_frame, end_frame, by_frame))
		logger.debug('scene        = %s' % scene_name)
		logger.debug('file         = %s' % filename)
		logger.debug('job_name     = %s' % job_name)
		logger.debug('project_path = %s' % project_path)
		logger.debug('outputs      = %s' % outputs)

		if pm.checkBox('cgru_afanasy__close', q=1, v=1):
			pm.deleteUI(self.window)

		cmd_buffer = [
			'"%(filename)s"',
			'%(start)s',
			'%(end)s',
			'-by %(by_frame)s',
			'-hostsmask %(msk)s',
			'-hostsexcl %(exc)s',
			'-fpt %(fpt)s',
			'-name "%(name)s"',
			'-pwd "%(pwd)s"',
			'-proj "%(proj)s"',
			'-images "%(images)s"',
			'-deletescene'
		]

		kwargs = {
			'filename': filename,
			'start': start_frame,
			'end': end_frame,
			'by_frame': by_frame,
			'msk': hosts_mask,
			'exc': hosts_exclude,
			'fpt': frames_per_task,
			'name': job_name,
			'pwd': project_path,
			'proj': project_path,
			'images': outputs
		}

		drg = pm.PyNode('defaultRenderGlobals')
		render_engine = drg.getAttr('currentRenderer')
		if render_engine == 'mentalRay':
			cmd_buffer.append('-type maya_mental')
		elif render_engine == 'arnold':
			cmd_buffer.append('-type maya_arnold')
			# set the verbosity level to warning+info
			aro = pm.PyNode('defaultArnoldRenderOptions')
			aro.setAttr('log_verbosity', 1)

		if pause:
			cmd_buffer.append('-pause')

		# save file
		pm.saveAs(
			filename,
			force=1,
			type='mayaBinary'
		)

		# rename back to original name
		pm.renameFile(scene_name)

		cmds = []

		# submit renders
		if separate_layers:
			# render each layer separately
			rlm = pm.PyNode('renderLayerManager')
			layers = [layer for layer in rlm.connections()
					  if layer.renderable.get()]

			for layer in layers:
				layer_name = layer.name()
				kwargs['name'] = '%s:%s' % (job_name, layer_name)

				tmp_cmd_buffer = copy.copy(cmd_buffer)
				tmp_cmd_buffer.append(
					'-take %s' % layer.name()
				)

				# create one big command
				afjob_cmd = ' '.join([
					os.environ['CGRU_PYTHONEXE'],
					'"%s/python/afjob.py"' % os.environ['AF_ROOT'],
					'%s' % ' '.join(tmp_cmd_buffer) % kwargs
				])
				cmds.append(afjob_cmd)

		else:
			# create one big command
			afjob_cmd = ' '.join([
				os.environ['CGRU_PYTHONEXE'],
				'%s/python/afjob.py' % os.environ['AF_ROOT'],
				'%s' % ' '.join(cmd_buffer) % kwargs
			])
			cmds.append(afjob_cmd)

		# call each command separately
		for cmd in cmds:
			print(cmds)

			os.system(cmd)
Esempio n. 19
0
def setRenderSettings(_in, _cam):
    cam = _cam
    pm.renderSettings(cam=cam)
Esempio n. 20
0
    def launch(self, *args, **kwargs):
        """launch renderer command
        """
        # do nothing if there is no window (called externally)
        if not self.window:
            return

        # warn the user about the ignore settings
        try:
            dAO = pm.PyNode('defaultArnoldRenderOptions')

            ignore_attrs = [
                'ignoreSubdivision', 'ignoreDisplacement', 'ignoreBump',
                'ignoreMotionBlur'
            ]

            attr_values = [(attr, dAO.getAttr(attr)) for attr in ignore_attrs
                           if dAO.getAttr(attr) is True]

            if any(attr_values):
                msg_text = '<br>'.join(
                    map(lambda x: '%s: %s' % (x[0], x[1]), attr_values))

                response = pm.confirmDialog(
                    title='Ignore These Settings?',
                    message=
                    'You have ignored:<br><br>%s<br><br><b>Is that ok?</b>' %
                    msg_text,
                    button=['Yes', 'No'],
                    defaultButton='No',
                    cancelButton='No',
                    dismissString='No')

                if response == 'No':
                    return
        except pm.MayaNodeError:
            # no Arnold
            pass

        # check if rendering with persp camera
        try:
            wrong_camera_names = [
                'perspShape',
                'topShape',
                'sideShape',
                'fontShape',
                'persp1Shape',
                'perspShape1',
            ]
            renderable_cameras = [
                node for node in pm.ls(type='camera')
                if node.getAttr('renderable')
            ]
            if any(
                    map(lambda x: x.name() in wrong_camera_names,
                        renderable_cameras)):
                response = pm.confirmDialog(
                    title='Rendering with Persp?',
                    message=
                    'You are rendering with <b>Persp Camera<b><br><br>Is that ok?</b>',
                    button=['Yes', 'No'],
                    defaultButton='No',
                    cancelButton='No',
                    dismissString='No')

                if response == 'No':
                    return

            if len(renderable_cameras) > 1:
                response = pm.confirmDialog(
                    title='Rendering more than one Camera?',
                    message=
                    'You are rendering <b>more than one camera<b><br><br>Is that ok?</b>',
                    button=['Yes', 'No'],
                    defaultButton='No',
                    cancelButton='No',
                    dismissString='No')

                if response == 'No':
                    return
            elif len(renderable_cameras) == 0:
                pm.confirmDialog(
                    title='No <b>Renderable</b> camera!!!',
                    message='There is no <b>renderable camera<b>!!!',
                    button=['Ok'],
                    defaultButton='Ok',
                    cancelButton='Ok',
                    dismissString='Ok')
                return

        except pm.MayaNodeError:
            # no default render globals node
            pass

        # get values
        start_frame = pm.intField('cgru_afanasy__start_frame', q=1, v=1)
        end_frame = pm.intField('cgru_afanasy__end_frame', q=1, v=1)
        frames_per_task = \
            pm.intField('cgru_afanasy__frames_per_task', q=1, v=1)
        by_frame = pm.intField('cgru_afanasy__by_frame', q=1, v=1)
        hosts_mask = pm.textField('cgru_afanasy__hosts_mask', q=1, text=True)
        hosts_exclude = pm.textField('cgru_afanasy__hosts_exclude',
                                     q=1,
                                     text=True)
        separate_layers = \
            pm.checkBox('cgru_afanasy__separate_layers', q=1, v=1)
        pause = pm.checkBox('cgru_afanasy__paused', q=1, v=1)
        life_time = pm.intField('cgru_afanasy__life_time', q=1, v=1)

        # check values
        if start_frame > end_frame:
            temp = end_frame
            end_frame = start_frame
            start_frame = temp

        frames_per_task = max(1, frames_per_task)
        by_frame = max(1, by_frame)

        # store without quota sign
        hosts_mask = hosts_mask.replace('"', '')
        hosts_exclude = hosts_exclude.replace('"', '')

        # store field values
        pm.optionVar['cgru_afanasy__start_frame_ov'] = start_frame
        pm.optionVar['cgru_afanasy__end_frame_ov'] = end_frame
        pm.optionVar['cgru_afanasy__frames_per_task_ov'] = frames_per_task
        pm.optionVar['cgru_afanasy__by_frame_ov'] = by_frame
        pm.optionVar['cgru_afanasy__hosts_mask_ov'] = hosts_mask
        pm.optionVar['cgru_afanasy__hosts_exclude_ov'] = hosts_exclude
        pm.optionVar['cgru_afanasy__separate_layers_ov'] = separate_layers
        pm.optionVar['cgru_afanasy__life_time_ov'] = life_time

        # get paths
        scene_name = pm.sceneName()
        datetime = '%s%s' % (time.strftime('%y%m%d-%H%M%S-'),
                             str(time.time() - int(time.time()))[2:5])

        filename = '%s.%s.mb' % (scene_name, datetime)

        project_path = pm.workspace(q=1, rootDirectory=1)

        # get output paths, set the RenderPass token to Beauty,
        # this will at least guarantee to get something
        outputs = \
            pm.renderSettings(
                fullPath=1, firstImageName=1, lastImageName=1,
                leaveUnmatchedTokens=1, customTokenString="RenderPass=Beauty"
            )

        job_name = os.path.basename(scene_name)

        logger.debug('%ss %se %sr' % (start_frame, end_frame, by_frame))
        logger.debug('scene        = %s' % scene_name)
        logger.debug('file         = %s' % filename)
        logger.debug('job_name     = %s' % job_name)
        logger.debug('project_path = %s' % project_path)
        logger.debug('outputs      = %s' % outputs)

        if pm.checkBox('cgru_afanasy__close', q=1, v=1):
            pm.deleteUI(self.window)

        drg = pm.PyNode('defaultRenderGlobals')
        render_engine = drg.getAttr('currentRenderer')

        job = af.Job(job_name)

        stored_log_level = None
        if render_engine == 'arnold':
            # set the verbosity level to warning+info
            aro = pm.PyNode('defaultArnoldRenderOptions')
            stored_log_level = aro.getAttr('log_verbosity')
            aro.setAttr('log_verbosity', 1)
            # set output to console
            aro.setAttr("log_to_console", 1)
        elif render_engine == 'redshift':
            # set the verbosity level to detailed+info
            redshift = pm.PyNode('redshiftOptions')
            stored_log_level = redshift.logLevel.get()
            redshift.logLevel.set(2)

        # save file
        pm.saveAs(filename, force=1, type='mayaBinary')

        # rename back to original name
        pm.renameFile(scene_name)

        # create the render command
        mrc = MayaRenderCommandBuilder(name=job_name,
                                       file_full_path=filename,
                                       render_engine=render_engine,
                                       project=project_path,
                                       by_frame=by_frame)

        # submit renders
        blocks = []
        if separate_layers:
            # render each layer separately
            rlm = pm.PyNode('renderLayerManager')
            layers = [
                layer for layer in rlm.connections() if layer.renderable.get()
            ]

            for layer in layers:
                mrc_layer = copy.copy(mrc)
                layer_name = layer.name()
                mrc_layer.name = layer_name
                mrc_layer.render_layer = layer_name

                # create a new block for this layer
                block = af.Block(
                    layer_name,
                    renderer_to_block_type.get(render_engine, 'maya'))

                block.setFiles(
                    afcommon.patternFromDigits(
                        afcommon.patternFromStdC(
                            afcommon.patternFromPaths(outputs[0],
                                                      outputs[1]))).split(';'))
                block.setNumeric(start_frame, end_frame, frames_per_task,
                                 by_frame)
                block.setCommand(mrc_layer.build_command())

                blocks.append(block)
        else:
            # create only one block
            block = af.Block('All Layers',
                             renderer_to_block_type.get(render_engine, 'maya'))

            block.setFiles(
                afcommon.patternFromDigits(
                    afcommon.patternFromStdC(
                        afcommon.patternFromPaths(outputs[0],
                                                  outputs[1]))).split(';'))
            block.setNumeric(start_frame, end_frame, frames_per_task, by_frame)
            block.setCommand(mrc.build_command())

            blocks.append(block)

        job.setFolder('input', os.path.dirname(filename))
        job.setFolder('output', os.path.dirname(outputs[0]))
        job.setHostsMask(hosts_mask)
        job.setHostsMaskExclude(hosts_exclude)
        if life_time > 0:
            job.setTimeLife(life_time * 3600)

        job.setCmdPost('deletefiles "%s"' % os.path.abspath(filename))
        if pause:
            job.offline()

        # add blocks
        job.blocks.extend(blocks)

        status, data = job.send()
        if not status:
            pm.PopupError('Something went wrong!')
        print('data: %s' % data)

        # restore log level
        if render_engine == 'arnold':
            aro = pm.PyNode('defaultArnoldRenderOptions')
            aro.setAttr('log_verbosity', stored_log_level)
            # disable set output to console
            aro.setAttr("log_to_console", 0)
        elif render_engine == 'redshift':
            redshift = pm.PyNode('redshiftOptions')
            redshift.logLevel.set(stored_log_level)
Esempio n. 21
0
def get_render_path():
    return pm.renderSettings(fp=1, fin=1)[0]
    def process(self, context):
        import os

        import clique

        import pymel.core as pm

        # Collect sets named starting with "remote".
        remote_members = []
        for object_set in pm.ls(type="objectSet"):

            if object_set.name().lower().startswith("remote"):
                remote_members.extend(object_set.members())

        # Getting render layers data.
        data = {}
        render_cams = []
        drg = pm.PyNode("defaultRenderGlobals")
        for layer in pm.ls(type="renderLayer"):

            # skipping defaultRenderLayers
            if layer.name().endswith("defaultRenderLayer"):
                continue

            layer_data = {}
            render_cams = []
            if layer.adjustments.get(multiIndices=True):
                for count in layer.adjustments.get(multiIndices=True):
                    if not layer.adjustments[count].plug.connections():
                        continue

                    if layer.adjustments[count].plug.connections()[0] == drg:
                        attr = layer.adjustments[count].plug
                        attr = attr.connections(plugs=True)[0]
                        layer_value = layer.adjustments[count].value.get()
                        layer_data[attr.name(includeNode=False)] = layer_value

                    plug = layer.adjustments[count].plug
                    for cam_attr in plug.connections(plugs=True,
                                                     type="camera"):
                        renderable = cam_attr.endswith("renderable")
                        layer_value = layer.adjustments[count].value.get()
                        if renderable and layer_value == 1.0:
                            name = cam_attr.split(".")[0]
                            render_cams.append(pm.PyNode(name))

                render_pass = layer.connections(type="renderPass")
                layer_data["renderpasses"] = render_pass
            else:
                render_pass = layer.connections(type="renderPass")
                layer_data["renderpasses"] = render_pass

            layer_data["cameras"] = render_cams
            data[layer.name()] = layer_data

        # Create instances
        for layer in data:

            node = pm.PyNode(layer)

            # Checking instance type.
            instance_type = "local"
            if node in remote_members:
                instance_type = "remote"

            instance = context.create_instance(name=layer)
            instance.data["families"] = ["renderlayer", instance_type, "img"]
            instance.data["family"] = "img"

            instance.data.update(data[layer])
            instance.add(node)

            publish_state = pm.PyNode(layer).renderable.get()
            instance.data["publish"] = publish_state

            label = "{0} - renderlayer - {1}".format(layer, instance_type)
            instance.data["label"] = label

            # Generate collection
            first_image, last_image = pm.renderSettings(
                firstImageName=True,
                lastImageName=True,
                fullPath=True,
                layer=layer
            )

            # Special case for vray that has it own extention setting
            renderer = drg.currentRenderer.get()

            if "currentRenderer" in data[layer]:
                renderer = data[layer]["currentRenderer"]

            if renderer == "vray":
                render_settings = pm.PyNode("vraySettings")

                # Assuming ".png" if nothing is set.
                # This happens when vray is initialized with the scene.
                ext = ".png"
                if render_settings.imageFormatStr.get():
                    ext = "."
                    ext += render_settings.imageFormatStr.get().split(" ")[0]

                first_image = os.path.splitext(first_image)[0] + ext

            # Adding renderer as family
            instance.data["families"] += [renderer]
            instance.data["renderer"] = renderer

            # Adding collection
            collections = clique.assemble([first_image], minimum_items=1)[0]
            ext = os.path.splitext(first_image)[1]
            collection = collections[0]
            for col in collections:
                if col.tail == ext:
                    collection = col

            render_globals = pm.PyNode("defaultRenderGlobals")
            start_frame = int(render_globals.startFrame.get())
            end_frame = int(render_globals.endFrame.get())
            step_frame = int(render_globals.byFrameStep.get())

            framerate = context.data["framerate"]
            if "endFrame" in data[layer]:
                end_frame = int(data[layer]["endFrame"] * framerate)
            if "startFrame" in data[layer]:
                start_frame = int(data[layer]["startFrame"] * framerate)

            fmt = collection.format("{head}{padding}{tail}")
            for count in range(start_frame, end_frame + 1, step_frame):
                f = fmt % count
                collection.add(f)

            instance.data["endFrame"] = end_frame
            instance.data["startFrame"] = start_frame
            instance.data["stepFrame"] = step_frame
            instance.data["collection"] = collection

            def instance_toggled(instance, value):
                instance[0].renderable.set(value)
            instance.data["instanceToggled"] = instance_toggled
Esempio n. 23
0
    def launch(self, *args, **kwargs):
        """launch renderer command
        """
        # do nothing if there is no window (called externally)
        if not self.window:
            return

        # warn the user about the ignore settings
        try:
            dAO = pm.PyNode('defaultArnoldRenderOptions')

            ignore_attrs = [
                'ignoreSubdivision',
                'ignoreDisplacement',
                'ignoreBump',
                'ignoreMotionBlur'
            ]

            attr_values = [
                (attr, dAO.getAttr(attr))
                for attr in ignore_attrs
                if dAO.getAttr(attr) is True
            ]

            if any(attr_values):
                msg_text = '<br>'.join(
                    map(
                        lambda x: '%s: %s' % (x[0], x[1]),
                        attr_values
                    )
                )

                response = pm.confirmDialog(
                    title='Ignore These Settings?',
                    message='You have ignored:<br><br>%s<br><br><b>Is that ok?</b>' % msg_text,
                    button=['Yes', 'No'],
                    defaultButton='No',
                    cancelButton='No',
                    dismissString='No'
                )

                if response == 'No':
                    return
        except pm.MayaNodeError:
            # no Arnold
            pass

        # check if rendering with persp camera
        try:
            wrong_camera_names = [
                'perspShape',
                'topShape',
                'sideShape',
                'fontShape',

                'persp1Shape',
                'perspShape1',
            ]
            renderable_cameras = [node for node in pm.ls(type='camera') if node.getAttr('renderable')]
            if any(map(lambda x: x.name() in wrong_camera_names, renderable_cameras)):
                response = pm.confirmDialog(
                    title='Rendering with Persp?',
                    message='You are rendering with <b>Persp Camera<b><br><br>Is that ok?</b>',
                    button=['Yes', 'No'],
                    defaultButton='No',
                    cancelButton='No',
                    dismissString='No'
                )

                if response == 'No':
                    return

            if len(renderable_cameras) > 1:
                response = pm.confirmDialog(
                    title='Rendering more than one Camera?',
                    message='You are rendering <b>more than one camera<b><br><br>Is that ok?</b>',
                    button=['Yes', 'No'],
                    defaultButton='No',
                    cancelButton='No',
                    dismissString='No'
                )

                if response == 'No':
                    return
            elif len(renderable_cameras) == 0:
                pm.confirmDialog(
                    title='No <b>Renderable</b> camera!!!',
                    message='There is no <b>renderable camera<b>!!!',
                    button=['Ok'],
                    defaultButton='Ok',
                    cancelButton='Ok',
                    dismissString='Ok'
                )
                return

        except pm.MayaNodeError:
            # no default render globals node
            pass

        drg = pm.PyNode('defaultRenderGlobals')
        render_engine = drg.getAttr('currentRenderer')
        # RENDERER SPECIFIC CHECKS

        if render_engine == 'redshift':
            # if the renderer is RedShift
            # check if unifiedDisableDivision is 1 which will take too much time
            # to render
            dro = pm.PyNode('redshiftOptions')
            if dro.unifiedDisableDivision.get() == 1:
                response = pm.confirmDialog(
                    title="Enabled **Don't Automatically Reduce Samples of Other Effects**",
                    message='It is not allowed to render with the following option is enabled:<br>'
                            '<br>'
                            "Don't Automatically Reduce Samples of Other Effects: Enabled<br>"
                            "<br>"
                            "Please DISABLE it!",
                    button=['OK'],
                    defaultButton='OK',
                    cancelButton='OK',
                    dismissString='OK'
                )
                return

            # Check dome light backgrounds
            domes_to_fix = []
            rs_domes = pm.ls(type='RedshiftDomeLight')
            if rs_domes:
                for rs_dome in rs_domes:
                    if rs_dome.getAttr('background_enable') == 1 \
                       or rs_dome.getAttr('backPlateEnabled') == 1:
                        domes_to_fix.append(rs_dome.name())

            if domes_to_fix:
                message = 'Some DomeLights have <b>BackGround Render ' \
                          'Enabled</b>:' \
                          '<br><br>%s<br><br>' \
                          'Are you Sure?' % '<br>'.join(domes_to_fix)

                response = pm.confirmDialog(
                    title='Dome Lights with Background Enabled?',
                    message=message,
                    button=['Yes', 'No'],
                    defaultButton='No',
                    cancelButton='No',
                    dismissString='No'
                )
                if response == 'No':
                    return

            # abort on license fail
            dro.abortOnLicenseFail.set(1)

        elif render_engine == 'arnold':
            # check if the samples are too high
            dAO = pm.PyNode('defaultArnoldRenderOptions')

            aa_samples = dAO.AASamples.get()
            diff_samples = dAO.GIDiffuseSamples.get()
            try:
                glossy_samples = dAO.GIGlossySamples.get()
            except AttributeError:
                glossy_samples = dAO.GISpecularSamples.get()
            if int(pm.about(v=1)) >= 2017:
                sss_samples = dAO.GISssSamples.get()
            else:
                sss_samples = dAO.sssBssrdfSamples.get()

            total_diff_samples = aa_samples**2 * diff_samples**2
            total_glossy_samples = aa_samples**2 * glossy_samples**2
            total_sss_samples = aa_samples**2 * sss_samples**2

            max_allowed_diff_samples = 225
            max_allowed_glossy_samples = 100
            max_allowed_sss_samples = 800

            if total_diff_samples > max_allowed_diff_samples:
                pm.confirmDialog(
                    title="Too Much Diffuse Samples!!!",
                    message='You are using too much DIFFUSE SAMPLES (>%s)<br>'
                            '<br>'
                            'Please either reduce AA samples of Diffuse '
                            'Samples!!!' % max_allowed_diff_samples,
                    button=['OK'],
                    defaultButton='OK',
                    cancelButton='OK',
                    dismissString='OK'
                )
                return

            if total_glossy_samples > max_allowed_glossy_samples:
                pm.confirmDialog(
                    title="Too Much Glossy Samples!!!",
                    message='You are using too much GLOSSY SAMPLES (>%s)<br>'
                            '<br>'
                            'Please either reduce AA samples of Glossy '
                            'Samples!!!' % max_allowed_glossy_samples,
                    button=['OK'],
                    defaultButton='OK',
                    cancelButton='OK',
                    dismissString='OK'
                )
                return

            if total_sss_samples > max_allowed_sss_samples:
                pm.confirmDialog(
                    title="Too Much SSS Samples!!!",
                    message='You are using too much SSS SAMPLES (>%s)<br>'
                            '<br>'
                            'Please either reduce AA samples of SSS '
                            'Samples!!!' % max_allowed_sss_samples,
                    button=['OK'],
                    defaultButton='OK',
                    cancelButton='OK',
                    dismissString='OK'
                )
                return

            # check Light Samples
            # check point lights with zero radius but more than one samples
            all_point_lights = pm.ls(type='pointLight')
            ridiculous_point_lights = []
            for point_light in all_point_lights:
                if point_light.aiRadius.get() < 0.1 and point_light.aiSamples.get() > 1:
                    ridiculous_point_lights.append(point_light)

            if ridiculous_point_lights:
                pm.confirmDialog(
                    title="Unnecessary Samples on Point Lights!!!",
                    message='You are using too much SAMPLES (>1)<br>'
                            '<br>'
                            'on <b>Point lights with zero radius</b><br>'
                            '<br>'
                            'Please reduce the samples to 1',
                    button=['OK'],
                    defaultButton='OK',
                    cancelButton='OK',
                    dismissString='OK'
                )
                return

            # Check area lights with more than 2 samples
            all_area_lights = pm.ls(type=['areaLight', 'aiAreaLight'])
            ridiculous_area_lights = []
            for area_light in all_area_lights:
                if area_light.aiSamples.get() > 2:
                    ridiculous_area_lights.append(area_light)

            if ridiculous_area_lights:
                pm.confirmDialog(
                    title="Unnecessary Samples on Area Lights!!!",
                    message='You are using too much SAMPLES (>2) on<br>'
                            '<br>'
                            '<b>Area Lights</b><br>'
                            '<br>'
                            'Please reduce the samples to 2',
                    button=['OK'],
                    defaultButton='OK',
                    cancelButton='OK',
                    dismissString='OK'
                )
                return

            # Check directional lights with angle == 0 and samples > 1
            all_directional_lights = pm.ls(type='directionalLight')
            ridiculous_directional_lights = []
            dir_sample_attr_name = 'aiSamples'
            # if pm.about(v=1) == "2014":
            #     dir_sample_attr_name = 'aiSamples'

            for directional_light in all_directional_lights:
                if directional_light.aiAngle.get() == 0 and directional_light.attr(dir_sample_attr_name).get() > 1:
                    ridiculous_directional_lights.append(directional_light)

            if ridiculous_directional_lights:
                pm.confirmDialog(
                    title="Unnecessary Samples on Directional Lights!!!",
                    message='You are using too much SAMPLES (>1) on <br>'
                            '<br>'
                            '<b>Directional lights with zero angle</b><br>'
                            '<br>'
                            'Please reduce the samples to 1',
                    button=['OK'],
                    defaultButton='OK',
                    cancelButton='OK',
                    dismissString='OK'
                )
                return

        # get values
        start_frame = pm.intField('cgru_afanasy__start_frame', q=1, v=1)
        end_frame = pm.intField('cgru_afanasy__end_frame', q=1, v=1)
        frames_per_task = \
            pm.intField('cgru_afanasy__frames_per_task', q=1, v=1)
        by_frame = pm.intField('cgru_afanasy__by_frame', q=1, v=1)
        hosts_mask = pm.textField('cgru_afanasy__hosts_mask', q=1, text=True)
        hosts_exclude = pm.textField('cgru_afanasy__hosts_exclude', q=1, text=True)
        separate_layers = \
            pm.radioButtonGrp('cgru_afanasy__separate_layers', q=1, sl=1)
        pause = pm.checkBox('cgru_afanasy__paused', q=1, v=1)
        life_time = pm.intField('cgru_afanasy__life_time', q=1, v=1)
        annotation = pm.textField('cgru_afanasy__annotation', q=1, text=True)
        submit_multiple_times = pm.intField('cgru_afanasy__submit_multiple_times', q=1, v=1)
        errors_avoid_host = pm.intField('cgru_afanasy__errors_avoid_host', q=1, v=1)
        errors_retries = pm.intField('cgru_afanasy__errors_retries', q=1, v=1)
        errors_task_same_host = pm.intField('cgru_afanasy__errors_task_same_host', q=1, v=1)
        errors_forgive_time = pm.intField('cgru_afanasy__errors_forgive_time', q=1, v=1)

        # check values
        if start_frame > end_frame:
            temp = end_frame
            end_frame = start_frame
            start_frame = temp

        frames_per_task = max(1, frames_per_task)
        by_frame = max(1, by_frame)

        # store without quota sign
        hosts_mask = hosts_mask.replace('"', '')
        hosts_exclude = hosts_exclude.replace('"', '')

        # store field values
        pm.optionVar['cgru_afanasy__start_frame_ov'] = start_frame
        pm.optionVar['cgru_afanasy__end_frame_ov'] = end_frame
        pm.optionVar['cgru_afanasy__frames_per_task_ov'] = frames_per_task
        pm.optionVar['cgru_afanasy__by_frame_ov'] = by_frame
        pm.optionVar['cgru_afanasy__hosts_mask_ov'] = hosts_mask
        pm.optionVar['cgru_afanasy__hosts_exclude_ov'] = hosts_exclude
        pm.optionVar['cgru_afanasy__separate_layers_ov'] = separate_layers
        pm.optionVar['cgru_afanasy__life_time_ov'] = life_time
        pm.optionVar['cgru_afanasy__annotation_ov'] = annotation

        pm.optionVar['cgru_afanasy__submit_multiple_times_ov'] = submit_multiple_times
        pm.optionVar['cgru_afanasy__errors_avoid_host_ov'] = errors_avoid_host
        pm.optionVar['cgru_afanasy__errors_retries_ov'] = errors_retries
        pm.optionVar['cgru_afanasy__errors_task_same_host_ov'] = errors_task_same_host
        pm.optionVar['cgru_afanasy__errors_errors_forgive_time_ov'] = errors_forgive_time

        # get paths
        scene_name = pm.sceneName()
        datetime = '%s%s' % (
            time.strftime('%y%m%d-%H%M%S-'),
            str(time.time() - int(time.time()))[2:5]
        )

        filename = '%s.%s.mb' % (scene_name, datetime)

        project_path = pm.workspace(q=1, rootDirectory=1)

        # outputs = \
        #     pm.renderSettings(fullPath=1, firstImageName=1, lastImageName=1)

        # get output paths, set the RenderPass token to Beauty,
        # this will at least guarantee to get something
        outputs = \
            pm.renderSettings(
                fullPath=1, firstImageName=1, lastImageName=1,
                leaveUnmatchedTokens=1, customTokenString="RenderPass=Beauty"
            )

        # job_name = os.path.basename(scene_name)
        job_name = self.generate_job_name()

        logger.debug('%ss %se %sr' % (start_frame, end_frame, by_frame))
        logger.debug('scene                 = %s' % scene_name)
        logger.debug('file                  = %s' % filename)
        logger.debug('job_name              = %s' % job_name)
        logger.debug('project_path          = %s' % project_path)
        logger.debug('outputs               = %s' % outputs)
        logger.debug('annotation            = %s' % annotation)
        logger.debug('separate_layers       = %s' % separate_layers)
        logger.debug('errors_avoid_host     = %s' % errors_avoid_host)
        logger.debug('errors_retries        = %s' % errors_retries)
        logger.debug('errors_task_same_host = %s' % errors_task_same_host)
        logger.debug('errors_forgive_time   = %s' % errors_forgive_time)

        if pm.checkBox('cgru_afanasy__close', q=1, v=1):
            pm.deleteUI(self.window)

        stored_log_level = None
        if render_engine == 'arnold':
            # set the verbosity level to warning+info
            aro = pm.PyNode('defaultArnoldRenderOptions')
            stored_log_level = aro.getAttr('log_verbosity')
            aro.setAttr('log_verbosity', 2)
            # set output to console
            aro.setAttr("log_to_console", 1)
        elif render_engine == 'redshift':
            # set the verbosity level to detailed+info
            redshift = pm.PyNode('redshiftOptions')
            stored_log_level = redshift.logLevel.get()
            redshift.logLevel.set(2)

        # save file
        pm.saveAs(
            filename,
            force=1,
            type='mayaBinary'
        )

        # rename back to original name
        pm.renameFile(scene_name)

        # create the render command
        mrc = MayaRenderCommandBuilder(
            name=job_name,
            file_full_path=filename,
            render_engine=render_engine,
            project=project_path,
            by_frame=by_frame
        )

        # submit renders
        jobs = []
        blocks = []

        #
        # separate_layers:
        # 1 -> None  -> submit one job with a single block with all layers
        # 2 -> Block -> submit one job with multiple blocks
        # 3 -> Job   -> submit multiple jobs with a single block per layer
        #
        if separate_layers in [1, 2]:
            job = af.Job(job_name)
            jobs.append(job)

        if separate_layers in [2, 3]:
            # render each layer separately
            rlm = pm.PyNode('renderLayerManager')
            layers = [layer for layer in rlm.connections()
                      if layer.renderable.get()]

            for layer in layers:
                mrc_layer = copy.copy(mrc)
                layer_name = layer.name()
                mrc_layer.name = layer_name
                mrc_layer.render_layer = layer_name

                # create a new block for this layer
                block = af.Block(
                    layer_name,
                    renderer_to_block_type.get(render_engine, 'maya')
                )

                # Fix the output path for this layer
                # by replacing the "masterLayer" with the layer name
                # without rs_ at the beginning
                layer_outputs = outputs
                if layer_name != 'defaultRenderLayer':
                    layer_outputs[0] = outputs[0].replace(
                        'masterLayer',
                        layer_name.replace('rs_', '')
                    )
                    layer_outputs[1] = outputs[1].replace(
                        'masterLayer',
                        layer_name.replace('rs_', '')
                    )

                outputs_split = afcommon.patternFromDigits(
                    afcommon.patternFromStdC(
                        afcommon.patternFromPaths(
                            layer_outputs[0],
                            layer_outputs[1]
                        )
                    )
                ).split(';')

                block.setFiles(outputs_split)

                block.setNumeric(
                    start_frame, end_frame, frames_per_task, by_frame
                )
                command = mrc_layer.build_command()

                block.setErrorsAvoidHost(errors_avoid_host)
                block.setErrorsRetries(errors_retries)
                block.setErrorsTaskSameHost(errors_task_same_host)
                block.setErrorsForgiveTime(errors_forgive_time)

                block.setCommand(command)

                if separate_layers == 2:
                    blocks.append(block)
                else:
                    job = af.Job('%s - %s' % (job_name, layer_name))
                    # add blocks
                    job.blocks = [block]
                    jobs.append(job)

        else:
            # create only one block
            block = af.Block(
                'All Layers',
                renderer_to_block_type.get(render_engine, 'maya')
            )

            block.setFiles(
                afcommon.patternFromDigits(
                    afcommon.patternFromStdC(
                        afcommon.patternFromPaths(outputs[0], outputs[1])
                    )
                ).split(';')
            )
            block.setNumeric(
                start_frame, end_frame, frames_per_task, by_frame
            )
            command = mrc.build_command()
            block.setCommand(command)

            blocks.append(block)

        for job in jobs:
            job.setAnnotation(annotation)
            job.setFolder('input', os.path.dirname(filename))
            job.setFolder('output', os.path.dirname(outputs[0]))
            job.setHostsMask(hosts_mask)
            job.setHostsMaskExclude(hosts_exclude)
            if life_time > 0:
                job.setTimeLife(life_time * 3600)
            else:
                job.setTimeLife(240 * 3600)

            job.setCmdPost('deletefiles -s "%s"' % os.path.abspath(filename))
            if pause:
                job.offline()

            # add blocks
            if separate_layers in [1, 2]:
                job.blocks.extend(blocks)

            for i in range(submit_multiple_times):
                orig_job_name = job.data['name']
                job.setName('%s - %03i' % (orig_job_name, i + 1))
                status, data = job.send()

                # restore job name
                job.setName(orig_job_name)
                if not status:
                    pm.PopupError('Something went wrong!')

        # restore log level
        if render_engine == 'arnold':
            aro = pm.PyNode('defaultArnoldRenderOptions')
            aro.setAttr('log_verbosity', stored_log_level)
            # disable set output to console
            aro.setAttr("log_to_console", 0)
        elif render_engine == 'redshift':
            redshift = pm.PyNode('redshiftOptions')
            redshift.logLevel.set(stored_log_level)

            # disable abort on license fail
            redshift.abortOnLicenseFail.set(0)