Reputation: 80
I am trying to create contact sheet in Nuke using Python script which is as follows :
def create_contact_sheet(self,entities, version_paths, first_frame,last_frame):
movie_per_sheet = 30
print ("no of movies per sheet:", movie_per_sheet)
shot_list_splits = [entities[i:i + movie_per_sheet] for i in range(0, len(entities), movie_per_sheet)]
print ("no of required sheets:", len(shot_list_splits))
print("entities", entities)
print("shot version split", version_paths)
last_batch_rnode_pos = 0
first_rnode_xpos = None
r_node_xpos = None
print('version map', version_paths)
for sht_index, e_sht_list in enumerate(shot_list_splits):
nodes_for_backdrop = []
# create contact sheet:
ctt_sheet = nuke.createNode("ContactSheet", "sheet_%s" %(sht_index + 1))
print (">>> create ctt_sheet",ctt_sheet.name())
nodes_for_backdrop.append(ctt_sheet)
ctt_sheet["rows"].setValue(5)
ctt_sheet["columns"].setValue(6)
ctt_sheet["width"].setValue(5 * 1920)
ctt_sheet["height"].setValue(6 * 1080)
ctt_sheet.setSelected(False)
for index, e_shot in enumerate(e_sht_list):
exr_path = version_paths[e_shot][0]
if exr_path == None:
exr_r_node = nuke.createNode("Constant")
else:
exr_r_node = nuke.createNode("Read", "name %s file %s" % (e_shot, exr_path))
nodes_for_backdrop.append(exr_r_node)
r_node_xpos = last_batch_rnode_pos + index * 100
exr_r_node["xpos"].setValue(r_node_xpos)
exr_r_node["ypos"].setValue(0)
exr_r_node['first'].setValue(first_frame)
exr_r_node['last'].setValue(last_frame)
ctt_sheet.setInput(index, exr_r_node)
exr_r_node.setSelected(False)
# store first node xpos to place ctt_sheet_xpos
if index == 0:
first_rnode_xpos = r_node_xpos
# fix ctt_sheet_xpos
ctt_sheet_xpos = (len(e_sht_list) * 100) / 2 + first_rnode_xpos
ctt_sheet["xpos"].setValue(ctt_sheet_xpos)
ctt_sheet["ypos"].setValue(300)
last_batch_rnode_pos = r_node_xpos + 200
self.create_back_drop(nodes_for_backdrop, ctt_sheet)
def create_back_drop(self, nodes, ctt_sheet):
"""
make sure nodes were selected before execution this function
"""
# select nodes
for e_node in nodes:
e_node.setSelected(True)
node = nukescripts.autoBackdrop()
node["label"].setValue(ctt_sheet.name())
# de-select nodes
for e_node in nodes:
e_node.setSelected(False)
Here I am doing following operations:
1) First creating split batches of 30 sheets so all nodes are easily readable.
2) Iterating over the list of entities ['a0','a1','a2']
and using the dictionary version_map = {'a0':[exr_path, hud_path], 'a1' :[None, hud_path], 'a2':[exr_path, None]}
, to extract necessary information.
3) Then I am creating contact sheet for each element in entities I am creating a read node by extracting exr_path from the dictionary, which is giving me output something like this
(I am creating constant nodes if the paths aren't there)
What I am trying to achieve ?
rather than creating read nodes of exr and directly map them , I want to create two read nodes one for exr and other for hud as well and create a merge_node to overlap them with each other. something like this
Issue i am facing
I am not able to create a worflow to create another node for huds and then map the merge node rather than the exr_read_node itself.
I tried few thing but it just gave me distorted output of nodes all over the graph.
This might be easy but as it is my first Nuke tool i am not able to figure it out,any help would be really great.
Thanks & Regards
Upvotes: 1
Views: 166
Reputation: 80
Update :
I was able to achieve this using the following method
def get_merge_node(self, e_shot ,source_paths, first_frame, last_frame,xpos, ypos):
exr_path = source_paths[0]
hud_path = source_paths[1]
if exr_path is not None:
exr_node = nuke.createNode("Read", "name %s" % (e_shot))
exr_node["file"].setValue(exr_path)
exr_node['first'].setValue(first_frame)
exr_node['last'].setValue(last_frame)
else:
exr_node = nuke.createNode("Constant")
if hud_path is not None:
hud_node = nuke.createNode("Read", "name %s" % (e_shot))
hud_node["file"].setValue(hud_path)
hud_node['first'].setValue(first_frame)
hud_node['last'].setValue(last_frame)
else:
hud_node = nuke.createNode("Constant")
merge_node = nuke.createNode("Merge", "name %s" % (e_shot))
exr_node["xpos"].setValue(xpos)
exr_node["ypos"].setValue(ypos - 200)
hud_node["xpos"].setValue(xpos)
hud_node["ypos"].setValue(ypos - 100)
merge_node.setInput(1, hud_node)
merge_node.setInput(0, exr_node)
merge_node["mix"].setValue(0.5)
return merge_node
I created a separate method for this node creation and linking , then I am returning the merge node here and using that in Contact Sheet.
Upvotes: 1