python C4D - Pyhton

Posted

tags:

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

#bh_keyLightBrightnessFromTextFile

#select a light or lights and run to key the light intensity with the values in the text file

# NB - each value should be on a new line in the text file

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

####################

startKeyingFrame=1 # change this value to determine what frame number the keying will start on

####################



import c4d

from c4d import gui



keyVals=list()



def readFile(path):

	for line in open(path):

		print line

		## below just left in for example of searching for particular words

		#words = ['startTime', 'endTime']

		#for word in words:

		#	if word in line:

		#		print line

		readValue = float (line)# need to cast the variable as a float so we can get its numerical value			

		keyVals.append(readValue)# add each value to the keyVals list			

	return keyVals



def main():

	animFile = c4d.storage.LoadDialog()# open the C4D file browser to allow the user to choose a text file to read

	readFile(animFile)# run the read file proc

	

	keyCount= len (keyVals)# count how many values are in the list

	FPS=doc.GetFps()

	dBright = c4d.DescID(c4d.LIGHT_BRIGHTNESS) #assign the DescID to a var for convenience

	objList=doc.GetActiveObjects(True)# get the selected objects

	lstSize = len(objList)# count how many objects are selected

	

	c=0

	while (c<lstSize):# loop through each selected object

	   tBright = objList[c].FindCTrack(dBright) #find the light brightness track

	   if not tBright:#if track isn't found, create it

		   tBright = c4d.CTrack(objList[c],dBright)

		   objList[c].InsertTrackSorted(tBright)

	   curve = tBright.GetCurve()

	   k=0

	   while (k<keyCount):# loop through each value in the keyVals list

		   frameNo=(startKeyingFrame+k)

		   frameTime= c4d.BaseTime(frameNo,FPS)

		   keyDict = curve.AddKey(frameTime)

		   tBright.FillKey(doc, objList[c], keyDict["key"])

		   keyVal=keyVals[k]

		   keyDict["key"].SetValue(curve,keyVal)

		   k=k+1

	   c4d.EventAdd()	

	   c=c+1

	  

	c4d.EventAdd()

	c4d.CallCommand(12147)#redraw the scene



				  

if __name__=='__main__':

	main()

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

python C4d - Python导出器

python C4D技巧和位

Pyhton编程之第一个Pyhton程序

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

python 使用Pyhton查找外部IP

Pyhton浅谈-Python与中间件之Redis