2020-08-21 20:38:57 +10:00
|
|
|
import bpy
|
|
|
|
|
import bmesh
|
|
|
|
|
from bpy.types import Operator
|
|
|
|
|
from bpy.props import FloatVectorProperty, FloatProperty, IntProperty
|
|
|
|
|
from bpy_extras.object_utils import AddObjectHelper, object_data_add
|
|
|
|
|
from mathutils import Vector
|
|
|
|
|
|
2020-11-01 20:08:48 +07:00
|
|
|
|
2020-08-21 20:38:57 +10:00
|
|
|
def add_object(self, context):
|
|
|
|
|
bm = bmesh.new()
|
|
|
|
|
bmesh.ops.create_cube(bm, size=self.size)
|
|
|
|
|
bm.verts.ensure_lookup_table()
|
|
|
|
|
bm.edges.ensure_lookup_table()
|
|
|
|
|
bm.faces.ensure_lookup_table()
|
|
|
|
|
mesh = bpy.data.meshes.new(name="Dumb Opening")
|
|
|
|
|
bm.to_mesh(mesh)
|
|
|
|
|
bm.free()
|
|
|
|
|
obj = object_data_add(context, mesh, operator=self)
|
2020-11-01 20:08:48 +07:00
|
|
|
obj.name = "IfcOpening/Dumb Opening"
|
|
|
|
|
obj.display_type = "WIRE"
|
2020-08-21 20:38:57 +10:00
|
|
|
attribute = obj.BIMObjectProperties.attributes.add()
|
2020-11-01 20:08:48 +07:00
|
|
|
attribute.name = "PredefinedType"
|
|
|
|
|
attribute.string_value = "OPENING"
|
2020-08-21 20:38:57 +10:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class BIM_OT_add_object(Operator, AddObjectHelper):
|
|
|
|
|
bl_idname = "mesh.add_opening"
|
|
|
|
|
bl_label = "Dumb Opening"
|
2020-11-01 20:08:48 +07:00
|
|
|
bl_options = {"REGISTER", "UNDO"}
|
2020-08-21 20:38:57 +10:00
|
|
|
|
2020-11-01 20:08:48 +07:00
|
|
|
size: FloatProperty(name="Size", default=2)
|
2020-08-21 20:38:57 +10:00
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
|
add_object(self, context)
|
2020-11-01 20:08:48 +07:00
|
|
|
return {"FINISHED"}
|
2020-08-21 20:38:57 +10:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def add_object_button(self, context):
|
2020-11-01 20:08:48 +07:00
|
|
|
self.layout.operator(BIM_OT_add_object.bl_idname, icon="PLUGIN")
|