Specific Render Location

Specific Render Location

gerard8H4HH
Explorer Explorer
581 Views
6 Replies
Message 1 of 7

Specific Render Location

gerard8H4HH
Explorer
Explorer

Hi everyone,

 

Is there any way to give Maya this render location:

1. Go one or two levels up from the project.

2. Find/Create a folder called RENDER

3. In that folder find/create a folder called whatever the name of the scene is and use that as your render output.

 

Not sure if this would be too tricky to do. Thanks in advance!

582 Views
6 Replies
Replies (6)
Message 2 of 7

Kahylan
Advisor
Advisor

Hi!

 

What you want to do is doable. But you have to keep in mind, that to render to a custom location, you need to change that location in the workspace file. So you should probably change it back once your rendering is finished. Atleast if you want to publish your script. Because users aren't to happy if you mess with their default settings.

As for the "find/create" part with  your folders, most renderers will per default create file structure needed when the path they are supposed to does not exists on the disk, if that isn't the case with the renderer you are intending to use, you would need to add the logic to that in the rendering portion of your script.

Here is how to find the location and set it in the workspace:

import maya.cmds as mc

#get project directory
wp = mc.workspace(q= True, dir = True)
print(wp)
#get directory two steps up
folders = wp.split("/")
folders = folders[1:-3]
wp = ""
for f in folders:
    wp = wp + "/" + f
    
#get file path
fn = mc.file(q= True, sn = True)

#get Scene Name
fn = fn.split("/")[-1]
fn = fn.split(".")[0]

renderpath = "{0}/RENDER/{1}".format(wp,fn)

#get current rendering location
ws = mc.workspace(fr= True, q = True)
i = ws.index('images')
        
cl = ws[i+1]

#set imagepath variable in workspace
mc.workspace(fr = ['images', renderpath])

#enter your rendering code between these lines
#_____________________________________________




#_____________________________________________

#reset imagepath variable to initial
mc.workspace(fr = ['images', cl])

 

I hope it helps!

Message 3 of 7

gerard8H4HH
Explorer
Explorer

Hi Kahylan,

 

Thank you for your reply and for the script, very nice of you! So it would be a matter of simply opening the workspace file of my project and pasting the script as you wrote in here?

 

Would there be any way of making this a Maya default? We use this nomenclature in the entire company and it would b helpful if all Maya projects had this by default.

 

Thanks again!

Message 4 of 7

Kahylan
Advisor
Advisor

This script is meant to be running from the Maya script editor, it will then edit the workspace file by itself.

 

The problem is, that Scenes get renamed a lot (save as, increment save, etc), so wanting to have the Scenename as folder means that this would have to be run right before a scene is rendered:

import maya.cmds as mc

    
#get file path
fn = mc.file(q= True, sn = True)

#get Scene Name
fn = fn.split("/")[-1]
fn = fn.split(".")[0]

renderpath = "../RENDER/{1}".format(fn)

#set imagepath variable in workspace
mc.workspace(fr = ['images', renderpath])

 

I took out everything that changes location back, since this seems to be an inhouse tool. Also I realised that the workspace file allows relative pathing.

 

So if you add this script to a shelf button, that needs to be pressed before rendering, it should work fine.

 

You also could start the render directly in the script, and just make it the "start render" button of your studio.

 

If you want to be more automated, you could also format it in a function and add it to userSetup.py:

def imagePath():   
    #get file path
    fn = mc.file(q= True, sn = True)
    
    #get Scene Name
    fn = fn.split("/")[-1]
    fn = fn.split(".")[0]
    
    renderpath = "../RENDER/{1}".format(fn)
    
    #set imagepath variable in workspace
    mc.workspace(fr = ['images', renderpath])

along with a protected scriptjob that runs this command whenever a file is saved.

 

Now there is also a less hacky way to do this using the interface:

Since the workspace accepts relative pathing you could just change the render image path in File>Project Window to "../Render"

PRWN.png

Sadly I couldn't find a keyword that just grabs the scene name for the workspace pathing. Maybe there is one but I haven't found it yet.

 

But some Renderers like Arnold also allow for relative Pathing, with this and Arnold you could just use the <Scene> keyword in the render Settings.

RS.png

This is ofcourse different from Renderer to Renderer, but if you know if you the Renderer you use allows this, you could also solve it like this.

 

I hope it helps!

0 Likes
Message 5 of 7

gerard8H4HH
Explorer
Explorer

Hi again,

 

Once again, thank you so much for all your help! After trying out a couple of your suggestions I think the easiest one to do would be the ../RENDER and <scene>/<scene> version. Only one extra question: .. will lead you to one folder above your project, is there any way to go two levels above?

0 Likes
Message 6 of 7

Kahylan
Advisor
Advisor

Oh right you wanted to go two steps up, sorry.

 

Change "../Render" to "../../Render".

 

I hope it helps 🙂

Message 7 of 7

gerard8H4HH
Explorer
Explorer

This was tremendously useful! Thank you very much 🙂

0 Likes