我有一根长管,上面有几个垂直于管表面的微小圆柱体贴片。我一直在尝试编写一个脚本,使用 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/