Bases: MayaInstancePlugin
, OptionalPyblishPluginMixin
Validates transform suffix based on the type of its children shapes.
Suffices must be
- mesh: _GEO (regular geometry) _GES (geometry to be smoothed at render) _GEP (proxy geometry; usually not to be rendered) _OSD (open subdiv smooth at rendertime)
- nurbsCurve: _CRV
- nurbsSurface: _NRB
- locator: _LOC
- null/group: _GRP
Suffices can also be overridden by project settings.
.. warning:: This grabs the first child shape as a reference and doesn't use the others in the check.
Source code in client/ayon_maya/plugins/publish/validate_transform_naming_suffix.py
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162 | class ValidateTransformNamingSuffix(plugin.MayaInstancePlugin,
OptionalPyblishPluginMixin):
"""Validates transform suffix based on the type of its children shapes.
Suffices must be:
- mesh:
_GEO (regular geometry)
_GES (geometry to be smoothed at render)
_GEP (proxy geometry; usually not to be rendered)
_OSD (open subdiv smooth at rendertime)
- nurbsCurve: _CRV
- nurbsSurface: _NRB
- locator: _LOC
- null/group: _GRP
Suffices can also be overridden by project settings.
.. warning::
This grabs the first child shape as a reference and doesn't use the
others in the check.
"""
order = ValidateContentsOrder
families = ["model"]
optional = True
label = "Suffix Naming Conventions"
actions = [ayon_maya.api.action.SelectInvalidAction]
SUFFIX_NAMING_TABLE = json.dumps({
"mesh": ["_GEO", "_GES", "_GEP", "_OSD"],
"nurbsCurve": ["_CRV"],
"nurbsSurface": ["_NRB"],
"locator": ["_LOC"],
"group": ["_GRP"]
})
ALLOW_IF_NOT_IN_SUFFIX_TABLE = True
@classmethod
def get_table_for_invalid(cls, markdown=False):
suffix_naming_table = json.loads(cls.SUFFIX_NAMING_TABLE)
if markdown:
ss = [
"- **{}**: {}".format(k, ", ".join(v))
for k, v in suffix_naming_table.items()
]
else:
ss = [
"- {}: {}".format(k, ", ".join(v))
for k, v in suffix_naming_table.items()
]
return "\n".join(ss)
@staticmethod
def is_valid_name(
node_name,
shape_type,
suffix_naming_table,
allow_if_not_in_suffix_table
):
"""Return whether node's name is correct.
The correctness for a transform's suffix is dependent on what
`shape_type` it holds. E.g. a transform with a mesh might need and
`_GEO` suffix.
When `shape_type` is None the transform doesn't have any direct
children shapes.
Args:
node_name (str): Node name.
shape_type (str): Type of node.
suffix_naming_table (dict): Mapping dict for suffixes.
allow_if_not_in_suffix_table (bool): Default output.
"""
if shape_type not in suffix_naming_table:
return allow_if_not_in_suffix_table
suffices = suffix_naming_table[shape_type]
for suffix in suffices:
if node_name.endswith(suffix):
return True
return False
@classmethod
def get_invalid(cls, instance):
"""Get invalid nodes in instance.
Args:
instance (:class:`pyblish.api.Instance`): published instance.
"""
transforms = cmds.ls(instance, type="transform", long=True)
invalid = []
suffix_naming_table = json.loads(cls.SUFFIX_NAMING_TABLE)
for transform in transforms:
shapes = cmds.listRelatives(transform,
shapes=True,
fullPath=True,
noIntermediate=True)
shape_type = cmds.nodeType(shapes[0]) if shapes else "group"
if not cls.is_valid_name(
transform,
shape_type,
suffix_naming_table,
cls.ALLOW_IF_NOT_IN_SUFFIX_TABLE
):
invalid.append(transform)
return invalid
def process(self, instance):
"""Process all the nodes in the instance.
Args:
instance (:class:`pyblish.api.Instance`): published instance.
"""
if not self.is_active(instance.data):
return
invalid = self.get_invalid(instance)
if invalid:
valid = self.get_table_for_invalid()
names = "\n".join(
" - {}".format(node) for node in invalid
)
raise PublishValidationError(
title="Invalid naming suffix",
message="Valid suffixes are:\n{0}\n\n"
"Incorrectly named geometry transforms:\n{1}"
"".format(valid, names),
description=self.get_description())
def get_description(self) -> str:
"""Get description for the plugin."""
table = self.get_table_for_invalid(markdown=True)
return (
"### Invalid naming suffix\n"
"Valid suffixes are:\n"
f"{table}\n"
"\n\\\n" # force extra line breaks in the resulting markdown
"Use the *Select Invalid* action to identify the invalid nodes."
)
|
Get description for the plugin.
Source code in client/ayon_maya/plugins/publish/validate_transform_naming_suffix.py
153
154
155
156
157
158
159
160
161
162 | def get_description(self) -> str:
"""Get description for the plugin."""
table = self.get_table_for_invalid(markdown=True)
return (
"### Invalid naming suffix\n"
"Valid suffixes are:\n"
f"{table}\n"
"\n\\\n" # force extra line breaks in the resulting markdown
"Use the *Select Invalid* action to identify the invalid nodes."
)
|
Get invalid nodes in instance.
Parameters:
Name | Type | Description | Default |
instance | | class:pyblish.api.Instance ): published instance. | required |
Source code in client/ayon_maya/plugins/publish/validate_transform_naming_suffix.py
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126 | @classmethod
def get_invalid(cls, instance):
"""Get invalid nodes in instance.
Args:
instance (:class:`pyblish.api.Instance`): published instance.
"""
transforms = cmds.ls(instance, type="transform", long=True)
invalid = []
suffix_naming_table = json.loads(cls.SUFFIX_NAMING_TABLE)
for transform in transforms:
shapes = cmds.listRelatives(transform,
shapes=True,
fullPath=True,
noIntermediate=True)
shape_type = cmds.nodeType(shapes[0]) if shapes else "group"
if not cls.is_valid_name(
transform,
shape_type,
suffix_naming_table,
cls.ALLOW_IF_NOT_IN_SUFFIX_TABLE
):
invalid.append(transform)
return invalid
|
Return whether node's name is correct.
The correctness for a transform's suffix is dependent on what shape_type
it holds. E.g. a transform with a mesh might need and _GEO
suffix.
When shape_type
is None the transform doesn't have any direct children shapes.
Parameters:
Name | Type | Description | Default |
node_name | str | | required |
shape_type | str | | required |
suffix_naming_table | dict | Mapping dict for suffixes. | required |
allow_if_not_in_suffix_table | bool | | required |
Source code in client/ayon_maya/plugins/publish/validate_transform_naming_suffix.py
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97 | @staticmethod
def is_valid_name(
node_name,
shape_type,
suffix_naming_table,
allow_if_not_in_suffix_table
):
"""Return whether node's name is correct.
The correctness for a transform's suffix is dependent on what
`shape_type` it holds. E.g. a transform with a mesh might need and
`_GEO` suffix.
When `shape_type` is None the transform doesn't have any direct
children shapes.
Args:
node_name (str): Node name.
shape_type (str): Type of node.
suffix_naming_table (dict): Mapping dict for suffixes.
allow_if_not_in_suffix_table (bool): Default output.
"""
if shape_type not in suffix_naming_table:
return allow_if_not_in_suffix_table
suffices = suffix_naming_table[shape_type]
for suffix in suffices:
if node_name.endswith(suffix):
return True
return False
|
Process all the nodes in the instance.
Parameters:
Name | Type | Description | Default |
instance | | class:pyblish.api.Instance ): published instance. | required |
Source code in client/ayon_maya/plugins/publish/validate_transform_naming_suffix.py
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151 | def process(self, instance):
"""Process all the nodes in the instance.
Args:
instance (:class:`pyblish.api.Instance`): published instance.
"""
if not self.is_active(instance.data):
return
invalid = self.get_invalid(instance)
if invalid:
valid = self.get_table_for_invalid()
names = "\n".join(
" - {}".format(node) for node in invalid
)
raise PublishValidationError(
title="Invalid naming suffix",
message="Valid suffixes are:\n{0}\n\n"
"Incorrectly named geometry transforms:\n{1}"
"".format(valid, names),
description=self.get_description())
|