3
$\begingroup$

Let say I have blend file called test01.blend, then I want to automatically assign render filepath via python to /media/data/render/[current blend filename]/[current blend filename]_.

So, it should look like this /media/data/render/test01/test01_

I'm trying to access it via bpy.data.filepath, but I got only full file path for current blend file not blend file name.

Thanks for your help

$\endgroup$
1
  • 1
    $\begingroup$ See this post $\endgroup$
    – gandalf3
    Nov 7, 2013 at 9:58

1 Answer 1

5
$\begingroup$

From iKlsR's answer:

You can get the filename with bpy.path.basename(bpy.context.blend_data.filepath). This will return it as a string without the path attached.

You can then assign the render output path with it:

import bpy

filename = bpy.path.basename(bpy.data.filepath)
if filename:
    bpy.context.scene.render.filepath = filename

Note that basename will include the file extension (.blend). You can strip it using os.path.splittext():

import os
import bpy

filename = bpy.path.basename(bpy.data.filepath)
filename = os.path.splitext(filename)[0]

if filename:
    bpy.context.scene.render.filepath = os.path.join("/media/data/render", filename, filename + "_")
$\endgroup$
7
  • 1
    $\begingroup$ is there any difference between bpy.context.blend_data.filepath and bpy.data.filepath? $\endgroup$
    – CodeManX
    Nov 7, 2013 at 10:08
  • $\begingroup$ it'll print .blend also in render filepath, any workaround to solve this? $\endgroup$
    – aditia
    Nov 7, 2013 at 10:08
  • $\begingroup$ @aditia Added a workaround $\endgroup$
    – gandalf3
    Nov 7, 2013 at 10:10
  • $\begingroup$ @CoDEmanX Good question. I don't know, but I don't see any.. (perhaps you should ask it? ;) ) $\endgroup$
    – gandalf3
    Nov 7, 2013 at 10:11
  • 2
    $\begingroup$ maybe make it more generic and use os.path.splitext[0] instead of replace('.blend', '')? $\endgroup$
    – CodeManX
    Nov 7, 2013 at 10:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .