1
$\begingroup$

Here's the code i have written so far, it's working inside blender text editor. I however like to run this script without opening blender, with command-line, better yet to create a shortcut icon on a PC to run it, hoping to make this friendly and available for people who do not know blender well.

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):
    os.makedirs(path)



# deselect all meshes
bpy.ops.object.select_all(action='DESELECT')

# 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
$\endgroup$
  • $\begingroup$ That all looks good. Have you got permissions to write to the /stl folder? are there any errors reported in the console? can you show the complete command line you are using? $\endgroup$ – rob Jun 6 at 10:50
  • 1
    $\begingroup$ @rob thx i got this running, hv edited the question to focus on the part on how to get this running with the GUI. $\endgroup$ – adrian li Jun 6 at 10:51
0
$\begingroup$

Find the blender.exe and Right Click and select Create Shortcut

create shortcut in windows

Due to permissions I cannot create a shortcut in the Blender folder so it offers to create it on the Desktop.

Find the shortcut and Right Click and select Properties

shortcut properties in windows

In the Target box append

 -b c:\tmp\target.blend --python c:\tmp\exportscript.py

to the fully quoted blender.exe e.g.

"C:\Program Files\Blender Foundation\Blender\blender.exe" -b c:\tmp\target.blend --python c:\tmp\exportscript.py

Where target.blend is the blender file with the "pboard" object to export and exportscript.py is the original posters code with the "path" value set to match your environment.

I created a c:\tmp folder that has full permissions for the blender user and set the path

path = "C:\\tmp\\stl\\"

Now when I double click the shortcut, a command window flashes open briefly before closing. The file C:\tmp\stl\pboard.stl" is then available.

$\endgroup$

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.