mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-24 18:50:05 +00:00
Fix error when trying to edit an object that doesn't support edit mode with the TAB keypress
Also run black on the rest of the file
This commit is contained in:
@@ -648,18 +648,19 @@ class OverrideDuplicateMoveLinked(bpy.types.Operator):
|
|||||||
blenderbim.bim.handler.purge_module_data()
|
blenderbim.bim.handler.purge_module_data()
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
class OverrideDuplicateMoveAggregateMacro(bpy.types.Macro):
|
class OverrideDuplicateMoveAggregateMacro(bpy.types.Macro):
|
||||||
bl_idname = "bim.override_object_duplicate_move_aggregate_macro"
|
bl_idname = "bim.override_object_duplicate_move_aggregate_macro"
|
||||||
bl_label = "IFC Duplicate Objects Aggregate"
|
bl_label = "IFC Duplicate Objects Aggregate"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
|
|
||||||
class OverrideDuplicateMoveAggregate(bpy.types.Operator):
|
class OverrideDuplicateMoveAggregate(bpy.types.Operator):
|
||||||
bl_idname = "bim.override_object_duplicate_move_aggregate"
|
bl_idname = "bim.override_object_duplicate_move_aggregate"
|
||||||
bl_label = "IFC Duplicate Objects Aggregate"
|
bl_label = "IFC Duplicate Objects Aggregate"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
is_interactive: bpy.props.BoolProperty(name="Is Interactive", default=True)
|
is_interactive: bpy.props.BoolProperty(name="Is Interactive", default=True)
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def poll(cls, context):
|
def poll(cls, context):
|
||||||
return len(context.selected_objects) > 0
|
return len(context.selected_objects) > 0
|
||||||
@@ -714,7 +715,9 @@ class OverrideDuplicateMoveAggregate(bpy.types.Operator):
|
|||||||
)
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
pset = ifcopenshell.api.run("pset.add_pset", tool.Ifc.get(), product=element, name="BBIM_Aggregate_Data")
|
pset = ifcopenshell.api.run(
|
||||||
|
"pset.add_pset", tool.Ifc.get(), product=element, name="BBIM_Aggregate_Data"
|
||||||
|
)
|
||||||
|
|
||||||
ifcopenshell.api.run(
|
ifcopenshell.api.run(
|
||||||
"pset.edit_pset",
|
"pset.edit_pset",
|
||||||
@@ -728,7 +731,7 @@ class OverrideDuplicateMoveAggregate(bpy.types.Operator):
|
|||||||
parent_element = tool.Ifc.get().by_guid(pset["Parent"])
|
parent_element = tool.Ifc.get().by_guid(pset["Parent"])
|
||||||
parent_pset = ifcopenshell.util.element.get_pset(parent_element, "BBIM_Aggregate_Data")
|
parent_pset = ifcopenshell.util.element.get_pset(parent_element, "BBIM_Aggregate_Data")
|
||||||
data = json.loads(parent_pset["Data"])
|
data = json.loads(parent_pset["Data"])
|
||||||
data[0]['children'].append(new_entity.GlobalId)
|
data[0]["children"].append(new_entity.GlobalId)
|
||||||
|
|
||||||
ifcopenshell.api.run(
|
ifcopenshell.api.run(
|
||||||
"pset.edit_pset",
|
"pset.edit_pset",
|
||||||
@@ -820,7 +823,6 @@ class OverrideDuplicateMoveAggregate(bpy.types.Operator):
|
|||||||
pair.append(new_parent)
|
pair.append(new_parent)
|
||||||
parents.append(pair)
|
parents.append(pair)
|
||||||
|
|
||||||
|
|
||||||
if not entity.is_a("IfcElementAssembly"):
|
if not entity.is_a("IfcElementAssembly"):
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
@@ -878,8 +880,9 @@ class OverrideDuplicateMoveAggregate(bpy.types.Operator):
|
|||||||
new_obj.BIMObjectProperties.collection = None
|
new_obj.BIMObjectProperties.collection = None
|
||||||
|
|
||||||
# Copy the actual class
|
# Copy the actual class
|
||||||
new_entity = blenderbim.core.root.copy_class(tool.Ifc, tool.Collector, tool.Geometry, tool.Root, obj=new_obj)
|
new_entity = blenderbim.core.root.copy_class(
|
||||||
|
tool.Ifc, tool.Collector, tool.Geometry, tool.Root, obj=new_obj
|
||||||
|
)
|
||||||
|
|
||||||
if new_entity:
|
if new_entity:
|
||||||
# Checks if the object belongs to an Ifc Array
|
# Checks if the object belongs to an Ifc Array
|
||||||
@@ -914,7 +917,6 @@ class OverrideDuplicateMoveAggregate(bpy.types.Operator):
|
|||||||
if not pset:
|
if not pset:
|
||||||
create_data_structure(selected_root_entity)
|
create_data_structure(selected_root_entity)
|
||||||
|
|
||||||
|
|
||||||
pset = ifcopenshell.util.element.get_pset(selected_root_entity, "BBIM_Aggregate_Data")
|
pset = ifcopenshell.util.element.get_pset(selected_root_entity, "BBIM_Aggregate_Data")
|
||||||
|
|
||||||
selected_root_parent = selected_root_entity
|
selected_root_parent = selected_root_entity
|
||||||
@@ -941,7 +943,6 @@ class RefreshAggregate(bpy.types.Operator):
|
|||||||
bl_label = "IFC Refresh Aggregate"
|
bl_label = "IFC Refresh Aggregate"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def poll(cls, context):
|
def poll(cls, context):
|
||||||
return len(context.selected_objects) > 0
|
return len(context.selected_objects) > 0
|
||||||
@@ -1013,7 +1014,9 @@ class RefreshAggregate(bpy.types.Operator):
|
|||||||
new_obj.select_set(True)
|
new_obj.select_set(True)
|
||||||
|
|
||||||
# Copy the actual class
|
# Copy the actual class
|
||||||
new_entity = blenderbim.core.root.copy_class(tool.Ifc, tool.Collector, tool.Geometry, tool.Root, obj=new_obj)
|
new_entity = blenderbim.core.root.copy_class(
|
||||||
|
tool.Ifc, tool.Collector, tool.Geometry, tool.Root, obj=new_obj
|
||||||
|
)
|
||||||
|
|
||||||
if new_entity:
|
if new_entity:
|
||||||
# Checks if the object belongs to an Ifc Array
|
# Checks if the object belongs to an Ifc Array
|
||||||
@@ -1040,7 +1043,6 @@ class RefreshAggregate(bpy.types.Operator):
|
|||||||
selected_root_obj = context.selected_objects[0]
|
selected_root_obj = context.selected_objects[0]
|
||||||
selected_root_entity = tool.Ifc.get_entity(selected_root_obj)
|
selected_root_entity = tool.Ifc.get_entity(selected_root_obj)
|
||||||
|
|
||||||
|
|
||||||
if not selected_root_entity.is_a("IfcElementAssembly"):
|
if not selected_root_entity.is_a("IfcElementAssembly"):
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
@@ -1064,7 +1066,6 @@ class RefreshAggregate(bpy.types.Operator):
|
|||||||
for parent in parents:
|
for parent in parents:
|
||||||
duplicate_children(parent)
|
duplicate_children(parent)
|
||||||
|
|
||||||
|
|
||||||
old_objs = []
|
old_objs = []
|
||||||
for old, new in old_to_new.items():
|
for old, new in old_to_new.items():
|
||||||
old_objs.append(tool.Ifc.get_object(old))
|
old_objs.append(tool.Ifc.get_object(old))
|
||||||
@@ -1317,9 +1318,8 @@ class OverrideModeSetEdit(bpy.types.Operator):
|
|||||||
# The active object is non-mesh-like. Set a valid object (or None) as active
|
# The active object is non-mesh-like. Set a valid object (or None) as active
|
||||||
context.view_layer.objects.active = context.selected_objects[0] if context.selected_objects else None
|
context.view_layer.objects.active = context.selected_objects[0] if context.selected_objects else None
|
||||||
if context.active_object:
|
if context.active_object:
|
||||||
bpy.ops.object.mode_set(mode="EDIT", toggle=True)
|
return tool.Blender.toggle_edit_mode(context)
|
||||||
else:
|
# Restore the selection if nothing worked
|
||||||
# restore the selection if nothing worked
|
|
||||||
for obj in objs:
|
for obj in objs:
|
||||||
obj.select_set(True)
|
obj.select_set(True)
|
||||||
context.view_layer.objects.active = active_obj
|
context.view_layer.objects.active = active_obj
|
||||||
@@ -1330,7 +1330,7 @@ class OverrideModeSetEdit(bpy.types.Operator):
|
|||||||
|
|
||||||
def _invoke(self, context, event):
|
def _invoke(self, context, event):
|
||||||
if not tool.Ifc.get():
|
if not tool.Ifc.get():
|
||||||
return bpy.ops.object.mode_set(mode="EDIT", toggle=True)
|
return tool.Blender.toggle_edit_mode(context)
|
||||||
return self.execute(context)
|
return self.execute(context)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,9 @@ VIEWPORT_ATTRIBUTES = [
|
|||||||
|
|
||||||
|
|
||||||
class Blender:
|
class Blender:
|
||||||
|
OBJECT_TYPES_THAT_SUPPORT_EDIT_MODE = ("MESH", "CURVE", "SURFACE", "META", "FONT", "LATTICE", "ARMATURE")
|
||||||
|
OBJECT_TYPES_THAT_SUPPORT_EDIT_GPENCIL_MODE = ("GPENCIL",)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def set_active_object(cls, obj):
|
def set_active_object(cls, obj):
|
||||||
bpy.context.view_layer.objects.active = obj
|
bpy.context.view_layer.objects.active = obj
|
||||||
@@ -441,3 +444,15 @@ class Blender:
|
|||||||
callback(bm_a, new_verts, new_edges, new_faces)
|
callback(bm_a, new_verts, new_edges, new_faces)
|
||||||
|
|
||||||
return bm_a
|
return bm_a
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def toggle_edit_mode(cls, context):
|
||||||
|
ao = context.active_object
|
||||||
|
if not ao:
|
||||||
|
return {"CANCELLED"}
|
||||||
|
if ao.type in cls.OBJECT_TYPES_THAT_SUPPORT_EDIT_MODE:
|
||||||
|
return bpy.ops.object.mode_set(mode="EDIT", toggle=True)
|
||||||
|
elif ao.type in cls.OBJECT_TYPES_THAT_SUPPORT_EDIT_GPENCIL_MODE:
|
||||||
|
return bpy.ops.object.mode_set(mode="EDIT_GPENCIL", toggle=True)
|
||||||
|
else:
|
||||||
|
return {"CANCELLED"}
|
||||||
|
|||||||
Reference in New Issue
Block a user