python C4D - Pyhton

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python C4D - Pyhton相关的知识,希望对你有一定的参考价值。

# -*- coding: utf-8 -*-

# bh_keyLightBrightnessFromTextFile - by Horganovski

# refined by Niklas Rosenstein <rosensteinniklas@googlemail.com>

# from https://www.c4dcafe.com/ipb/forums/topic/68561-python-example-create-animation-from-text-file/



import os

import re

import c4d



line_match = re.compile('^s*(-|+)?(d*.?d*)')



def readKeysFile(path):

	if not os.path.exists(path):

		return None



	keys = []



	with open(path) as fl:

		for line in fl:

			value = line_match.match(line)

			if value and value.group(2):

				string = (value.group(1) or '+') + value.group(2)

				keys.append(float(string))

			else:

				keys.append(None)



	return keys



def main():

	path = c4d.storage.LoadDialog()

	if not path:

		return



	offset = None

	while True:

		offset = c4d.gui.InputDialog('Enter the start-frame:')

		if not offset:

			return

		try:

			offset = int(offset)

			break

		except ValueError:

			offset = None

			c4d.gui.MessageDialog('Not a number.')



	keys = readKeysFile(path)

	if not keys:

		c4d.gui.MessageDialog("No keys loaded.")

		return



	fps  = doc.GetFps()

	objects = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_CHILDREN)



	for op in objects:

		track = op.FindCTrack(c4d.LIGHT_BRIGHTNESS)

		if not track:

			track = c4d.CTrack(op, c4d.LIGHT_BRIGHTNESS)

			op.InsertTrackSorted(track)



		curve = track.GetCurve()

		for i, key_value in enumerate(keys):

			if key_value is None:

				pass

			else:

				frame = offset + i

				frame_time = c4d.BaseTime(frame, fps)

				key_dict = curve.AddKey(frame_time)

				key_dict['key'].SetValue(curve, key_value)



	c4d.EventAdd()

	

main()

以上是关于python C4D - Pyhton的主要内容,如果未能解决你的问题,请参考以下文章

python C4d - Python导出器

python C4D技巧和位

Pyhton编程之第一个Pyhton程序

通过Python编程语言实现C4D(R13)中的简单动画

python 使用Pyhton查找外部IP

Pyhton浅谈-Python与中间件之Redis