Blender Python api 顶点、边和面选择

发布于 2025-01-13 12:59:59 字数 1103 浏览 1 评论 0原文

使用我从 获得的以下代码https://blender.stackexchange.com/questions/43127/how-do-i-select-specific-vertices-in-blender-using-python-script。我可以选择顶点,但是当我取消注释边缘或面并注释顶点时,它不起作用。我只是猜测了“edges”和“facees”的拼写,但它正确吗?

import bpy

#clear scene, make mesh
bpy.ops.object.mode_set(mode = 'OBJECT')
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete(use_global=False)
bpy.ops.mesh.primitive_cube_add(size=2, enter_editmode=False, align='WORLD', location=(0, 0, 0), rotation=(1.5708, 1.5708, 0))
obj = bpy.data.objects["Cube"]

#select vertex
obj = bpy.context.active_object
bpy.ops.object.mode_set(mode = 'EDIT') 
bpy.ops.mesh.select_mode(type="VERT")
#bpy.ops.mesh.select_mode(type="EDGE")
#bpy.ops.mesh.select_mode(type="FACE")
bpy.ops.mesh.select_all(action = 'DESELECT')
bpy.ops.object.mode_set(mode = 'OBJECT')
obj.data.vertices[5].select = True
#obj.data.edges[1].select = True
#obj.data.faces[1].select = True
bpy.ops.object.mode_set(mode = 'EDIT') 

Using the following code which I got from https://blender.stackexchange.com/questions/43127/how-do-i-select-specific-vertices-in-blender-using-python-script. I can get vertices to select but when I uncomment for edged or faces and comment for vertices it doesn't work. I just guessed at the spelling for edges and facees but is it correct?

import bpy

#clear scene, make mesh
bpy.ops.object.mode_set(mode = 'OBJECT')
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete(use_global=False)
bpy.ops.mesh.primitive_cube_add(size=2, enter_editmode=False, align='WORLD', location=(0, 0, 0), rotation=(1.5708, 1.5708, 0))
obj = bpy.data.objects["Cube"]

#select vertex
obj = bpy.context.active_object
bpy.ops.object.mode_set(mode = 'EDIT') 
bpy.ops.mesh.select_mode(type="VERT")
#bpy.ops.mesh.select_mode(type="EDGE")
#bpy.ops.mesh.select_mode(type="FACE")
bpy.ops.mesh.select_all(action = 'DESELECT')
bpy.ops.object.mode_set(mode = 'OBJECT')
obj.data.vertices[5].select = True
#obj.data.edges[1].select = True
#obj.data.faces[1].select = True
bpy.ops.object.mode_set(mode = 'EDIT') 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

千寻… 2025-01-20 12:59:59

我最终用“多边形”一词替换了“面”一词,并且它起作用了。
输入图片此处描述

import bpy

#clear scene, make mesh
bpy.ops.object.mode_set(mode = 'OBJECT')
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete(use_global=False)
bpy.ops.mesh.primitive_cube_add(size=2, enter_editmode=False, align='WORLD', location=(0, 0, 0), rotation=(1.5708, 1.5708, 0))
obj = bpy.data.objects["Cube"]

#select vertex
obj = bpy.context.active_object
bpy.ops.object.mode_set(mode = 'EDIT') 
#bpy.ops.mesh.select_mode(type="VERT")
#bpy.ops.mesh.select_mode(type="EDGE")
bpy.ops.mesh.select_mode(type="FACE")
bpy.ops.mesh.select_all(action = 'DESELECT')
bpy.ops.object.mode_set(mode = 'OBJECT')
#obj.data.vertices[2].select = True
#obj.data.edges[7].select = True
obj.data.polygons[2].select = True
bpy.ops.object.mode_set(mode = 'EDIT') 

I eventually replaced the word 'face' with the word 'polygons' and it worked.
enter image description here

import bpy

#clear scene, make mesh
bpy.ops.object.mode_set(mode = 'OBJECT')
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete(use_global=False)
bpy.ops.mesh.primitive_cube_add(size=2, enter_editmode=False, align='WORLD', location=(0, 0, 0), rotation=(1.5708, 1.5708, 0))
obj = bpy.data.objects["Cube"]

#select vertex
obj = bpy.context.active_object
bpy.ops.object.mode_set(mode = 'EDIT') 
#bpy.ops.mesh.select_mode(type="VERT")
#bpy.ops.mesh.select_mode(type="EDGE")
bpy.ops.mesh.select_mode(type="FACE")
bpy.ops.mesh.select_all(action = 'DESELECT')
bpy.ops.object.mode_set(mode = 'OBJECT')
#obj.data.vertices[2].select = True
#obj.data.edges[7].select = True
obj.data.polygons[2].select = True
bpy.ops.object.mode_set(mode = 'EDIT') 
空城仅有旧梦在 2025-01-20 12:59:59

在编辑模式下,Blender 使用网格的“副本”,该副本在您退出此模式之前不会保存。在对象模式下,更改是立即的。

bpy.ops.object.mode_set(mode = 'OBJECT')
act_obj = bpy.context.active_object.name
#No need to select to apply transformation
bpy.data.meshes[act_obj].vertices[2].co[2] +=0.1

In edit mode Blender works with a 'copy' of the mesh that is not saved until you exit this mode. In object mode the changes are immediate.

bpy.ops.object.mode_set(mode = 'OBJECT')
act_obj = bpy.context.active_object.name
#No need to select to apply transformation
bpy.data.meshes[act_obj].vertices[2].co[2] +=0.1
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文