mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-28 19:27:10 +00:00
Code Cleanup & Consistency
This commit is contained in:
@@ -92,13 +92,14 @@ class AddRepresentation(bpy.types.Operator):
|
|||||||
gprop = context.scene.BIMGeoreferenceProperties
|
gprop = context.scene.BIMGeoreferenceProperties
|
||||||
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 context.selected_objects
|
||||||
for obj in objs:
|
for obj in objs:
|
||||||
if not obj.BIMObjectProperties.ifc_definition_id:
|
obj_id = obj.BIMObjectProperties.ifc_definition_id
|
||||||
|
if not obj_id:
|
||||||
continue
|
continue
|
||||||
bpy.ops.bim.edit_object_placement(obj=obj.name)
|
bpy.ops.bim.edit_object_placement(obj=obj.name)
|
||||||
if not obj.data or not hasattr(obj.data, "polygons"):
|
if not obj.data or not hasattr(obj.data, "polygons"):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
product = self.file.by_id(obj.BIMObjectProperties.ifc_definition_id)
|
product = self.file.by_id(obj_id)
|
||||||
|
|
||||||
context_id = self.context_id or int(context.scene.BIMProperties.contexts)
|
context_id = self.context_id or int(context.scene.BIMProperties.contexts)
|
||||||
context_of_items = self.file.by_id(context_id)
|
context_of_items = self.file.by_id(context_id)
|
||||||
@@ -158,7 +159,7 @@ class AddRepresentation(bpy.types.Operator):
|
|||||||
mesh.name = "{}/{}".format(context_id, result.id())
|
mesh.name = "{}/{}".format(context_id, result.id())
|
||||||
mesh.BIMMeshProperties.ifc_definition_id = int(result.id())
|
mesh.BIMMeshProperties.ifc_definition_id = int(result.id())
|
||||||
obj.data = mesh
|
obj.data = mesh
|
||||||
Data.load(IfcStore.get_file(), obj.BIMObjectProperties.ifc_definition_id)
|
Data.load(self.file, obj_id)
|
||||||
|
|
||||||
if product.is_a("IfcTypeProduct"):
|
if product.is_a("IfcTypeProduct"):
|
||||||
if self.file.schema == "IFC2X3":
|
if self.file.schema == "IFC2X3":
|
||||||
@@ -167,7 +168,7 @@ class AddRepresentation(bpy.types.Operator):
|
|||||||
types = product.Types
|
types = product.Types
|
||||||
if types:
|
if types:
|
||||||
for element in types[0].RelatedObjects:
|
for element in types[0].RelatedObjects:
|
||||||
Data.load(IfcStore.get_file(), element.id())
|
Data.load(self.file, element.id())
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -125,23 +125,25 @@ class AssignMaterial(bpy.types.Operator):
|
|||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
self.file = IfcStore.get_file()
|
self.file = IfcStore.get_file()
|
||||||
|
active_object = bpy.data.objects.get(self.obj, context.active_object)
|
||||||
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 context.selected_objects
|
||||||
for obj in objs:
|
material = self.file.by_id(int(active_object.BIMObjectMaterialProperties.material))
|
||||||
if not obj.BIMObjectProperties.ifc_definition_id:
|
material_type = self.material_type or active_object.BIMObjectMaterialProperties.material_type
|
||||||
|
for obj in objs:
|
||||||
|
obj_id = obj.BIMObjectProperties.ifc_definition_id
|
||||||
|
if not obj_id:
|
||||||
continue
|
continue
|
||||||
material_type = self.material_type or obj.BIMObjectMaterialProperties.material_type
|
|
||||||
element = self.file.by_id(obj.BIMObjectProperties.ifc_definition_id)
|
|
||||||
ifcopenshell.api.run(
|
ifcopenshell.api.run(
|
||||||
"material.assign_material",
|
"material.assign_material",
|
||||||
self.file,
|
self.file,
|
||||||
**{
|
**{
|
||||||
"product": element,
|
"product": self.file.by_id(obj_id),
|
||||||
"type": material_type,
|
"type": material_type,
|
||||||
"material": self.file.by_id(int(obj.BIMObjectMaterialProperties.material)),
|
"material": material,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
Data.load(IfcStore.get_file())
|
Data.load(self.file)
|
||||||
Data.load(IfcStore.get_file(), obj.BIMObjectProperties.ifc_definition_id)
|
Data.load(self.file, obj_id)
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
@@ -504,26 +506,25 @@ class EditAssignedMaterial(bpy.types.Operator):
|
|||||||
self.file = IfcStore.get_file()
|
self.file = IfcStore.get_file()
|
||||||
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object
|
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object
|
||||||
props = obj.BIMObjectMaterialProperties
|
props = obj.BIMObjectMaterialProperties
|
||||||
product_data = Data.products[obj.BIMObjectProperties.ifc_definition_id]
|
obj_id = obj.BIMObjectProperties.ifc_definition_id
|
||||||
|
product_data = Data.products[obj_id]
|
||||||
|
|
||||||
if product_data["type"] == "IfcMaterial":
|
if product_data["type"] == "IfcMaterial":
|
||||||
bpy.ops.bim.unassign_material(obj=obj.name)
|
bpy.ops.bim.unassign_material(obj=obj.name)
|
||||||
bpy.ops.bim.assign_material(obj=obj.name, material_type="IfcMaterial")
|
bpy.ops.bim.assign_material(obj=obj.name, material_type="IfcMaterial")
|
||||||
Data.load(IfcStore.get_file(), obj.BIMObjectProperties.ifc_definition_id)
|
Data.load(self.file, obj_id)
|
||||||
bpy.ops.bim.disable_editing_assigned_material(obj=obj.name)
|
bpy.ops.bim.disable_editing_assigned_material(obj=obj.name)
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
material_set = self.file.by_id(self.material_set)
|
material_set = self.file.by_id(self.material_set)
|
||||||
|
|
||||||
attributes = {}
|
attributes = {attribute.name: attribute.get_value() for attribute in props.material_set_attributes}
|
||||||
for attribute in props.material_set_attributes:
|
|
||||||
attributes[attribute.name] = None if attribute.is_null else attribute.string_value
|
|
||||||
ifcopenshell.api.run(
|
ifcopenshell.api.run(
|
||||||
"material.edit_assigned_material",
|
"material.edit_assigned_material",
|
||||||
self.file,
|
self.file,
|
||||||
**{"element": material_set, "attributes": attributes},
|
**{"element": material_set, "attributes": attributes},
|
||||||
)
|
)
|
||||||
Data.load(IfcStore.get_file(), obj.BIMObjectProperties.ifc_definition_id)
|
Data.load(self.file, obj_id)
|
||||||
|
|
||||||
if self.material_set_usage:
|
if self.material_set_usage:
|
||||||
material_set_usage = self.file.by_id(self.material_set_usage)
|
material_set_usage = self.file.by_id(self.material_set_usage)
|
||||||
@@ -737,17 +738,18 @@ class CopyMaterial(bpy.types.Operator):
|
|||||||
for obj in context.selected_objects:
|
for obj in context.selected_objects:
|
||||||
if obj == context.active_object:
|
if obj == context.active_object:
|
||||||
continue
|
continue
|
||||||
if not obj.BIMObjectProperties.ifc_definition_id:
|
obj_id = obj.BIMObjectProperties.ifc_definition_id
|
||||||
|
if not obj_id:
|
||||||
continue
|
continue
|
||||||
ifcopenshell.api.run(
|
ifcopenshell.api.run(
|
||||||
"material.copy_material",
|
"material.copy_material",
|
||||||
self.file,
|
self.file,
|
||||||
**{
|
**{
|
||||||
"material": material,
|
"material": material,
|
||||||
"element": self.file.by_id(obj.BIMObjectProperties.ifc_definition_id),
|
"element": self.file.by_id(obj_id),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
Data.load(self.file, obj.BIMObjectProperties.ifc_definition_id)
|
Data.load(self.file, obj_id)
|
||||||
self.set_default_material(obj, material)
|
self.set_default_material(obj, material)
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|||||||
@@ -137,15 +137,20 @@ class RemoveContainer(bpy.types.Operator):
|
|||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
active_object = context.active_object
|
active_object = context.active_object
|
||||||
for obj in [bpy.data.objects.get(self.obj)] if self.obj else context.selected_objects:
|
self.file = IfcStore.get_file()
|
||||||
oprops = obj.BIMObjectProperties
|
objs = [bpy.data.objects.get(self.obj)] if self.obj else context.selected_objects
|
||||||
if not oprops.ifc_definition_id:
|
for obj in objs:
|
||||||
|
obj_id = obj.BIMObjectProperties.ifc_definition_id
|
||||||
|
if not obj_id:
|
||||||
continue
|
continue
|
||||||
self.file = IfcStore.get_file()
|
|
||||||
ifcopenshell.api.run(
|
ifcopenshell.api.run(
|
||||||
"spatial.remove_container", self.file, **{"product": self.file.by_id(oprops.ifc_definition_id)}
|
"spatial.remove_container",
|
||||||
|
self.file,
|
||||||
|
**{
|
||||||
|
"product": self.file.by_id(obj_id)
|
||||||
|
}
|
||||||
)
|
)
|
||||||
Data.load(IfcStore.get_file(), oprops.ifc_definition_id)
|
Data.load(self.file, obj_id)
|
||||||
|
|
||||||
aggregate_collection = bpy.data.collections.get(obj.name)
|
aggregate_collection = bpy.data.collections.get(obj.name)
|
||||||
if aggregate_collection:
|
if aggregate_collection:
|
||||||
|
|||||||
Reference in New Issue
Block a user