4
$\begingroup$

I have a bunch of blend files, each in their own directory with supported files wherever necessary. I want to configure all the blend files to use relative paths. I can open each of them and do File > Externel Data > Make all paths relative. But since I've a lot of blend files, this is time consuming. Is it possible to do this via python script?

$\endgroup$
6
  • $\begingroup$ Are they all in one directory or something? $\endgroup$
    – scurest
    Commented Apr 4, 2021 at 17:35
  • $\begingroup$ No, they're in different directory. But I can run the same python script for each blend file. That, I've got it covered. I need to know how to set this setting via python for a single blend file. $\endgroup$ Commented Apr 4, 2021 at 17:44
  • 1
    $\begingroup$ Have you tried this? docs.blender.org/api/current/… $\endgroup$ Commented Apr 4, 2021 at 17:49
  • $\begingroup$ Thanks! I think that will work. I'll try it. I'm new to blender. How can I search for such things? i.e. how to do some things via python which I know how to do in GUI. I tried looking at blender python documentation, but I couldn't make head or tail out of it $\endgroup$ Commented Apr 4, 2021 at 17:53
  • 2
    $\begingroup$ In Preferences > Interface, turn on Python Tooltips. It will show you what to call in Python in the tooltip when you hover over a button. $\endgroup$
    – scurest
    Commented Apr 4, 2021 at 17:54

1 Answer 1

5
$\begingroup$

This will make all paths relative and then save

import bpy
bpy.ops.file.make_paths_relative()
bpy.ops.wm.save_mainfile()

You can run this from the shell like this. This should make all paths in file.blend relative

blender --background file.blend --python-expr 'import bpy;bpy.ops.file.make_paths_relative();bpy.ops.wm.save_mainfile()'
$\endgroup$

You must log in to answer this question.

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