Fix unintuitive UI where objects had to be visible for the operation to run.

This commit is contained in:
Dion Moult
2023-02-05 22:27:56 +11:00
parent 4d4961a490
commit 3cb29e1344
5 changed files with 16 additions and 14 deletions
@@ -117,5 +117,5 @@ class CopyAttributeToSelection(bpy.types.Operator, Operator):
def _execute(self, context):
value = context.active_object.BIMAttributeProperties.attributes.get(self.name).get_value()
for obj in context.selected_objects:
for obj in tool.Blender.get_selected_objects():
core.copy_attribute_to_selection(tool.Ifc, name=self.name, value=value, obj=obj)
@@ -128,7 +128,7 @@ class AssignDocument(bpy.types.Operator, tool.Ifc.Operator):
def _execute(self, context):
document = tool.Ifc.get().by_id(self.document)
objs = [bpy.data.objects.get(self.obj)] if self.obj else context.selected_objects
objs = [bpy.data.objects.get(self.obj)] if self.obj else tool.Blender.get_selected_objects()
for obj in objs:
element = tool.Ifc.get_entity(obj)
if element:
@@ -144,7 +144,7 @@ class UnassignDocument(bpy.types.Operator, tool.Ifc.Operator):
def _execute(self, context):
document = tool.Ifc.get().by_id(self.document)
objs = [bpy.data.objects.get(self.obj)] if self.obj else context.selected_objects
objs = [bpy.data.objects.get(self.obj)] if self.obj else tool.Blender.get_selected_objects()
for obj in objs:
element = tool.Ifc.get_entity(obj)
if element:
@@ -142,7 +142,7 @@ class AssignMaterial(bpy.types.Operator, tool.Ifc.Operator):
material_type: bpy.props.StringProperty()
def _execute(self, context):
objects = [bpy.data.objects.get(self.obj)] if self.obj else context.selected_objects
objects = [bpy.data.objects.get(self.obj)] if self.obj else tool.Blender.get_selected_objects()
active_obj = context.active_object
active_object_material_type = self.material_type or active_obj.BIMObjectMaterialProperties.material_type
material = tool.Ifc.get().by_id(int(active_obj.BIMObjectMaterialProperties.material))
@@ -205,7 +205,7 @@ class UnassignMaterial(bpy.types.Operator, tool.Ifc.Operator):
obj: bpy.props.StringProperty()
def _execute(self, context):
objects = [bpy.data.objects.get(self.obj)] if self.obj else context.selected_objects
objects = [bpy.data.objects.get(self.obj)] if self.obj else tool.Blender.get_selected_objects()
for obj in objects:
element = tool.Ifc.get_entity(obj)
if element:
@@ -472,7 +472,7 @@ class EditAssignedMaterial(bpy.types.Operator, tool.Ifc.Operator):
element = tool.Ifc.get_entity(active_obj)
material = ifcopenshell.util.element.get_material(element)
objects = context.selected_objects
objects = tool.Blender.get_selected_objects()
if props.active_material_set_item_id != 0: # We were editing a material layer set item
bpy.ops.bim.edit_material_set_item(material_set_item=props.active_material_set_item_id)
@@ -668,7 +668,7 @@ class CopyMaterial(bpy.types.Operator, tool.Ifc.Operator):
material = ifcopenshell.util.element.get_material(
self.file.by_id(context.active_object.BIMObjectProperties.ifc_definition_id)
)
for obj in context.selected_objects:
for obj in tool.Blender.get_selected_objects():
if obj == context.active_object:
continue
if not obj.BIMObjectProperties.ifc_definition_id:
@@ -289,7 +289,7 @@ class RemovePset(bpy.types.Operator, Operator):
def _execute(self, context):
if self.obj_type == "Object":
if context.selected_objects:
objects = [o.name for o in context.selected_objects]
objects = [o.name for o in tool.Blender.get_selected_objects()]
else:
objects = [context.active_object.name]
else:
@@ -318,7 +318,7 @@ class AddPset(bpy.types.Operator, Operator):
pset_name = get_pset_props(context, self.obj, self.obj_type).pset_name
if self.obj_type == "Object":
if context.selected_objects:
objects = [o.name for o in context.selected_objects]
objects = [o.name for o in tool.Blender.get_selected_objects()]
else:
objects = [context.active_object.name]
else:
@@ -446,7 +446,7 @@ class CopyPropertyToSelection(bpy.types.Operator, Operator):
is_pset = tool.Ifc.get().by_id(context.active_object.PsetProperties.active_pset_id).is_a("IfcPropertySet")
pset_name = context.active_object.PsetProperties.active_pset_name
prop_value = context.active_object.PsetProperties.properties.get(self.name).metadata.get_value()
for obj in context.selected_objects:
for obj in tool.Blender.get_selected_objects():
core.copy_property_to_selection(
tool.Ifc,
tool.Pset,
@@ -548,10 +548,9 @@ class BIM_OT_add_edit_custom_property(bpy.types.Operator):
def _execute(self, context):
self.file = IfcStore.get_file()
selected_objects = context.selected_objects
props = context.scene.AddEditProperties
for obj in selected_objects:
for obj in tool.Blender.get_selected_objects():
ifc_definition_id = obj.BIMObjectProperties.ifc_definition_id
if not ifc_definition_id:
continue
@@ -607,10 +606,9 @@ class BIM_OT_bulk_remove_psets(bpy.types.Operator):
def _execute(self, context):
self.file = IfcStore.get_file()
selected_objects = context.selected_objects
props = context.scene.DeletePsets
for obj in selected_objects:
for obj in tool.Blender.get_selected_objects():
ifc_definition_id = obj.BIMObjectProperties.ifc_definition_id
if not ifc_definition_id:
continue
@@ -37,6 +37,10 @@ class Blender:
i += 1
return f"{name} {i}"
@classmethod
def get_selected_objects(cls):
return set(bpy.context.selected_objects + [bpy.context.active_object])
@classmethod
def create_ifc_object(cls, ifc_class: str, name: str = None, data=None) -> bpy.types.Object:
name = name or "My " + ifc_class