Files
IfcOpenShell/src/ifcblenderexport/blenderbim/bim/module/model/grid.py
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

89 lines
3.2 KiB
Python
Raw Normal View History

import bpy
from bpy.types import Operator
2020-11-13 15:50:37 +07:00
from bpy.props import FloatProperty, IntProperty
from bpy_extras.object_utils import AddObjectHelper, object_data_add
from mathutils import Vector
2020-11-01 20:08:48 +07:00
def add_object(self, context):
obj = object_data_add(context, None, operator=self)
2020-11-01 20:08:48 +07:00
obj.name = "IfcGrid/Grid"
name = obj.name.split("/")[1]
default_collection = obj.users_collection[0]
default_collection.objects.unlink(obj)
2020-11-01 20:08:48 +07:00
collection = bpy.data.collections.new("IfcGrid/" + name)
has_site_collection = False
for child in bpy.context.view_layer.layer_collection.children:
if "IfcProject/" not in child.name:
continue
for grandchild in child.children:
if "IfcSite/" not in grandchild.name:
continue
has_site_collection = True
grandchild.collection.children.link(collection)
break
if not has_site_collection:
bpy.context.view_layer.active_layer_collection.collection.children.link(collection)
collection.objects.link(obj)
2020-11-01 20:08:48 +07:00
axes_collection = bpy.data.collections.new("UAxes")
collection.children.link(axes_collection)
for i in range(0, self.total_u):
2020-11-01 20:08:48 +07:00
verts = [
Vector((-2, i * self.u_spacing, 0)),
Vector((((self.total_v - 1) * self.v_spacing) + 2, i * self.u_spacing, 0)),
]
edges = [[0, 1]]
faces = []
mesh = bpy.data.meshes.new(name="Grid Axis")
mesh.from_pydata(verts, edges, faces)
obj = object_data_add(context, mesh, operator=self)
2020-11-01 20:08:48 +07:00
tag = chr(ord("A") + i)
obj.name = "IfcGridAxis/" + tag
default_collection.objects.unlink(obj)
axes_collection.objects.link(obj)
attribute = obj.BIMObjectProperties.attributes.add()
2020-11-01 20:08:48 +07:00
attribute.name = "AxisTag"
attribute.string_value = tag
2020-11-01 20:08:48 +07:00
axes_collection = bpy.data.collections.new("VAxes")
collection.children.link(axes_collection)
for i in range(0, self.total_v):
2020-11-01 20:08:48 +07:00
verts = [
Vector((i * self.v_spacing, -2, 0)),
Vector((i * self.v_spacing, ((self.total_u - 1) * self.u_spacing) + 2, 0)),
]
edges = [[0, 1]]
faces = []
mesh = bpy.data.meshes.new(name="Grid Axis")
mesh.from_pydata(verts, edges, faces)
obj = object_data_add(context, mesh, operator=self)
2020-11-01 20:08:48 +07:00
tag = str(i + 1).zfill(2)
obj.name = "IfcGridAxis/" + tag
default_collection.objects.unlink(obj)
axes_collection.objects.link(obj)
attribute = obj.BIMObjectProperties.attributes.add()
2020-11-01 20:08:48 +07:00
attribute.name = "AxisTag"
attribute.string_value = tag
class BIM_OT_add_object(Operator, AddObjectHelper):
bl_idname = "mesh.add_grid"
bl_label = "Grid"
2020-11-01 20:08:48 +07:00
bl_options = {"REGISTER", "UNDO"}
2020-11-01 20:08:48 +07:00
u_spacing: FloatProperty(name="U Spacing", default=10)
total_u: IntProperty(name="Number of U Grids", default=3)
v_spacing: FloatProperty(name="V Spacing", default=10)
total_v: IntProperty(name="Number of V Grids", default=3)
def execute(self, context):
add_object(self, context)
2020-11-01 20:08:48 +07:00
return {"FINISHED"}
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")