1. I have a displacement modifier applied on the object.
  2. Image files were put into a sub-folder.
  3. I wanted to use script to search the sub-folder, replace the image(used by displacement modifier) and export it to stl each.

Currently i only got the exporting part working.

However I do not know how to get blender to:

a) search a folder, get the image files

b) replace it into current modifier

c) export and repeat a) until there's no file

Progress so far:

import bpy
import os

# get the current path and make a new folder for the exported meshes
path = bpy.path.abspath('//stl/')

if not os.path.exists(path):

# deselect all meshes

# select the object
#object.select = True
object = bpy.data.objects['pboard']
object.hide_select = False
object.select = True
bpy.context.scene.objects.active = object

# export object with its name as file name
fPath = str((path + object.name + '.stl'))

#bpy.context.active_object = object
bpy.ops.export_mesh.stl(filepath=fPath, use_selection=True)

object.hide_select = True

P.S. the way how scripting blender to work with file and directories, is it the same as typical python? just so I know how to broaden my search when i walk into problems.

  • $\begingroup$ Yes it works like typical python (it is python with a module). You can look into "images = os.listdir("path/to/images")" which returns the contents of a a directory as list of images. Then this blender.stackexchange.com/a/43348/245. and something like bpy.context.object.modifiers["Displace"].texture = bpy.data.textures['Tex'] $\endgroup$ – miceterminator Jun 18 '19 at 6:53

Your Answer

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

Browse other questions tagged or ask your own question.