1
$\begingroup$

Changing variables or functions within the blender scripts should normally be auto updated. I wanted to select a face on the plane added to scene and extrude it for several units. At the beginning no problem but when I change the face index then it does not update this condition. I did make several changes in my blender script and hoped Blender would auto update this and show me the updated result in my view port. I tried "Reloading script" or went to blender->system->reload and tried it again, but no luck, it could not update my script. Below is a screen shot and the code: I researched on internet and saw that it should be a problem for many people, but could not reason why exactly. Could you help me out? I am new in Blender and do not want to hang on problems which have maybe easy explanation.

import bpy
import bmesh

bpy.ops.object.editmode_toggle()

bpy.ops.mesh.select_mode( type = 'FACE' )

plane = bpy.context.scene.objects['Plane'].data

bm = bmesh.new()

bm.from_mesh(plane)

#bpy.ops.mesh.normals_make_consistent(inside=False)

bm.faces.ensure_lookup_table()

for face in bm.faces:
    face.select = False

bm.faces[42].select = True
    
#bm.faces.active = bm.faces[10]

bpy.ops.mesh.extrude_faces_move(TRANSFORM_OT_shrink_fatten={"value":+10})

bpy.ops.object.editmode_toggle()

#bm.to_mesh(plane)


extrude

$\endgroup$
1
  • $\begingroup$ Please do not edit the answer into the question. Post it as an answer instead. $\endgroup$
    – TheLabCat
    Commented Jun 5 at 15:17

1 Answer 1

0
$\begingroup$

I have one working code:

import bpy
import bmesh

bpy.ops.object.editmode_toggle()

bpy.ops.mesh.select_mode( type = 'FACE' )

plane = bpy.context.scene.objects['Plane'].data

bm = bmesh.new()

#below updated
bm = bmesh.from_edit_mesh(plane)

#bpy.ops.mesh.normals_make_consistent(inside=False)

bm.faces.ensure_lookup_table()

for face in bm.faces:
    face.select = False

bm.faces[19].select = True
    
#bm.faces.active = bm.faces[10]

bpy.ops.mesh.extrude_faces_move(TRANSFORM_OT_shrink_fatten={"value":+10})

#below updated
bmesh.update_edit_mesh(plane)

bpy.ops.object.editmode_toggle()

It is working like expected.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .