Friday, December 7, 2012

Python Smoothing

This tutorial entry will show how to script in the sub-surface modifier and the smooth_shader operator.  Note that the following code would be used within an Operator.  For simply performing these operations on an already selected object, see the Python Macros entry.

# add a subsurf modifier, setting level to 2
ssMod = obj.modifiers.new("MyName", type='SUBSURF')
ssMod.levels = 2

# set a selected active object (operations must be in this order)
obj.select = True
bpy.context.scene.objects.active = obj

# add smooth shading
bpy.obs.object.shade_smooth()



Some items to note:  the shade_smooth() operator performs its action on an active-selected object.  This is typically identified by an orange border in the 3D viewport.  To achieve this kind of selection, the object must first be selected, and then set as the active object in the scene.  Order matters here.

No comments:

Post a Comment