You can now copy a representation from one object to another

This commit is contained in:
Dion Moult
2021-10-15 13:21:31 +11:00
parent d666a687dc
commit 07bfe296dd
5 changed files with 49 additions and 15 deletions
@@ -20,13 +20,14 @@ import bpy
from . import ui, prop, operator
classes = (
operator.EditObjectPlacement,
operator.AddRepresentation,
operator.SwitchRepresentation,
operator.RemoveRepresentation,
operator.UpdateRepresentation,
operator.UpdateParametricRepresentation,
operator.CopyRepresentation,
operator.EditObjectPlacement,
operator.GetRepresentationIfcParameters,
operator.RemoveRepresentation,
operator.SwitchRepresentation,
operator.UpdateParametricRepresentation,
operator.UpdateRepresentation,
prop.BIMGeometryProperties,
ui.BIM_PT_derived_placements,
ui.BIM_PT_representations,
@@ -17,16 +17,18 @@
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
import bpy
import bmesh
import logging
import numpy as np
import ifcopenshell
import ifcopenshell.util.unit
import ifcopenshell.util.element
import ifcopenshell.util.representation
import logging
import ifcopenshell.api
import blenderbim.core.geometry as core
import blenderbim.core.style
import blenderbim.tool as tool
import blenderbim.bim.handler
from blenderbim.bim.ifc import IfcStore
from blenderbim.bim import import_ifc
from ifcopenshell.api.geometry.data import Data
@@ -38,6 +40,7 @@ from mathutils import Vector
class Operator:
def execute(self, context):
IfcStore.execute_ifc_operator(self, context)
blenderbim.bim.handler.refresh_ui_data()
return {"FINISHED"}
@@ -53,7 +56,7 @@ class EditObjectPlacement(bpy.types.Operator, Operator):
core.edit_object_placement(tool.Ifc, tool.Surveyor, obj=obj)
class AddRepresentation(bpy.types.Operator):
class AddRepresentation(bpy.types.Operator, Operator):
bl_idname = "bim.add_representation"
bl_label = "Add Representation"
bl_options = {"REGISTER", "UNDO"}
@@ -62,9 +65,6 @@ class AddRepresentation(bpy.types.Operator):
ifc_representation_class: bpy.props.StringProperty()
profile_set_usage: bpy.props.IntProperty()
def execute(self, context):
return IfcStore.execute_ifc_operator(self, context)
def _execute(self, context):
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object
self.file = IfcStore.get_file()
@@ -232,16 +232,13 @@ class SwitchRepresentation(bpy.types.Operator):
self.element_obj.modifiers.remove(modifier)
class RemoveRepresentation(bpy.types.Operator):
class RemoveRepresentation(bpy.types.Operator, Operator):
bl_idname = "bim.remove_representation"
bl_label = "Remove Representation"
bl_options = {"REGISTER", "UNDO"}
obj: bpy.props.StringProperty()
representation_id: bpy.props.IntProperty()
def execute(self, context):
return IfcStore.execute_ifc_operator(self, context)
def _execute(self, context):
self.file = IfcStore.get_file()
representation = self.file.by_id(self.representation_id)
@@ -415,3 +412,22 @@ class GetRepresentationIfcParameters(bpy.types.Operator):
if element[i]:
new.value = element[i]
return {"FINISHED"}
class CopyRepresentation(bpy.types.Operator, Operator):
bl_idname = "bim.copy_representation"
bl_label = "Copy Representation"
bl_options = {"REGISTER", "UNDO"}
obj: bpy.props.StringProperty()
def _execute(self, context):
if not context.active_object:
return
bm = bmesh.new()
bm.from_mesh(context.active_object.data)
for obj in context.selected_objects:
if obj == context.active_object:
continue
if obj.data:
bm.to_mesh(obj.data)
bpy.ops.bim.add_representation(obj=obj.name)
@@ -102,6 +102,9 @@ class BIM_PT_mesh(Panel):
op.ifc_definition_id = props.ifc_definition_id
op.disable_opening_subtractions = True
row = layout.row()
row.operator("bim.copy_representation")
row = layout.row()
row.operator("bim.update_representation")
@@ -1,6 +1,5 @@
@geometry
Feature: Geometry
Covers geometry and coordinate manipulation
Scenario: Edit object placement
Given an empty IFC project
@@ -11,3 +10,17 @@ Scenario: Edit object placement
And the object "IfcWall/Cube" is selected
When I press "bim.edit_object_placement"
Then nothing happens
Scenario: Copy representation
Given an empty IFC project
And I add a cube
And the object "Cube" is selected
And I set "scene.BIMRootProperties.ifc_class" to "IfcWall"
And I press "bim.assign_class"
And I add a cube
And the object "Cube" is selected
And I press "bim.assign_class"
And the object "IfcWall/Cube" is selected
And additionally the object "IfcWall/Cube.001" is selected
When I press "bim.copy_representation"
Then nothing happens
+1
View File
@@ -105,6 +105,7 @@ def the_object_name_is_selected(name):
additionally_the_object_name_is_selected(name)
@given(parsers.parse('additionally the object "{name}" is selected'))
@when(parsers.parse('additionally the object "{name}" is selected'))
def additionally_the_object_name_is_selected(name):
obj = bpy.context.scene.objects.get(name)