Skip to main content
added 260 characters in body
Source Link
batFINGER
  • 85.2k
  • 10
  • 114
  • 244

Never use Avoid using foo.bar["foo"]bar["Foo"]

With a camera active or pinned, the object of interest in the object data properties tab (camera icon) in the properties panel is theits data part. In the usual case of it being the context object.

Once again use of the scene camera in those operators would make more sense than relying on the camera named "Camera" being the active camera.

A poll method is added to ensure the scene has an active camera. A poll method on your other custom operators could test for active object. If there is no active object and hence they don't poll, the buttons will appear disabled.

Never use foo.bar["foo"]

With a camera active or pinned, the object of interest in the object data properties tab (camera icon) in the properties panel is the data part of the context object.

Once again use of the scene camera in those operators would make more sense than relying on the camera named "Camera" being the active camera.

Avoid using foo.bar["Foo"]

With a camera active or pinned, the object of interest in the object data properties tab (camera icon) in the properties panel is its data. In the usual case of it being the context object.

Once again use of the scene camera in those operators would make more sense than relying on the camera named "Camera" being the active camera.

A poll method is added to ensure the scene has an active camera. A poll method on your other custom operators could test for active object. If there is no active object and hence they don't poll, the buttons will appear disabled.

added 471 characters in body
Source Link
batFINGER
  • 85.2k
  • 10
  • 114
  • 244

Suggest in the case of camera, the active camera is assigned to the scene, scene.camera. As long as this is set can use instead. This is the goto camera used when when pressing Numpad 0 for camera view.

Object Data Properties

With a camera active or pinned, the object of interest in the object data properties tab (camera icon) in the properties panel is the data part of the context object.

>>> C.object
bpy.data.objects['Camera']

>>> C.object.data
bpy.data.cameras['Camera']

>>> C.object.data.dof.aperture_fstop
44.41624069213867

>>> C.scene.camera
bpy.data.objects['Camera']

Putting it all together

Suggest in the case of camera, the active camera is assigned to the scene, scene.camera. As long as this is set can use instead. This is the camera used when pressing Numpad 0 for camera view.

Suggest in the case of camera, the active camera is assigned to the scene, scene.camera. As long as this is set can use instead. This is the goto camera when pressing Numpad 0 for camera view.

Object Data Properties

With a camera active or pinned, the object of interest in the object data properties tab (camera icon) in the properties panel is the data part of the context object.

>>> C.object
bpy.data.objects['Camera']

>>> C.object.data
bpy.data.cameras['Camera']

>>> C.object.data.dof.aperture_fstop
44.41624069213867

>>> C.scene.camera
bpy.data.objects['Camera']

Putting it all together

deleted 3 characters in body
Source Link
batFINGER
  • 85.2k
  • 10
  • 114
  • 244

which will fail (throw a KeyError) if there is no object named camera, which could simply mean its been renamed, or is camera in a different language etc. It could be the camera linked to another scene, or no scene at all... in which case sliding it would appear to do nought.

Suggest in the case of camera, the active camera is assigned to the scene, scene.camera. As long as this is set can use instead. This is the camera used when pressing Numpad 0 for camera view.

import bpy

class VIEW3D_PT_dof(bpy.types.Panel):
    bl_idname = "VIEW3D_PT_dof"
    bl_label = "Quick Focus"
    bl_category = "DOF"
    bl_space_type = "VIEW_3D"'VIEW_3D'
    bl_region_type = "UI"'UI'
 
    @classmethod
    def poll(cls, context):
        return context.scene.comaeracamera is not None
    
    def draw_header(self, context):
        layout = self.layout
        layout.label(icon = "CAMERA_DATA"icon='CAMERA_DATA')
        
    def draw(self, context):
        layout = self.layout
                
        cam = context.scene.camera
        col = layout.column()     
        #col.label(text= "Focus", icon="CAMERA_DATA"icon='CAMERA_DATA')
        col.operator("wm.splash")
        col.operator("wm.splash")
        col.prop(cam.data.dof, "aperture_fstop", slider=True)
        

classes = (
        VIEW3D_PT_dof,
        )          
        
def register():
    for cls in classes:
        bpy.utils.register_class(cls)

def unregister():
    for cls in reversed(classes):
        bpy.utils.unregister_class(cls)


if __name__ == "__main__":
    register()

which will fail (throw a KeyError) if there is no object named camera, which could simply mean its been renamed, or is camera in a different language etc.

Suggest in the case of camera, the active camera is assigned to the scene, scene.camera. As long as this is set can use instead.

import bpy

class VIEW3D_PT_dof(bpy.types.Panel):
    bl_idname = "VIEW3D_PT_dof"
    bl_label = "Quick Focus"
    bl_category = "DOF"
    bl_space_type = "VIEW_3D"
    bl_region_type = "UI"
 
    @classmethod
    def poll(cls, context):
        return context.scene.comaera is not None
    
    def draw_header(self, context):
        layout = self.layout
        layout.label(icon = "CAMERA_DATA")
        
    def draw(self, context):
        layout = self.layout
                
        cam = context.scene.camera
        col = layout.column()     
        #col.label(text= "Focus", icon="CAMERA_DATA")
        col.operator("wm.splash")
        col.operator("wm.splash")
        col.prop(cam.data.dof, "aperture_fstop", slider=True)
        

classes = (
        VIEW3D_PT_dof,
        )          
        
def register():
    for cls in classes:
        bpy.utils.register_class(cls)

def unregister():
    for cls in reversed(classes):
        bpy.utils.unregister_class(cls)


if __name__ == "__main__":
    register()

which will fail (throw a KeyError) if there is no object named camera, which could simply mean its been renamed, or is camera in a different language etc. It could be the camera linked to another scene, or no scene at all... in which case sliding it would appear to do nought.

Suggest in the case of camera, the active camera is assigned to the scene, scene.camera. As long as this is set can use instead. This is the camera used when pressing Numpad 0 for camera view.

import bpy

class VIEW3D_PT_dof(bpy.types.Panel):
    bl_idname = "VIEW3D_PT_dof"
    bl_label = "Quick Focus"
    bl_category = "DOF"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'
 
    @classmethod
    def poll(cls, context):
        return context.scene.camera is not None
    
    def draw_header(self, context):
        layout = self.layout
        layout.label(icon='CAMERA_DATA')
        
    def draw(self, context):
        layout = self.layout
                
        cam = context.scene.camera
        col = layout.column()     
        #col.label(text= "Focus", icon='CAMERA_DATA')
        col.operator("wm.splash")
        col.operator("wm.splash")
        col.prop(cam.data.dof, "aperture_fstop", slider=True)
        

classes = (
        VIEW3D_PT_dof,
        )          
        
def register():
    for cls in classes:
        bpy.utils.register_class(cls)

def unregister():
    for cls in reversed(classes):
        bpy.utils.unregister_class(cls)


if __name__ == "__main__":
    register()
Source Link
batFINGER
  • 85.2k
  • 10
  • 114
  • 244
Loading