Bases: MayaInstancePlugin
, OptionalPyblishPluginMixin
Validates Camera instance contents.
A Camera instance may only hold a SINGLE camera's transform, nothing else.
It may hold a "locator" as shape, but different shapes are down the hierarchy.
Source code in client/ayon_maya/plugins/publish/validate_camera_contents.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82 | class ValidateCameraContents(plugin.MayaInstancePlugin,
OptionalPyblishPluginMixin):
"""Validates Camera instance contents.
A Camera instance may only hold a SINGLE camera's transform, nothing else.
It may hold a "locator" as shape, but different shapes are down the
hierarchy.
"""
order = ValidateContentsOrder
families = ['camera']
label = 'Camera Contents'
actions = [ayon_maya.api.action.SelectInvalidAction]
validate_shapes = True
optional = False
@classmethod
def get_invalid(cls, instance):
# get cameras
members = instance.data['setMembers']
shapes = cmds.ls(members, dag=True, shapes=True, long=True)
# single camera
invalid = []
cameras = cmds.ls(shapes, type='camera', long=True)
if len(cameras) != 1:
cls.log.error("Camera instance must have a single camera. "
"Found {0}: {1}".format(len(cameras), cameras))
invalid.extend(cameras)
# We need to check this edge case because returning an extended
# list when there are no actual cameras results in
# still an empty 'invalid' list
if len(cameras) < 1:
if members:
# If there are members in the instance return all of
# them as 'invalid' so the user can still select invalid
cls.log.error("No cameras found in instance "
"members: {}".format(members))
return members
raise PublishValidationError(
"No cameras found in empty instance.")
if not cls.validate_shapes:
cls.log.debug("Not validating shapes in the camera content"
" because 'validate shapes' is disabled")
return invalid
# non-camera shapes
valid_shapes = cmds.ls(shapes, type=('camera', 'locator'), long=True)
shapes = set(shapes) - set(valid_shapes)
if shapes:
shapes = list(shapes)
cls.log.error("Camera instance should only contain camera "
"shapes. Found: {0}".format(shapes))
invalid.extend(shapes)
invalid = list(set(invalid))
return invalid
def process(self, instance):
"""Process all the nodes in the instance"""
if not self.is_active(instance.data):
return
invalid = self.get_invalid(instance)
if invalid:
raise PublishValidationError("Invalid camera contents: "
"{0}".format(invalid))
|
process(instance)
Process all the nodes in the instance
Source code in client/ayon_maya/plugins/publish/validate_camera_contents.py
| def process(self, instance):
"""Process all the nodes in the instance"""
if not self.is_active(instance.data):
return
invalid = self.get_invalid(instance)
if invalid:
raise PublishValidationError("Invalid camera contents: "
"{0}".format(invalid))
|