NukeStudio常用命令参考

获取项目

关于preject类的用法,在下面的链接查看

https://learn.foundry.com/hiero/developers/11.1/HieroPythonDevGuide/api/api_core.html#hiero.core.Project

1
2
3
4
5
6
7
8
9
10
import hiero.core as hc
all_projects = hc.projects()

# 打印出所有项目名
for p in all_projects:
print p.name()

# 获取指定名称的项目
name = 'test_project'
p = hc.project(name)

创建Clip,放到对应的Sequence或者Bin

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import hiero.core as hc
file_path = r'D:\demo\shot001\shot001_v001.1001.exr'

# 创建MediaSource对象
m = hc.MediaSource(file_path)

# 创建Clip对象
c = hc.Clip(m)

# 创建binItem对象
bin_item = hc.BinItem(c)

# 获取需要放置的bin路径对象,添加对象到Bin
# 确保test_project和Bin 1已经存在
p = hc.project('test_project')
bin1 = p.bins('Bin 1')[0]
bin1.addItem(bin_item)

关于Clip,MediaSource,binItem对象的方法:

https://learn.foundry.com/hiero/developers/11.1/HieroPythonDevGuide/api/api_core.html#hiero.core.Clip

https://learn.foundry.com/hiero/developers/11.1/HieroPythonDevGuide/api/api_core.html#hiero.core.MediaSource

https://learn.foundry.com/hiero/developers/11.1/HieroPythonDevGuide/api/api_core.html#hiero.core.BinItem

获取MediaSource对象的路径

1
2
3
4
5
6
import hiero.core as hc

file_path = r'D:\demo\shot001\shot001_v001.1001.exr'
m = hc.MediaSource(file_path)
m_infos = m.fileinfos()
print m_infos[0].filename()

在项目顶层文件夹创建Bin

1
2
3
4
5
import hiero.core as hc

p = hc.project('test_project')
bin1 = hc.Bin('test')
p.clipsBin().addItem(bin1)

将clip放置到时间线

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""
设置源文件出入点
TrackItem.setSourceIn()
TrackItem.setSourceOut()

设置时间线出入点
TrackItem.setTimelineIn()
TrackItem.setTimelineOut()
"""

import hiero.core as hc

file_path = r'D:\demo\shot001\shot001_v001.1001.exr'

# 获取project和bin,以及bin下面的sequence对象
p = hc.project('test_project')
bin1 = p.bins('Bin 1')[0]
s = bin1.sequences()[0]

# 创建MediaSource和Clip对象
m = hc.MediaSource(file_path)
c = hc.Clip(m)

# 获取video1对象,并创建一个TrackItem对象
vt = s.activeItem().videoTrack(0)
t = s.activeItem().videoTrack(0).createTrackItem('shot001')

# 为trackItem对象设置来源clip,时间线起始帧结束帧
t.setSource(c)
t.setTimelineIn(1)
t.setTimelineOut(22)
vt.addItem(t)

添加在时间线右键触发事件

1
2
3
4
5
6
7
8
import hiero.core as hc

def add_print(event):
event.menu.addAction('print selected')
selection = event.sender.selection()
print selection

hc.events.registerInterest("kShowContextMenu/kTimeline", add_print)

获取选中的clip对象

1
2
3
4
5
6
7
8
9
10
from hiero.core import TrackItem

# 获取激活的sequence对象
seq = hiero.ui.activeSequence()

# 获取TimelineEditor对象
te = hiero.ui.getTimelineEditor(seq)

# 得到所有选择的clip items
print te.selection()

直接在sequence添加clip

1
2
3
4
5
6
7
8
9
10
11
12
13
import hiero.core as hc

file_path = r'D:\demo\shot006\BEN_0230_V001.1001.exr'

# 获取project和bin,以及bin下面的sequence对象
p = hc.project('test')

s = p.sequences('seq01')[0]

# 创建MediaSource和Clip对象
m = hc.MediaSource(file_path)
c = hc.Clip(m)
s.addClip(c, time=1001) # time这里为起始时间

获取clip的matadata信息

1
2
3
4
5
c.metadata().value('foundry.timeline.duration')

"""
hasKey, keys, setValue, value
"""