running code as script

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Post Reply
spiritech
Posts: 0
Joined: Sun Mar 21, 2010 6:08 pm
Location: UK

running code as script

Post by spiritech » Tue Sep 18, 2012 5:46 pm

i found these two snippets of code that help me apply all modifiers or a single, specified, modifier on all selected objects. they save me a lot of time when applying modifiers to lots of objects in one go. they work fine in the python console. how do i go about running it as a script.
i tried adding the lines to a text file and using RUN SCRIPT from the text editor and it does not work. do i need to add something before the lines to pipe it to the python console.

here are the two different codes.

# applies all modifiers on selected objects.

bpy.ops.object.convert(target='MESH', keep_original=False)

and

# applies single, specified, modifier on selected objects.

if modifier.type != 'SUBSURF':
modifier.show_render=True
bpy.ops.object.convert(target='MESH', '''keep_original=True''')

i would like two different scripts for each code.

code copied from http://wiki.blender.org/index.php/Doc:2 ... Python/FAQ

spiritech
live with the world as it is today and tomorrow the world is yours

CoDEmanX
Posts: 0
Joined: Sun Apr 05, 2009 7:42 pm
Location: Germany

Post by CoDEmanX » Wed Sep 19, 2012 1:07 am

open the Scripting screen, click on "+ New" and paste your code

note that you need to import e.g. bpy, while you don't have to in console

then click "Run script"

you may also have a look at the api docs and wiki to see how you can turn this into an addon
I'm sitting, waiting, wishing, building Blender in superstition...

Post Reply