Skip to content

Commit fc220ef

Browse files
committed
Create UI to switch between views easily
1 parent 6d83815 commit fc220ef

4 files changed

Lines changed: 39 additions & 0 deletions

File tree

src/ifcblenderexport/blenderbim/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
operator.CreateSheets,
8282
operator.GenerateDigitalTwin,
8383
operator.CreateView,
84+
operator.ActivateView,
8485
prop.Subcontext,
8586
prop.BIMProperties,
8687
prop.DocProperties,

src/ifcblenderexport/blenderbim/operator.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,3 +881,22 @@ class GenerateDigitalTwin(bpy.types.Operator):
881881
def execute(self, context):
882882
# Does absolutely nothing at all :D
883883
return {'FINISHED'}
884+
885+
class ActivateView(bpy.types.Operator):
886+
bl_idname = 'bim.activate_view'
887+
bl_label = 'Activate View'
888+
889+
def execute(self, context):
890+
camera = bpy.data.objects.get(bpy.context.scene.DocProperties.available_views)
891+
if not camera:
892+
return {'FINISHED'}
893+
bpy.context.scene.camera = camera
894+
area = next(area for area in bpy.context.screen.areas if area.type == 'VIEW_3D')
895+
area.spaces[0].region_3d.view_perspective = 'CAMERA'
896+
views_collection = bpy.data.collections.get('Views')
897+
for collection in views_collection.children:
898+
bpy.context.view_layer.layer_collection.children['Views'].children[collection.name].hide_viewport = True
899+
bpy.data.collections.get(collection.name).hide_render = True
900+
bpy.context.view_layer.layer_collection.children['Views'].children[camera.users_collection[0].name].hide_viewport = False
901+
bpy.data.collections.get(camera.users_collection[0].name).hide_render = False
902+
return {'FINISHED'}

src/ifcblenderexport/blenderbim/prop.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def __init__(self):
3838
target_views_enum = []
3939
persons_enum = []
4040
organisations_enum = []
41+
views_enum = []
4142

4243
@persistent
4344
def setDefaultProperties(scene):
@@ -209,6 +210,19 @@ def getTargetViews(self, context):
209210
return target_views_enum
210211

211212

213+
def getViews(self, context):
214+
global views_enum
215+
views_enum.clear()
216+
views_collection = bpy.data.collections.get('Views')
217+
if not views_collection:
218+
return views_enum
219+
for collection in views_collection.children:
220+
for obj in collection.objects:
221+
if obj.type == 'CAMERA':
222+
views_enum.append((obj.name, obj.name, ''))
223+
return views_enum
224+
225+
212226
class Subcontext(PropertyGroup):
213227
name: StringProperty(name='Name')
214228
target_view: StringProperty(name='Target View')
@@ -217,6 +231,7 @@ class Subcontext(PropertyGroup):
217231
class DocProperties(PropertyGroup):
218232
should_recut: BoolProperty(name="Should Recut", default=True)
219233
view_name: StringProperty(name="View Name")
234+
available_views: EnumProperty(items=getViews, name="Available Views")
220235

221236

222237
class BIMCameraProperties(PropertyGroup):

src/ifcblenderexport/blenderbim/ui.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ def draw(self, context):
198198
row.prop(props, 'view_name')
199199
row.operator('bim.create_view', icon='ADD', text='')
200200

201+
row = layout.row()
202+
row.prop(props, 'available_views')
203+
row.operator('bim.activate_view', icon='SCENE', text='')
204+
201205
row = layout.row()
202206
row.operator('bim.create_sheets')
203207

0 commit comments

Comments
 (0)