Create UI to switch between views easily

This commit is contained in:
Dion Moult
2020-01-06 14:30:44 +11:00
parent 6d83815ab1
commit fc220efb6c
4 changed files with 39 additions and 0 deletions
@@ -81,6 +81,7 @@ if bpy is not None:
operator.CreateSheets,
operator.GenerateDigitalTwin,
operator.CreateView,
operator.ActivateView,
prop.Subcontext,
prop.BIMProperties,
prop.DocProperties,
@@ -881,3 +881,22 @@ class GenerateDigitalTwin(bpy.types.Operator):
def execute(self, context):
# Does absolutely nothing at all :D
return {'FINISHED'}
class ActivateView(bpy.types.Operator):
bl_idname = 'bim.activate_view'
bl_label = 'Activate View'
def execute(self, context):
camera = bpy.data.objects.get(bpy.context.scene.DocProperties.available_views)
if not camera:
return {'FINISHED'}
bpy.context.scene.camera = camera
area = next(area for area in bpy.context.screen.areas if area.type == 'VIEW_3D')
area.spaces[0].region_3d.view_perspective = 'CAMERA'
views_collection = bpy.data.collections.get('Views')
for collection in views_collection.children:
bpy.context.view_layer.layer_collection.children['Views'].children[collection.name].hide_viewport = True
bpy.data.collections.get(collection.name).hide_render = True
bpy.context.view_layer.layer_collection.children['Views'].children[camera.users_collection[0].name].hide_viewport = False
bpy.data.collections.get(camera.users_collection[0].name).hide_render = False
return {'FINISHED'}
+15
View File
@@ -38,6 +38,7 @@ subcontexts_enum = []
target_views_enum = []
persons_enum = []
organisations_enum = []
views_enum = []
@persistent
def setDefaultProperties(scene):
@@ -209,6 +210,19 @@ def getTargetViews(self, context):
return target_views_enum
def getViews(self, context):
global views_enum
views_enum.clear()
views_collection = bpy.data.collections.get('Views')
if not views_collection:
return views_enum
for collection in views_collection.children:
for obj in collection.objects:
if obj.type == 'CAMERA':
views_enum.append((obj.name, obj.name, ''))
return views_enum
class Subcontext(PropertyGroup):
name: StringProperty(name='Name')
target_view: StringProperty(name='Target View')
@@ -217,6 +231,7 @@ class Subcontext(PropertyGroup):
class DocProperties(PropertyGroup):
should_recut: BoolProperty(name="Should Recut", default=True)
view_name: StringProperty(name="View Name")
available_views: EnumProperty(items=getViews, name="Available Views")
class BIMCameraProperties(PropertyGroup):
+4
View File
@@ -198,6 +198,10 @@ class BIM_PT_documentation(Panel):
row.prop(props, 'view_name')
row.operator('bim.create_view', icon='ADD', text='')
row = layout.row()
row.prop(props, 'available_views')
row.operator('bim.activate_view', icon='SCENE', text='')
row = layout.row()
row.operator('bim.create_sheets')