mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-26 18:21:59 +00:00
bim.add_representation - option to add default cube representation
Example - https://imgur.com/a/Mklgmhj It can be useful as a way to start working with the representation when object had no representations before. You can also now add a representation from other object even if object had no representation before.
This commit is contained in:
@@ -144,6 +144,14 @@ class AddRepresentation(bpy.types.Operator, Operator):
|
|||||||
),
|
),
|
||||||
("OBJECT", "From Object", "Copies geometry from another object"),
|
("OBJECT", "From Object", "Copies geometry from another object"),
|
||||||
("PROJECT", "Full Representation", "Reuses the current representation"),
|
("PROJECT", "Full Representation", "Reuses the current representation"),
|
||||||
|
(
|
||||||
|
"CUBE",
|
||||||
|
"Cube",
|
||||||
|
(
|
||||||
|
"Add cube representation.\n"
|
||||||
|
"Useful for adding a representation to an object without any representations"
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
name="Representation Conversion Method",
|
name="Representation Conversion Method",
|
||||||
)
|
)
|
||||||
@@ -160,7 +168,7 @@ class AddRepresentation(bpy.types.Operator, Operator):
|
|||||||
original_data = obj.data
|
original_data = obj.data
|
||||||
|
|
||||||
conversion_method = self.representation_conversion_method
|
conversion_method = self.representation_conversion_method
|
||||||
if not original_data:
|
if not original_data and conversion_method not in ("OBJECT", "CUBE"):
|
||||||
self.report(
|
self.report(
|
||||||
{"ERROR"},
|
{"ERROR"},
|
||||||
(f"No mesh data found for the active object. Mesh data required for '{conversion_method}' method."),
|
(f"No mesh data found for the active object. Mesh data required for '{conversion_method}' method."),
|
||||||
@@ -183,13 +191,25 @@ class AddRepresentation(bpy.types.Operator, Operator):
|
|||||||
else:
|
else:
|
||||||
data = tool.Geometry.generate_3d_box_mesh(obj)
|
data = tool.Geometry.generate_3d_box_mesh(obj)
|
||||||
tool.Geometry.change_object_data(obj, data, is_global=True)
|
tool.Geometry.change_object_data(obj, data, is_global=True)
|
||||||
elif conversion_method == "OBJECT":
|
elif conversion_method in ("OBJECT", "CUBE"):
|
||||||
if not props.representation_from_object:
|
if conversion_method == "OBJECT":
|
||||||
self.report({"ERROR"}, "No object is selected to copy a representation from.")
|
if not props.representation_from_object:
|
||||||
return {"FINISHED"}
|
self.report({"ERROR"}, "No object is selected to copy a representation from.")
|
||||||
|
return {"FINISHED"}
|
||||||
|
|
||||||
data = tool.Geometry.duplicate_object_data(props.representation_from_object)
|
data_ = tool.Geometry.duplicate_object_data(props.representation_from_object)
|
||||||
tool.Geometry.change_object_data(obj, data, is_global=True)
|
assert isinstance(data_, bpy.types.Mesh) # Type checker.
|
||||||
|
data = data_
|
||||||
|
else: # CUBE
|
||||||
|
data = bpy.data.meshes.new("Cube")
|
||||||
|
bm = tool.Blender.get_bmesh_for_mesh(data)
|
||||||
|
bmesh.ops.create_cube(bm, size=1)
|
||||||
|
tool.Blender.apply_bmesh(data, bm)
|
||||||
|
|
||||||
|
if original_data:
|
||||||
|
tool.Geometry.change_object_data(obj, data, is_global=True)
|
||||||
|
else:
|
||||||
|
obj = tool.Geometry.recreate_object_with_data(obj, data)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
core.add_representation(
|
core.add_representation(
|
||||||
@@ -202,6 +222,9 @@ class AddRepresentation(bpy.types.Operator, Operator):
|
|||||||
ifc_representation_class=None,
|
ifc_representation_class=None,
|
||||||
profile_set_usage=None,
|
profile_set_usage=None,
|
||||||
)
|
)
|
||||||
|
# Object might be recreated, need to set it as active again.
|
||||||
|
if context.active_object != obj:
|
||||||
|
tool.Blender.set_active_object(obj)
|
||||||
except core.IncompatibleRepresentationError:
|
except core.IncompatibleRepresentationError:
|
||||||
if obj.data != original_data:
|
if obj.data != original_data:
|
||||||
tool.Geometry.change_object_data(obj, original_data, is_global=True)
|
tool.Geometry.change_object_data(obj, original_data, is_global=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user