User choosing own file path

Hi all,

I have a nice small script where there is a file path, the thing is that another user couldn’t access to it since it needs its own computers file path.
Is there a way on the N panel to let the user select its own file path and that being the one read by the script?
I hope it makes sense :slight_smile:

Here is my small script, which works as it should be in my computer.

import bpy
import subprocess
import os


os.chdir("D:\\testfolder")
os.startfile("my_own_batch.bat")

Thanks in advance,
Juan

Blender’s path options are documented here:
https://docs.blender.org/api/current/bpy.path.html

You might also end up using some of the path stuff from the os library.

Here’s an example of an add-on that has a simple N-panel where you can specify the output folder and file name (uncheck the boxes for using the blend file name and directory).

image

Grab version 0.0.4 for the latest. In this case the path is also something that can be set from the add-on preferences but I don’t think that is strictly necessary. Most of the path related stuff takes place between line 60 and 84.

For the N panel add-on panel I set the user input as a string property with a subtype of DIR_PATH. When the subtype is specified Blender automatically gives it the file browser button when added to the panel layout. (Panel layout happens on line 215 to 236.)

Available subtypes are listed here:
https://docs.blender.org/api/current/bpy.props.html#bpy.props.StringProperty

1 Like

Sorry for the very late reply :frowning:
Thank you so much for the detailed explanation I really appreciate it :slight_smile:

I will start digging into it and I will keep you posted.

Cheers,
Juan