Python C4D 笔记4 -获取当前帧 (Basetime and fps)

  1. 创建物体 ,然后打python标签。
    在这里插入图片描述

  2. 获取当前帧,由于当前时间是相对于整个doc,所以要找c4d.douments下的基类c4d.documents.BaseDocument

BaseDocument.GetTime()
BaseDocument.SetTime()

先执行下看看效果,不用实例化,直接使用 doc 的方法就可以,代码如下:

def main():
    basetime = doc.GetTime()
    print(basetime)
执行结果如下:
<c4d.BaseTime object at 0x0000022757520120>

这个结果貌似并不是想要的,再查看下GetTime()函数内容,如下所示:

BaseDocument.GetTime()¶Returns the min time.
Return type: c4d.BaseTime
Returns: The current time.

貌似返回的是doc的最小时间,因此不管我怎么移动时间滑块,得到的结果都是一样,并不是我想要的结果,我希望获取当前帧时间。
在这里插入图片描述3. 继续再看,GetTime()返回的是c4d.BaseTime,那我们就查下BaseTime类,里面有BaseTime.GetFrame(),描述如下:
BaseTime.GetFrame(fps)¶
Get the number of frames equivalent to this time for the given number of frames per second.

Parameters: fps (int) – The number of frames for this time.
Return type: int
Returns: The frames per second to use to calculate the frame number for this time.

参数是要fps,这个fps是doc项目的fps(一般默认30),通过整个项目初始帧数,计算当时间所在帧,既然是整个项目的帧数,那肯定是要在documents类里找了。
4. 在documents.BaseDocument看到以下方法:

BaseDocument.GetFps()
BaseDocument.SetFps()
在这里插入图片描述

  1. 我获得了整个doc的FPS,那么通过上面的调用关系,我就能获得当前帧是多少了。代码如下:
def main():
    basetime = doc.GetTime() # 返回BaseTime对象    
    fps = doc.GetFps() # 获取整个项目FPS    
    current_fps = basetime.GetFrame(fps) #获取当前帧
    
    print('current fps : ' + str(current_fps)) #打印
    #等价于
    print('current fps : ' + str(doc.GetTime().GetFrame(doc.GetFps())))

执行结果:
在这里插入图片描述

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值