Skip to content

Commit 4614bde

Browse files
committed
Cleanup : Use clear instead of while...remove loop
1 parent 8866970 commit 4614bde

24 files changed

Lines changed: 79 additions & 150 deletions

File tree

src/blenderbim/blenderbim/bim/module/attribute/operator.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ def execute(self, context):
4040
obj = bpy.data.materials.get(self.obj)
4141
oprops = obj.BIMObjectProperties
4242
props = obj.BIMAttributeProperties
43-
while len(props.attributes) > 0:
44-
props.attributes.remove(0)
43+
props.attributes.clear()
4544
for attribute in Data.products[oprops.ifc_definition_id]:
4645
new = props.attributes.add()
4746
if attribute["type"] == "entity" or (attribute["type"] == "list" and attribute["list_type"] == "entity"):

src/blenderbim/blenderbim/bim/module/bcf/operator.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,7 @@ def execute(self, context):
166166
bcfxml = bcfstore.BcfStore.get_bcfxml()
167167
bcfxml.get_comments(self.topic_guid)
168168
blender_topic = context.scene.BCFProperties.topics.get(self.topic_guid)
169-
while len(blender_topic.comments) > 0:
170-
blender_topic.comments.remove(0)
169+
blender_topic.comments.clear()
171170
for comment in bcfxml.topics[self.topic_guid].comments.values():
172171
new = blender_topic.comments.add()
173172
data_map = {
@@ -770,8 +769,7 @@ def execute(self, context):
770769

771770
if viewpoint.snapshot:
772771
obj.data.show_background_images = True
773-
while len(obj.data.background_images) > 0:
774-
obj.data.background_images.remove(obj.data.background_images[0])
772+
obj.data.background_images.clear()
775773
background = obj.data.background_images.new()
776774
background.image = bpy.data.images.load(
777775
os.path.join(bcfxml.filepath, topic.guid, viewpoint.snapshot)

src/blenderbim/blenderbim/bim/module/clash/operator.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,7 @@ class SetBlenderClashSetA(bpy.types.Operator):
459459
bl_options = {"REGISTER", "UNDO"}
460460

461461
def execute(self, context):
462-
while len(context.scene.BIMClashProperties.blender_clash_set_a) > 0:
463-
context.scene.BIMClashProperties.blender_clash_set_a.remove(0)
462+
context.scene.BIMClashProperties.blender_clash_set_a.clear()
464463
for obj in context.selected_objects:
465464
new = context.scene.BIMClashProperties.blender_clash_set_a.add()
466465
new.name = obj.name
@@ -473,8 +472,7 @@ class SetBlenderClashSetB(bpy.types.Operator):
473472
bl_options = {"REGISTER", "UNDO"}
474473

475474
def execute(self, context):
476-
while len(context.scene.BIMClashProperties.blender_clash_set_b) > 0:
477-
context.scene.BIMClashProperties.blender_clash_set_b.remove(0)
475+
context.scene.BIMClashProperties.blender_clash_set_b.clear()
478476
for obj in context.selected_objects:
479477
new = context.scene.BIMClashProperties.blender_clash_set_b.add()
480478
new.name = obj.name

src/blenderbim/blenderbim/bim/module/classification/operator.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ class EnableEditingClassification(bpy.types.Operator):
6969

7070
def execute(self, context):
7171
props = context.scene.BIMClassificationProperties
72-
while len(props.classification_attributes) > 0:
73-
props.classification_attributes.remove(0)
72+
props.classification_attributes.clear()
7473
classification_data = Data.classifications[self.classification]
7574
for attribute in IfcStore.get_schema().declaration_by_name("IfcClassification").all_attributes():
7675
new = props.classification_attributes.add()
@@ -154,8 +153,7 @@ class EnableEditingClassificationReference(bpy.types.Operator):
154153
def execute(self, context):
155154
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object
156155
props = obj.BIMClassificationReferenceProperties
157-
while len(props.reference_attributes) > 0:
158-
props.reference_attributes.remove(0)
156+
props.reference_attributes.clear()
159157
reference_data = Data.references[self.reference]
160158
for attribute in IfcStore.get_schema().declaration_by_name("IfcClassificationReference").all_attributes():
161159
if attribute.name() == "ReferencedSource":

src/blenderbim/blenderbim/bim/module/classification/prop.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ def updateClassification(self, context):
5656

5757
def getReferences(self, context, parent_id=None):
5858
props = context.scene.BIMClassificationProperties
59-
while len(props.available_library_references) > 0:
60-
props.available_library_references.remove(0)
59+
props.available_library_references.clear()
6160
for reference in Data.library_file.by_id(parent_id).HasReferences:
6261
new = props.available_library_references.add()
6362
new.identification = reference.Identification or ""

src/blenderbim/blenderbim/bim/module/constraint/operator.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ class LoadObjectives(bpy.types.Operator):
3333

3434
def execute(self, context):
3535
props = context.scene.BIMConstraintProperties
36-
while len(props.constraints) > 0:
37-
props.constraints.remove(0)
36+
props.constraints.clear()
3837
for constraint_id, constraint in Data.objectives.items():
3938
new = props.constraints.add()
4039
new.name = constraint["Name"] or "Unnamed"
@@ -63,8 +62,7 @@ class EnableEditingConstraint(bpy.types.Operator):
6362

6463
def execute(self, context):
6564
props = context.scene.BIMConstraintProperties
66-
while len(props.constraint_attributes) > 0:
67-
props.constraint_attributes.remove(0)
65+
props.constraint_attributes.clear()
6866

6967
if props.is_editing == "IfcObjective":
7068
data = Data.objectives[self.constraint]

src/blenderbim/blenderbim/bim/module/cost/operator.py

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ class EnableEditingCostSchedule(bpy.types.Operator):
9494
def execute(self, context):
9595
self.props = context.scene.BIMCostProperties
9696
self.props.active_cost_schedule_id = self.cost_schedule
97-
while len(self.props.cost_schedule_attributes) > 0:
98-
self.props.cost_schedule_attributes.remove(0)
97+
self.props.cost_schedule_attributes.clear()
9998
self.enable_editing_cost_schedule()
10099
self.props.is_editing = "COST_SCHEDULE"
101100
return {"FINISHED"}
@@ -276,8 +275,7 @@ class EnableEditingCostItem(bpy.types.Operator):
276275

277276
def execute(self, context):
278277
props = context.scene.BIMCostProperties
279-
while len(props.cost_item_attributes) > 0:
280-
props.cost_item_attributes.remove(0)
278+
props.cost_item_attributes.clear()
281279

282280
data = Data.cost_items[self.cost_item]
283281
blenderbim.bim.helper.import_attributes("IfcCostItem", props.cost_item_attributes, data)
@@ -538,8 +536,7 @@ class EnableEditingCostItemQuantity(bpy.types.Operator):
538536

539537
def execute(self, context):
540538
self.props = context.scene.BIMCostProperties
541-
while len(self.props.quantity_attributes) > 0:
542-
self.props.quantity_attributes.remove(0)
539+
self.props.quantity_attributes.clear()
543540
self.props.active_cost_item_quantity_id = self.physical_quantity
544541
data = Data.physical_quantities[self.physical_quantity]
545542
blenderbim.bim.helper.import_attributes(data["type"], self.props.quantity_attributes, data)
@@ -635,8 +632,7 @@ class EnableEditingCostItemValue(bpy.types.Operator):
635632

636633
def execute(self, context):
637634
self.props = context.scene.BIMCostProperties
638-
while len(self.props.cost_value_attributes) > 0:
639-
self.props.cost_value_attributes.remove(0)
635+
self.props.cost_value_attributes.clear()
640636
self.props.active_cost_item_value_id = self.cost_value
641637
data = Data.cost_values[self.cost_value]
642638

@@ -868,12 +864,9 @@ class LoadCostItemQuantities(bpy.types.Operator):
868864
def execute(self, context):
869865
self.props = context.scene.BIMCostProperties
870866
self.file = IfcStore.get_file()
871-
while len(self.props.cost_item_products) > 0:
872-
self.props.cost_item_products.remove(0)
873-
while len(self.props.cost_item_processes) > 0:
874-
self.props.cost_item_processes.remove(0)
875-
while len(self.props.cost_item_resources) > 0:
876-
self.props.cost_item_resources.remove(0)
867+
self.props.cost_item_products.clear()
868+
self.props.cost_item_processes.clear()
869+
self.props.cost_item_resources.clear()
877870
ifc_definition_id = self.props.cost_items[self.props.active_cost_item_index].ifc_definition_id
878871
for control_id, quantity_ids in Data.cost_items[ifc_definition_id]["Controls"].items():
879872
related_object = self.file.by_id(control_id)
@@ -900,13 +893,10 @@ class LoadCostItemTypes(bpy.types.Operator):
900893
def execute(self, context):
901894
self.props = context.scene.BIMCostProperties
902895
self.file = IfcStore.get_file()
903-
while len(self.props.cost_item_type_products) > 0:
904-
self.props.cost_item_type_products.remove(0)
896+
self.props.cost_item_type_products.clear()
905897
# TODO implement process and resource types
906-
# while len(self.props.cost_item_processes) > 0:
907-
# self.props.cost_item_processes.remove(0)
908-
# while len(self.props.cost_item_resources) > 0:
909-
# self.props.cost_item_resources.remove(0)
898+
# self.props.cost_item_processes.clear()
899+
# self.props.cost_item_resources.clear()
910900
ifc_definition_id = self.props.cost_items[self.props.active_cost_item_index].ifc_definition_id
911901
for control_id, quantity_ids in Data.cost_items[ifc_definition_id]["Controls"].items():
912902
related_object = self.file.by_id(control_id)

src/blenderbim/blenderbim/bim/module/debug/operator.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -197,18 +197,16 @@ def poll(cls, context):
197197

198198
def execute(self, context):
199199
self.file = IfcStore.get_file()
200-
context.scene.BIMDebugProperties.active_step_id = self.step_id
200+
debug_props = context.scene.BIMDebugProperties
201+
debug_props.active_step_id = self.step_id
201202
crumb = context.scene.BIMDebugProperties.step_id_breadcrumb.add()
202203
crumb.name = str(self.step_id)
203204
element = self.file.by_id(self.step_id)
204-
while len(context.scene.BIMDebugProperties.attributes) > 0:
205-
context.scene.BIMDebugProperties.attributes.remove(0)
206-
while len(context.scene.BIMDebugProperties.inverse_attributes) > 0:
207-
context.scene.BIMDebugProperties.inverse_attributes.remove(0)
208-
while len(context.scene.BIMDebugProperties.inverse_references) > 0:
209-
context.scene.BIMDebugProperties.inverse_references.remove(0)
205+
debug_props.attributes.clear()
206+
debug_props.inverse_attributes.clear()
207+
debug_props.inverse_references.clear()
210208
for key, value in element.get_info().items():
211-
self.add_attribute(context.scene.BIMDebugProperties.attributes, key, value)
209+
self.add_attribute(debug_props.attributes, key, value)
212210
for key in dir(element):
213211
if (
214212
not key[0].isalpha()
@@ -217,9 +215,9 @@ def execute(self, context):
217215
or not getattr(element, key)
218216
):
219217
continue
220-
self.add_attribute(context.scene.BIMDebugProperties.inverse_attributes, key, getattr(element, key))
218+
self.add_attribute(debug_props.inverse_attributes, key, getattr(element, key))
221219
for inverse in self.file.get_inverse(element):
222-
new = context.scene.BIMDebugProperties.inverse_references.add()
220+
new = debug_props.inverse_references.add()
223221
new.string_value = str(inverse)
224222
new.int_value = inverse.id()
225223
return {"FINISHED"}

src/blenderbim/blenderbim/bim/module/document/operator.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ class LoadInformation(bpy.types.Operator):
3333
def execute(self, context):
3434
self.file = IfcStore.get_file()
3535
props = context.scene.BIMDocumentProperties
36-
while len(props.documents) > 0:
37-
props.documents.remove(0)
36+
props.documents.clear()
3837
for information_id, information in Data.information.items():
3938
new = props.documents.add()
4039
new.name = information["Name"] or "Unnamed"
@@ -56,8 +55,7 @@ class LoadDocumentReferences(bpy.types.Operator):
5655
def execute(self, context):
5756
self.file = IfcStore.get_file()
5857
props = context.scene.BIMDocumentProperties
59-
while len(props.documents) > 0:
60-
props.documents.remove(0)
58+
props.documents.clear()
6159
for reference_id, reference in Data.references.items():
6260
new = props.documents.add()
6361
new.name = reference["Name"] or "Unnamed"
@@ -90,8 +88,7 @@ class EnableEditingDocument(bpy.types.Operator):
9088

9189
def execute(self, context):
9290
props = context.scene.BIMDocumentProperties
93-
while len(props.document_attributes) > 0:
94-
props.document_attributes.remove(0)
91+
props.document_attributes.clear()
9592

9693
if props.is_editing == "information":
9794
data = Data.information[self.document]

src/blenderbim/blenderbim/bim/module/drawing/operator.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -819,8 +819,7 @@ def execute(self, context):
819819
obj.data.align_y = source.data.align_y
820820
obj.data.BIMTextProperties.font_size = source.data.BIMTextProperties.font_size
821821
obj.data.BIMTextProperties.symbol = source.data.BIMTextProperties.symbol
822-
while len(obj.data.BIMTextProperties.variables) > 0:
823-
obj.data.BIMTextProperties.variables.remove(0)
822+
obj.data.BIMTextProperties.variables.clear()
824823
for variable in source.data.BIMTextProperties.variables:
825824
new_variable = obj.data.BIMTextProperties.variables.add()
826825
new_variable.name = variable.name
@@ -1144,13 +1143,13 @@ class RefreshDrawingList(bpy.types.Operator):
11441143
bl_label = "Refresh Drawing List"
11451144

11461145
def execute(self, context):
1147-
while len(bpy.context.scene.DocProperties.drawings) > 0:
1148-
bpy.context.scene.DocProperties.drawings.remove(0)
1149-
for obj in bpy.context.scene.objects:
1146+
doc_props = context.scene.DocProperties.drawings
1147+
doc_props.drawings.clear()
1148+
for obj in context.scene.objects:
11501149
if not isinstance(obj.data, bpy.types.Camera):
11511150
continue
11521151
if "IfcAnnotation/" in obj.name:
1153-
new = bpy.context.scene.DocProperties.drawings.add()
1152+
new = doc_props.drawings.add()
11541153
new.name = "/".join(obj.name.split("/")[1:])
11551154
new.camera = obj
11561155
return {"FINISHED"}

0 commit comments

Comments
 (0)