Compare commits

...

2 Commits

Author SHA1 Message Date
Ryan Schultz 33dc49693a whoops, forgot to delete some bits. 2023-10-21 19:53:50 -05:00
Ryan Schultz ec8210fb67 When adding a context, check to see if it already exists first. 2023-10-21 19:50:43 -05:00
@@ -40,7 +40,23 @@ class AddContext(bpy.types.Operator, Operator):
target_view: bpy.props.StringProperty()
parent: bpy.props.IntProperty()
def _execute(self, context):
def _execute(self, context):
ifc_file = tool.Ifc.get()
# Check if a IfcGeometricRepresentationSubContext already exists in the file
for subcontext in ifc_file.by_type("IfcGeometricRepresentationSubContext", include_subtypes=False):
if (
subcontext.ContextType == self.context_type
and subcontext.ContextIdentifier == self.context_identifier
and subcontext.TargetView == self.target_view
):
self.report({'INFO'}, "Context already exists. Did not add.")
return {'CANCELLED'}
# If the context doesn't exist, add it
core.add_context(
tool.Ifc,
context_type=self.context_type,
@@ -48,6 +64,10 @@ class AddContext(bpy.types.Operator, Operator):
target_view=self.target_view,
parent=tool.Ifc.get().by_id(self.parent) if self.parent else None,
)
self.report({'INFO'}, "Context added.")
return {'FINISHED'}
class RemoveContext(bpy.types.Operator, Operator):