0
$\begingroup$

I have a Blender python script in my Blender file

import bpy
print(variable)

and an external .py file in the same directory as the .blend file.

variable = "spam"

I want to import the external file into Blender using a relative path.

$\endgroup$
  • 1
    $\begingroup$ Please add more details to your question, it is currently unclear what you mean. $\endgroup$ – Ray Mairlot Jan 7 '17 at 17:38
2
$\begingroup$

You can append the path to your script

import bpy, sys
sys.path.append('//myscript.py')
import myscript
$\endgroup$
  • $\begingroup$ The second file is not in the blend file but in the same directory as the blend file $\endgroup$ – froggyman Jan 7 '17 at 18:14
  • $\begingroup$ This code is for if the script is in the same directory as the script calling it. Is that not the case? $\endgroup$ – cmomoney Jan 7 '17 at 18:16
  • $\begingroup$ no, because it is in the same directory as the .blend file but not IN the .blend file $\endgroup$ – froggyman Jan 7 '17 at 18:23
  • $\begingroup$ Edited my answer. $\endgroup$ – cmomoney Jan 7 '17 at 19:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.