mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-26 10:11:46 +00:00
New debug utility to purge all Blender IFC links. See #1599.
This commit is contained in:
@@ -3,6 +3,7 @@ from . import ui, prop, operator
|
|||||||
|
|
||||||
classes = (
|
classes = (
|
||||||
operator.PrintIfcFile,
|
operator.PrintIfcFile,
|
||||||
|
operator.PurgeIfcLinks,
|
||||||
operator.PrintObjectPlacement,
|
operator.PrintObjectPlacement,
|
||||||
operator.ValidateIfcFile,
|
operator.ValidateIfcFile,
|
||||||
operator.ProfileImportIFC,
|
operator.ProfileImportIFC,
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ import bpy
|
|||||||
import logging
|
import logging
|
||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
import ifcopenshell.util.placement
|
import ifcopenshell.util.placement
|
||||||
|
import ifcopenshell.util.representation
|
||||||
|
import blenderbim.bim.handler
|
||||||
import blenderbim.bim.import_ifc as import_ifc
|
import blenderbim.bim.import_ifc as import_ifc
|
||||||
from blenderbim.bim.ifc import IfcStore
|
from blenderbim.bim.ifc import IfcStore
|
||||||
|
|
||||||
@@ -15,6 +17,24 @@ class PrintIfcFile(bpy.types.Operator):
|
|||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
|
class PurgeIfcLinks(bpy.types.Operator):
|
||||||
|
bl_idname = "bim.purge_ifc_links"
|
||||||
|
bl_label = "Purge IFC Links"
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
for obj in bpy.data.objects:
|
||||||
|
if obj.type in {"MESH", "EMPTY"}:
|
||||||
|
obj.BIMObjectProperties.ifc_definition_id = 0
|
||||||
|
if obj.data:
|
||||||
|
obj.data.BIMMeshProperties.ifc_definition_id = 0
|
||||||
|
for material in bpy.data.materials:
|
||||||
|
material.BIMMaterialProperties.ifc_style_id = False
|
||||||
|
bpy.context.scene.BIMProperties.ifc_file = ""
|
||||||
|
IfcStore.purge()
|
||||||
|
blenderbim.bim.handler.purge_module_data()
|
||||||
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
class ValidateIfcFile(bpy.types.Operator):
|
class ValidateIfcFile(bpy.types.Operator):
|
||||||
bl_idname = "bim.validate_ifc_file"
|
bl_idname = "bim.validate_ifc_file"
|
||||||
bl_label = "Validate IFC File"
|
bl_label = "Validate IFC File"
|
||||||
@@ -37,11 +57,9 @@ class ProfileImportIFC(bpy.types.Operator):
|
|||||||
import pstats
|
import pstats
|
||||||
|
|
||||||
# For Windows
|
# For Windows
|
||||||
filepath = bpy.context.scene.BIMProperties.ifc_file.replace('\\', '\\\\')
|
filepath = bpy.context.scene.BIMProperties.ifc_file.replace("\\", "\\\\")
|
||||||
|
|
||||||
cProfile.run(
|
cProfile.run(f"import bpy; bpy.ops.import_ifc.bim(filepath='{filepath}')", "blender.prof")
|
||||||
f"import bpy; bpy.ops.import_ifc.bim(filepath='{filepath}')", "blender.prof"
|
|
||||||
)
|
|
||||||
p = pstats.Stats("blender.prof")
|
p = pstats.Stats("blender.prof")
|
||||||
p.sort_stats("cumulative").print_stats(50)
|
p.sort_stats("cumulative").print_stats(50)
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
@@ -57,18 +75,18 @@ class CreateAllShapes(bpy.types.Operator):
|
|||||||
total = len(elements)
|
total = len(elements)
|
||||||
settings = ifcopenshell.geom.settings()
|
settings = ifcopenshell.geom.settings()
|
||||||
failures = []
|
failures = []
|
||||||
excludes = () # For the developer to debug with
|
excludes = () # For the developer to debug with
|
||||||
for i, element in enumerate(elements):
|
for i, element in enumerate(elements):
|
||||||
if element.GlobalId in excludes:
|
if element.GlobalId in excludes:
|
||||||
continue
|
continue
|
||||||
print(f'{i}/{total}:', element)
|
print(f"{i}/{total}:", element)
|
||||||
try:
|
try:
|
||||||
shape = ifcopenshell.geom.create_shape(settings, element)
|
shape = ifcopenshell.geom.create_shape(settings, element)
|
||||||
print("Success", len(shape.geometry.verts), len(shape.geometry.edges), len(shape.geometry.faces))
|
print("Success", len(shape.geometry.verts), len(shape.geometry.edges), len(shape.geometry.faces))
|
||||||
except:
|
except:
|
||||||
failures.append(element)
|
failures.append(element)
|
||||||
print('***** FAILURE *****')
|
print("***** FAILURE *****")
|
||||||
print('Failures:')
|
print("Failures:")
|
||||||
for failure in failures:
|
for failure in failures:
|
||||||
print(failure)
|
print(failure)
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|||||||
@@ -23,6 +23,9 @@ class BIM_PT_debug(Panel):
|
|||||||
row = layout.row()
|
row = layout.row()
|
||||||
row.operator("bim.print_ifc_file")
|
row.operator("bim.print_ifc_file")
|
||||||
|
|
||||||
|
row = layout.row()
|
||||||
|
row.operator("bim.purge_ifc_links")
|
||||||
|
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
row.operator("bim.create_all_shapes")
|
row.operator("bim.create_all_shapes")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user