if I want these classes to be called by other plugins, like Pie Menu Editor addon, What code should I add?
import bpy
class Cam_Base(bpy.types.Operator):
bl_idname = "cam.base"
bl_label = "Cam Base"
cam_name = "C_"
def execute(self, context):
C = bpy.context
# lock cam
bpy.context.object.lock_scale = (True, True, True)
bpy.context.object.lock_rotation = (True, True, True)
bpy.context.object.lock_location = (True, True, True)
# select cam
bpy.context.space_data.camera = bpy.data.objects[self.cam_name]
# Select Active Cam
for area in C.screen.areas:
if area.type == 'VIEW_3D':
A = C.area.spaces.active.camera
bpy.context.scene.camera = bpy.data.objects[A.name]
bpy.context.space_data.shading.color_type = 'OBJECT'
bpy.context.space_data.region_3d.view_perspective = 'CAMERA'
#############Supplementary Code################
#Modify camera attributes
bpy.data.objects[A.name].lock_scale[0] = True
bpy.data.objects[A.name].lock_scale[1] = True
bpy.data.objects[A.name].lock_scale[2] = True
bpy.data.objects[A.name].lock_location[0] = True
bpy.data.objects[A.name].lock_location[1] = True
bpy.data.objects[A.name].lock_location[2] = True
bpy.data.objects[A.name].lock_rotation[0] = True
bpy.data.objects[A.name].lock_rotation[1] = True
bpy.data.objects[A.name].lock_rotation[2] = True
bpy.data.objects[A.name].scale[0] = 1
bpy.data.objects[A.name].scale[1] = 1
bpy.data.objects[A.name].scale[2] = 1
bpy.data.cameras[A.name].display_size = 0.05
bpy.data.cameras[A.name].background_images[0].alpha = 0
bpy.data.cameras[A.name].dof.use_dof = False
bpy.data.cameras[A.name].clip_start = 25
bpy.data.cameras[A.name].clip_end = 100000
bpy.data.cameras[A.name].background_images[0].scale = 1
bpy.data.cameras[A.name].background_images[1].scale = 1
bpy.data.cameras[A.name].background_images[2].scale = 1
bpy.ops.view3d.view_center_camera()
bpy.ops.image.reload()
#select camera as active objcet in object mode
if bpy.context.object.mode == 'OBJECT':
bpy.ops.object.select_all(action='DESELECT')
objectToSelect = bpy.data.objects[A.name]
objectToSelect.select_set(True)
bpy.context.view_layer.objects.active = objectToSelect
#############Supplementary Code################
return {'FINISHED'}
class Cam_0V0(Cam_Base):
bl_idname = "cam.0v0"
bl_label = "Cam_0V0"
cam_name = "C_0V0"
class Cam_0V1(Cam_Base):
bl_idname = "cam.0v1"
bl_label = "Cam_0V1"
cam_name = "C_0V1"
class Cam_0V2(Cam_Base):
bl_idname = "cam.0v2"
bl_label = "Cam_0V2"
cam_name = "C_0V2"
addon_keymaps = []
def register():
bpy.utils.register_class(Cam_Base)
bpy.utils.register_class(Cam_0V0)
bpy.utils.register_class(Cam_0V1)
bpy.utils.register_class(Cam_0V2)
def unregister():
bpy.utils.unregister_class(Cam_Base)
bpy.utils.unregister_class(Cam_0V0)
bpy.utils.unregister_class(Cam_0V1)
bpy.utils.unregister_class(Cam_0V2)
if __name__ == "__main__":
register()
bpy.types.Operator
to correctly register. It's a quirk of the API. You can use composition though, and inherit fromOperator
and another class $\endgroup$Cam_Base
a base class (no inheritance) and define your child classes withCam_0V0(Cam_Base, bpy.types.Operator):
. Note that you won't be able to registerCam_Base
$\endgroup$