-1
$\begingroup$

I'm wondering if there is a way, I'm guessing a little python script, to get the image editor to open a random image from a folder on my drive. I saw a similar thread, but it wasn't about opening one random image.

I'm on mac if that is of any interest.

$\endgroup$

2 Answers 2

1
$\begingroup$

os.listdir() will give you a list of the files in a directory.

random.choice() will pick a random item in a list.

Once you have the random file name you can then open it in the UV/Image Editor.

import bpy, random, os

imgdir = '/path/to/images'

imgfile = random.choice(os.listdir(imgdir))

bpy.ops.image.open(filepath=os.path.join(imgdir, imgfile))

new_image = bpy.data.images[imgfile]

# show the new image in the image editor
for area in bpy.context.screen.areas :
    if area.type == 'IMAGE_EDITOR' :
            area.spaces.active.image = new_image
$\endgroup$
0
0
$\begingroup$

Wait so do you mean like open a random texture for a game? Well you would have to make a random sensor (switch it to int uniform) and then make the min 1, and the max however many pictures you have. Then add a property sensor that is equals to 1, 2 3 and so on so that you have lots of equals sensors. They all each make a picture get added in. I know this isn't from a drive, but for a drive it wouldn't really work because it would have to make a new UV map and a new material for every time you wanted a texture and that simply isn't something blender can do on its own from what I have heard. Their might be a way, but I certainly don't know about it.

$\endgroup$
1
  • $\begingroup$ This is kind of an example of what I mean, but instead of adding chunks of city on multiple empties, it adds a random texture on a single empty. youtube.com/watch?v=YcUj_yaYkeY $\endgroup$
    – user37321
    Mar 25, 2017 at 20:16

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.