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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327 | class BaseCreateRoyalRenderJob(
pyblish.api.InstancePlugin, AYONPyblishPluginMixin
):
"""Creates separate rendering job for Royal Render"""
label = "Create Nuke Render job in RR"
order = pyblish.api.IntegratorOrder + 0.1
hosts = ["nuke"]
families = ["render", "prerender"]
targets = ["local"]
optional = True
priority = 50
chunk_size = 1
concurrent_tasks = 1
use_gpu = True
use_published = True
auto_delete = True
@classmethod
def get_attribute_defs(cls):
return [
NumberDef(
"priority",
label="Priority",
default=cls.priority,
decimals=0
),
NumberDef(
"chunk",
label="Frames Per Task",
default=cls.chunk_size,
decimals=0,
minimum=1,
maximum=1000
),
NumberDef(
"concurrency",
label="Concurrency",
default=cls.concurrent_tasks,
decimals=0,
minimum=1,
maximum=10
),
BoolDef(
"use_gpu",
default=cls.use_gpu,
label="Use GPU"
),
BoolDef(
"suspend_publish",
default=False,
label="Suspend publish"
),
BoolDef(
"use_published",
default=cls.use_published,
label="Use published workfile",
),
BoolDef(
"auto_delete",
default=cls.auto_delete,
label="Cleanup temp renderfolder",
),
]
def __init__(self, *args, **kwargs):
self._rr_root = None
self.scene_path = None
self.job = None
self.submission_parameters = None
self.rr_api = None
def process(self, instance):
if not instance.data.get("farm"):
self.log.info("Skipping local instance.")
return
instance.data["attributeValues"] = self.get_attr_values_from_data(
instance.data
)
# add suspend_publish and auto_delete attributeValue to instance data
instance.data["suspend_publish"] = instance.data["attributeValues"][
"suspend_publish"
]
instance.data["auto_delete"] = instance.data["attributeValues"][
"auto_delete"
]
instance.data["priority"] = instance.data["attributeValues"][
"priority"
]
context = instance.context
self._rr_root = instance.data.get("rr_root")
self.log.debug(self._rr_root)
if not self._rr_root:
raise KnownPublishError(
(
"Missing RoyalRender root. "
"You need to configure RoyalRender module."
)
)
self.rr_api = rrApi(self._rr_root)
self.scene_path = context.data["currentFile"]
if self.use_published:
published_workfile = get_published_workfile_instance(context)
# fallback if nothing was set
if published_workfile is None:
self.log.warning("Falling back to workfile")
file_path = context.data["currentFile"]
else:
workfile_repre = published_workfile.data["representations"][0]
file_path = workfile_repre["published_path"]
self.scene_path = file_path
self.log.info(
"Using published scene for render {}".format(self.scene_path)
)
if not instance.data.get("expectedFiles"):
instance.data["expectedFiles"] = []
if not instance.data.get("rrJobs"):
instance.data["rrJobs"] = []
def get_job(
self, instance, script_path, render_path, node_name, single=False
):
"""Get RR job based on current instance.
Args:
script_path (str): Path to Nuke script.
render_path (str): Output path.
node_name (str): Name of the render node.
Returns:
RRJob: RoyalRender Job instance.
"""
anatomy = instance.context.data["anatomy"]
start_frame = int(instance.data["frameStartHandle"])
end_frame = int(instance.data["frameEndHandle"])
padding = anatomy.templates_obj.frame_padding
batch_name = os.path.basename(script_path)
jobname = "%s - %s" % (batch_name, instance.name)
if is_in_tests():
batch_name += datetime.now().strftime("%d%m%Y%H%M%S")
render_dir = os.path.normpath(os.path.dirname(render_path))
output_filename_0 = self.pad_file_name(
render_path, str(start_frame), padding
)
file_name, file_ext = os.path.splitext(
os.path.basename(output_filename_0)
)
custom_attributes = []
job_disabled = "1" if instance.data["suspend_publish"] is True else "0"
priority = instance.data["priority"]
submitter_parameters_job = [
SubmitterParameter("SendJobDisabled", "1", f"{job_disabled}"),
SubmitterParameter("Priority", "1", f"{priority}"),
]
# this will append expected files to instance as needed.
expected_files = self.expected_files(
instance, render_path, start_frame, end_frame
)
instance.data["expectedFiles"].extend(expected_files)
# anatomy_data = instance.context.data["anatomyData"]
environment = RREnvList(
{
"AYON_PROJECT_NAME": instance.context.data["projectName"],
"AYON_FOLDER_PATH": instance.context.data["folderPath"],
"AYON_TASK_NAME": instance.context.data["task"],
"AYON_USERNAME": instance.context.data["user"],
"AYON_APP_NAME": os.environ["AYON_APP_NAME"],
"AYON_RENDER_JOB": "1",
"AYON_BUNDLE_NAME": os.environ["AYON_BUNDLE_NAME"],
"AYON_EXECUTABLE": os.environ["AYON_EXECUTABLE"],
"AYON_SERVER_URL": os.environ["AYON_SERVER_URL"],
"AYON_API_KEY": os.environ["AYON_API_KEY"],
}
)
render_dir = render_dir.replace("\\", "/")
job = RRJob(
Software="",
Renderer="",
SeqStart=int(start_frame),
SeqEnd=int(end_frame),
SeqStep=int(instance.data.get("byFrameStep", 1)),
ImageFramePadding=padding,
SeqFileOffset=0,
Version=0,
SceneName=script_path,
IsActive=True,
ImageDir=render_dir.replace("\\", "/"),
ImageFilename=file_name,
ImageExtension=file_ext,
ImagePreNumberLetter="",
ImageSingleOutputFile=single,
SceneOS=get_rr_platform(),
Layer=node_name,
SceneDatabaseDir=script_path,
CustomSHotName=jobname,
CompanyProjectName=instance.context.data["projectName"],
ImageWidth=instance.data["resolutionWidth"],
ImageHeight=instance.data["resolutionHeight"],
CustomAttributes=custom_attributes,
SubmitterParameters=submitter_parameters_job,
rrEnvList=environment.serialize(),
rrEnvFile=os.path.join(render_dir, "rrEnv.rrEnv"),
)
return job
def update_job_with_host_specific(self, instance, job):
"""Host specific mapping for RRJob"""
raise NotImplementedError
def expected_files(self, instance, path, start_frame, end_frame):
"""Get expected files.
This function generate expected files from provided
path and start/end frames.
It was taken from Deadline module, but this should be
probably handled better in collector to support more
flexible scenarios.
Args:
instance (Instance)
path (str): Output path.
start_frame (int): Start frame.
end_frame (int): End frame.
Returns:
list: List of expected files.
"""
dir_name = os.path.dirname(path)
file = os.path.basename(path)
expected_files = []
if "#" in file:
pparts = file.split("#")
padding = "%0{}d".format(len(pparts) - 1)
file = pparts[0] + padding + pparts[-1]
if "%" not in file:
expected_files.append(path)
return expected_files
if instance.data.get("slate"):
start_frame -= 1
expected_files.extend(
os.path.join(dir_name, (file % i)).replace("\\", "/")
for i in range(start_frame, (end_frame + 1))
)
return expected_files
def pad_file_name(self, path, first_frame, padding):
"""Return output file path with #### for padding.
RR requires the path to be formatted with # in place of numbers.
For example `/path/to/render.####.png`
Args:
path (str): path to rendered image
first_frame (str): from representation to cleany replace with #
padding
Returns:
str
"""
self.log.debug("pad_file_name path: `{}`".format(path))
self.log.debug("padding_from_anatatomy_preset: `{}`".format(padding))
if "%" in path:
search_results = re.search(r"(%0)(\d)(d.)", path).groups()
self.log.debug("_ search_results: `{}`".format(search_results))
return int(search_results[1])
if "#" in path:
self.log.debug("already padded: `{}`".format(path))
return path
if first_frame:
path = path.replace(str(first_frame).zfill(padding), "#" * padding)
return path
|