You can now easily create orthographic and perspective model drawings from a preset

This commit is contained in:
Dion Moult
2023-10-06 10:43:47 +11:00
parent 69e447be1c
commit 88d96f7d57
5 changed files with 14 additions and 5 deletions
@@ -123,6 +123,8 @@ class DrawingsData:
[(str(s.id()), s.Name or "Unnamed", "") for s in tool.Ifc.get().by_type("IfcBuildingStorey")] [(str(s.id()), s.Name or "Unnamed", "") for s in tool.Ifc.get().by_type("IfcBuildingStorey")]
) )
return results return results
elif bpy.context.scene.DocProperties.target_view in ["MODEL_VIEW"]:
return [(h.upper(), h, "") for h in ["Orthographic", "Perspective"]]
return [(h.upper(), h, "") for h in ["North", "South", "East", "West"]] return [(h.upper(), h, "") for h in ["North", "South", "East", "West"]]
@classmethod @classmethod
+1 -1
View File
@@ -190,7 +190,7 @@ def disable_editing_drawings(drawing):
def add_drawing(ifc, collector, drawing, target_view=None, location_hint=None): def add_drawing(ifc, collector, drawing, target_view=None, location_hint=None):
drawing_name = drawing.ensure_unique_drawing_name(drawing.generate_drawing_name(target_view, location_hint)) drawing_name = drawing.ensure_unique_drawing_name(drawing.generate_drawing_name(target_view, location_hint))
drawing_matrix = drawing.generate_drawing_matrix(target_view, location_hint) drawing_matrix = drawing.generate_drawing_matrix(target_view, location_hint)
camera = drawing.create_camera(drawing_name, drawing_matrix) camera = drawing.create_camera(drawing_name, drawing_matrix, location_hint)
element = drawing.run_root_assign_class( element = drawing.run_root_assign_class(
obj=camera, obj=camera,
ifc_class="IfcAnnotation", ifc_class="IfcAnnotation",
+1 -1
View File
@@ -253,7 +253,7 @@ class Drawing:
def copy_representation(cls, source, dest): pass def copy_representation(cls, source, dest): pass
def create_annotation_context(cls, target_view, object_type=None): pass def create_annotation_context(cls, target_view, object_type=None): pass
def create_annotation_object(cls, drawing, object_type): pass def create_annotation_object(cls, drawing, object_type): pass
def create_camera(cls, name, matrix): pass def create_camera(cls, name, matrix, location_hint): pass
def create_svg_schedule(cls, schedule): pass def create_svg_schedule(cls, schedule): pass
def create_svg_sheet(cls, document, titleblock): pass def create_svg_sheet(cls, document, titleblock): pass
def delete_collection(cls, collection): pass def delete_collection(cls, collection): pass
+9 -2
View File
@@ -205,11 +205,14 @@ class Drawing(blenderbim.core.tool.Drawing):
return rep return rep
@classmethod @classmethod
def create_camera(cls, name, matrix): def create_camera(cls, name, matrix, location_hint):
camera = bpy.data.objects.new(name, bpy.data.cameras.new(name)) camera = bpy.data.objects.new(name, bpy.data.cameras.new(name))
camera.location = (0, 0, 1.5) # The view shall be 1.5m above the origin camera.location = (0, 0, 1.5) # The view shall be 1.5m above the origin
camera.data.show_limits = True camera.data.show_limits = True
camera.data.type = "ORTHO" if location_hint == "PERSPECTIVE":
camera.data.type = "PERSP"
else:
camera.data.type = "ORTHO"
camera.data.ortho_scale = 50 # The default of 6m is too small camera.data.ortho_scale = 50 # The default of 6m is too small
camera.data.clip_start = 0.002 # 2mm is close to zero but allows any GPU-drawn lines to be visible. camera.data.clip_start = 0.002 # 2mm is close to zero but allows any GPU-drawn lines to be visible.
camera.data.clip_end = 10 # A slightly more reasonable default camera.data.clip_end = 10 # A slightly more reasonable default
@@ -487,6 +490,8 @@ class Drawing(blenderbim.core.tool.Drawing):
return mathutils.Matrix(((0, 0, -1, x), (-1, 0, 0, y), (0, 1, 0, z), (0, 0, 0, 1))) return mathutils.Matrix(((0, 0, -1, x), (-1, 0, 0, y), (0, 1, 0, z), (0, 0, 0, 1)))
elif location_hint == "WEST": elif location_hint == "WEST":
return mathutils.Matrix(((0, 0, 1, x), (1, 0, 0, y), (0, 1, 0, z), (0, 0, 0, 1))) return mathutils.Matrix(((0, 0, 1, x), (1, 0, 0, y), (0, 1, 0, z), (0, 0, 0, 1)))
elif target_view == "MODEL_VIEW":
return mathutils.Matrix(((1, 0, 0, x), (0, 1, 0, y), (0, 0, 1, z), (0, 0, 0, 1)))
return mathutils.Matrix() return mathutils.Matrix()
@classmethod @classmethod
@@ -954,6 +959,8 @@ class Drawing(blenderbim.core.tool.Drawing):
return (location.Name or "UNNAMED").upper() + " " + target_view.split("_")[0] return (location.Name or "UNNAMED").upper() + " " + target_view.split("_")[0]
elif target_view in ("SECTION_VIEW", "ELEVATION_VIEW") and location_hint: elif target_view in ("SECTION_VIEW", "ELEVATION_VIEW") and location_hint:
return location_hint + " " + target_view.split("_")[0] return location_hint + " " + target_view.split("_")[0]
elif target_view == "MODEL_VIEW" and location_hint:
return location_hint
return target_view return target_view
@classmethod @classmethod
+1 -1
View File
@@ -311,7 +311,7 @@ class TestAddDrawing:
drawing.generate_drawing_name("target_view", "location_hint").should_be_called().will_return("drawing_name") drawing.generate_drawing_name("target_view", "location_hint").should_be_called().will_return("drawing_name")
drawing.ensure_unique_drawing_name("drawing_name").should_be_called().will_return("name") drawing.ensure_unique_drawing_name("drawing_name").should_be_called().will_return("name")
drawing.generate_drawing_matrix("target_view", "location_hint").should_be_called().will_return("matrix") drawing.generate_drawing_matrix("target_view", "location_hint").should_be_called().will_return("matrix")
drawing.create_camera("name", "matrix").should_be_called().will_return("obj") drawing.create_camera("name", "matrix", "location_hint").should_be_called().will_return("obj")
drawing.get_body_context().should_be_called().will_return("context") drawing.get_body_context().should_be_called().will_return("context")
drawing.run_root_assign_class( drawing.run_root_assign_class(
obj="obj", obj="obj",