我有一个长管,有几个垂直于管表面的微小圆柱体。我一直在尝试编写一个脚本,使用布尔修饰符将所有内容组合在一起,然后移除微小的圆柱体,这样只有一个网格由一个带有微小圆柱体的管组成(对于未来的FEA)。创建这些柱面后,我保存了这个搅拌器文件,最后一个柱面处于活动状态。之后,无论我做了什么,我似乎都无法取消选择最后一个圆柱体(如图中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()
答案 0 :(得分:3)
我知道这是一个老帖子,但对于其他想要取消选择所有对象的人,我会这样做:
for obj in bpy.data.objects:
obj.select = False
答案 1 :(得分:1)
Dfelinto向我展示了一个很酷的技巧,让所有物体都成为活跃的。
circle.svg
答案 2 :(得分:0)
这是2.8的更新,它减少了对选定对象的迭代。
for obj in bpy.context.selected_objects:
obj.select_set(False)
或者您可以致电
bpy.ops.object.select_all(action='DESELECT')