Created
February 9, 2019 16:56
-
-
Save aaronjolson/ea54e6c483f5a5b790112e6c0c43a7a3 to your computer and use it in GitHub Desktop.
Demonstration of using Python to take an existing mesh, selecting a particular face, and extruding it
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import bpy,bmesh | |
| # Assumes we aleady have a cube out, nothing selected | |
| ob = bpy.data.objects['Cube'] | |
| bpy.ops.object.mode_set(mode='EDIT') | |
| mesh = bmesh.from_edit_mesh(bpy.context.object.data) | |
| ur_face = None | |
| # look at all of the faces of the cube, find the one that is 'facing' the positive direction on the y axis | |
| for f in mesh.faces: | |
| if f.normal.y == 1.0: | |
| f.select = True | |
| face_to_extrude = f | |
| # command to make an inplace extrusion | |
| extruded_face = bmesh.ops.extrude_face_region(mesh, geom=[face_to_extrude]) | |
| # translate the newly extruded face along the green y axis in 3D space | |
| bmesh.ops.translate(mesh, vec=(0,2,0), verts=extruded_face['geom'][-1].verts) | |
| # trigger viewport update | |
| bpy.context.scene.objects.active = bpy.context.scene.objects.active |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment