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