python - 无法完全取消选择 Blender 中的所有对象(使用脚本或键 A)

标签 python blender

我有一根长管,上面有几个垂直于管表面的微小圆柱体贴片。我一直在尝试编写一个脚本,使用 bool 修饰符将所有内容组合在一起,然后移除小圆柱体,以便只有一个网格由带有小圆柱体的管组成(用于 future 的 FEA)。创建这些圆柱体后,我保存了这个 blender 文件,最后一个圆柱体处于事件状态。之后,无论我做什么,我似乎都无法取消选择最后一个圆柱体(如图所示:i can't seem to get rid of the orange dot, which i thought it was fine but it weren't)。因此,当我尝试运行以下代码时:

import bpy  
import bmesh
import mathutils 

bpy.ops.object.select_all(action='DESELECT')

# tried to rename the first cylinder, but the last cylinder was renamed instead
bpy.ops.object.select_pattern(pattern = 'Cylinder')
bpy.context.object.data.name = 'Cylinder.000'

bpy.ops.object.select_all(action='DESELECT')
bpy.ops.object.select_pattern(pattern = 'Cylinder.000')

# tried to remesh the first cylinder, but the last one was remeshed instead
bpy.ops.object.modifier_add(type='REMESH')
bpy.context.object.modifiers["Remesh"].scale = 0.5
bpy.ops.object.modifier_apply(apply_as='DATA', modifier="Remesh")

bpy.ops.object.select_all(action='DESELECT')
bpy.ops.object.select_pattern(pattern = 'tube')

# tried to combine the first cylinder and the tube, but two cylinders were combined instead
bpy.ops.object.modifier_add(type='BOOLEAN')
bpy.context.object.modifiers["Boolean"].object = bpy.data.objects['Cylinder.000']   
bpy.context.object.modifiers["Boolean"].operation = 'UNION'
bpy.ops.object.modifier_apply(apply_as='DATA', modifier="Boolean")

# reselect the first cylinder and delete it (the only one worked!!!)
bpy.ops.object.select_all(action='DESELECT')
bpy.ops.object.select_pattern(pattern = 'Cylinder.000')
bpy.ops.object.delete()

最佳答案

这是 2.8 的更新,它减少了对选定对象的迭代。

for obj in bpy.context.selected_objects:
    obj.select_set(False)

或者你可以打电话

bpy.ops.object.select_all(action='DESELECT')

关于python - 无法完全取消选择 Blender 中的所有对象(使用脚本或键 A),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37335653/

相关文章:

python - pygame需要键盘中断来初始化显示

python - 我如何通过特定的垃圾箱过滤数据框的行

python - 如何在 blender 中标记最后导入的 *obj

three.js - 为什么在 ThreeJs 中两张脸看不见?

python - 将 CSV 导入 Blender 时出现 "Could not convert string to float"

python - django请求getlist方法: does this preserve the sequence of my posted parameters?

python - Colorbar 作为 Gridspec 中的子图(python): change size

python - 脚本: updating scripts

python - 使用python启动并行ssh渲染作业

Python:lambda 表达式的数据帧错误