mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 09:21:46 +00:00
bim.switch_representation to switch to exact representation
previously it was switching to the first representation that matches the context, so it wasn't possible to switch to the second one if you had more than 1 representation in the same context using always both element and representation in `geometry.import_representation` so it will import the exact representation and not the first one found by `ifcopenshell.geom.create_shape`
This commit is contained in:
@@ -211,18 +211,22 @@ class SwitchRepresentation(bpy.types.Operator, Operator):
|
||||
should_switch_all_meshes: bpy.props.BoolProperty()
|
||||
|
||||
def _execute(self, context):
|
||||
target = tool.Ifc.get().by_id(self.ifc_definition_id).ContextOfItems
|
||||
target_representation = tool.Ifc.get().by_id(self.ifc_definition_id)
|
||||
target = target_representation.ContextOfItems
|
||||
is_subcontext = target.is_a("IfcGeometricRepresentationSubContext")
|
||||
for obj in set(context.selected_objects + [context.active_object]):
|
||||
element = tool.Ifc.get_entity(obj)
|
||||
if not element:
|
||||
continue
|
||||
if is_subcontext:
|
||||
representation = ifcopenshell.util.representation.get_representation(
|
||||
element, target.ContextType, target.ContextIdentifier, target.TargetView
|
||||
)
|
||||
if obj == context.active_object:
|
||||
representation = target_representation
|
||||
else:
|
||||
representation = ifcopenshell.util.representation.get_representation(element, target.ContextType)
|
||||
if is_subcontext:
|
||||
representation = ifcopenshell.util.representation.get_representation(
|
||||
element, target.ContextType, target.ContextIdentifier, target.TargetView
|
||||
)
|
||||
else:
|
||||
representation = ifcopenshell.util.representation.get_representation(element, target.ContextType)
|
||||
if not representation:
|
||||
continue
|
||||
core.switch_representation(
|
||||
|
||||
@@ -479,23 +479,19 @@ class Geometry(blenderbim.core.tool.Geometry):
|
||||
element = tool.Ifc.get_entity(obj)
|
||||
settings = ifcopenshell.geom.settings()
|
||||
settings.set(settings.WELD_VERTICES, True)
|
||||
|
||||
context = representation.ContextOfItems
|
||||
if element.is_a("IfcTypeProduct") or not apply_openings:
|
||||
settings.set(settings.DISABLE_OPENING_SUBTRACTIONS, True)
|
||||
|
||||
if context.ContextIdentifier == "Body" and context.TargetView == "MODEL_VIEW":
|
||||
try:
|
||||
if element.is_a("IfcTypeProduct") or not apply_openings:
|
||||
shape = ifcopenshell.geom.create_shape(settings, representation)
|
||||
else:
|
||||
shape = ifcopenshell.geom.create_shape(settings, element)
|
||||
shape = ifcopenshell.geom.create_shape(settings, element, representation)
|
||||
except:
|
||||
settings.set(settings.INCLUDE_CURVES, True)
|
||||
if element.is_a("IfcTypeProduct") or not apply_openings:
|
||||
shape = ifcopenshell.geom.create_shape(settings, representation)
|
||||
else:
|
||||
shape = ifcopenshell.geom.create_shape(settings, element)
|
||||
shape = ifcopenshell.geom.create_shape(settings, element, representation)
|
||||
else:
|
||||
settings.set(settings.INCLUDE_CURVES, True)
|
||||
shape = ifcopenshell.geom.create_shape(settings, representation)
|
||||
shape = ifcopenshell.geom.create_shape(settings, element, representation)
|
||||
|
||||
ifc_importer = blenderbim.bim.import_ifc.IfcImporter(ifc_import_settings)
|
||||
ifc_importer.file = tool.Ifc.get()
|
||||
|
||||
Reference in New Issue
Block a user