def createAnimationObject(curObj, animTag, newName, doc): #newObj=curObj.GetClone() #doc.InsertObject(newObj,curObj.GetUp(),curObj) doc.SetActiveObject(curObj, c4d.SELECTION_NEW) c4d.CallCommand(12233) newObj = curObj.GetNext() extraRemove = None if newObj.GetType() != c4d.Opolygon: extraRemove = newObj newObj = newObj.GetDown() doc.InsertObject(newObj, curObj.GetUp(), curObj) cleanTracks(newObj) id = c4d.DescID(c4d.DescLevel(c4d.CTpla, c4d.CTpla, 0)) plaTrack = c4d.CTrack(newObj, id) newObj.InsertTrackSorted(plaTrack) setNewtracks(plaTrack, curObj, newObj, animTag, doc) newAnimationTag = newObj.GetTag(1030484) newAnimationTag[1054] = 1056 newAnimationTag[1051] = False newAnimationTag[1010] = True newAnimationTag[1011] = newName animTag[1010] = False newObj.SetName(newName) if extraRemove is not None: extraRemove.Remove() c4d.EventAdd()
def main(): path = s.LoadDialog(c4d.FILESELECTTYPE_ANYTHING, "Sound file", c4d.FILESELECT_LOAD) folderPath, fileName = os.path.split(path) doc = c4d.documents.GetActiveDocument() # Get active Cinema 4D document time = c4d.BaseTime(doc.GetTime().Get()) # Get current time null = c4d.BaseObject(c4d.Onull) # Initialize a null null.SetName("Sound: "+fileName) # Set name null[c4d.NULLOBJECT_DISPLAY] = 14 # Set 'Display' to 'None' null[c4d.ID_BASELIST_ICON_FILE] = "440000255" # Set icon null[c4d.ID_BASELIST_ICON_COLORIZE_MODE] = 2 # Set 'Icon Color' to 'Display Color' null[c4d.ID_BASEOBJECT_USECOLOR] = 2 # Set 'Display Color' to 'On' null[c4d.ID_BASEOBJECT_COLOR] = c4d.Vector(140.0/255.0, 203.0/255.0, 1.0) null[c4d.ID_BASELIST_ICON_COLOR] = c4d.Vector(140.0/255.0, 203.0/255.0, 1.0) doc.InsertObject(null) # Insert null to the document desc = c4d.DescID(c4d.DescLevel(c4d.CTsound, c4d.CTsound, 0)) SoundTrack = c4d.CTrack(null, desc) # Initialize a sound Track null.InsertTrackSorted(SoundTrack) # Insert the sound track to the object SoundTrack[c4d.CID_SOUND_NAME] = path # Set sou SoundTrack[c4d.CID_SOUND_START] = time c4d.EventAdd()
def Bake(source, target): """ Bake function """ doc = c4d.documents.GetActiveDocument() # Get active Cinema 4D document fps = doc.GetFps() # Get Frame Rate startFrame = doc.GetLoopMinTime().GetFrame(fps) # Get first frame of Preview Range endFrame = doc.GetLoopMaxTime().GetFrame(fps) # Get last frame of Preview Range desc = c4d.DescID(c4d.DescLevel(c4d.CTpla, c4d.CTpla, 0)) PLAtrack = c4d.CTrack(target, desc) # Initialize a PLA track target.InsertTrackSorted(PLAtrack) # Insert PLA track to the object curve = PLAtrack.GetCurve() # Get Curve of the CTrack for i in range(startFrame, endFrame+1): # Iterate through Preview Range SetCurrentFrame(i, doc) # Set current frame frame = doc.GetTime().GetFrame(fps) # Get current frame points = source.GetAllPoints() #key.SetValue(curve, value) #key.SetGeData(curve, value) # Keyframe value needs to be set with SetGeData currentTime = c4d.BaseTime(frame, fps) # Get current time #points = source.GetAllPoints() key = curve.AddKey(currentTime)["key"] target.SetAllPoints(points) target.Message(c4d.MSG_UPDATE) PLAtrack.FillKey(doc, target, key)
def createAnimationObject(curObj, animTag, newName, doc): #newObj=curObj.GetClone() #doc.InsertObject(newObj) doc.SetActiveObject(curObj, c4d.SELECTION_NEW) c4d.CallCommand( 12233) # perform "current state to object" on the selected object # search the newly created object stateObj = curObj.GetNext() newObj = getPolyObject(stateObj) stateObj.Remove() doc.InsertObject(newObj, curObj.GetUp(), curObj) cleanTracks(newObj) id = c4d.DescID(c4d.DescLevel(c4d.CTpla, c4d.CTpla, 0)) plaTrack = c4d.CTrack(newObj, id) newObj.InsertTrackSorted(plaTrack) setNewtracks(plaTrack, curObj, newObj, animTag, doc) newAnimationTag = newObj.GetTag(1030484) newAnimationTag[1054] = 1056 newAnimationTag[1051] = False newAnimationTag[1010] = True newAnimationTag[1011] = newName animTag[1010] = False newObj.SetName(newName) c4d.EventAdd()
def set_matrix(self, matrix, frame): """ :type frame: int :param frame: :type: Matrix :param matrix: :return: """ transform = [ matrix.get().off, c4d.utils.MatrixToHPB(matrix.get(), self.__object.GetRotationOrder()), matrix.get().GetScale() ] for i_type in range(3): for i_dir in range(3): desc_id = c4d.DescID( c4d.DescLevel(ID_TYPES[i_type], c4d.DTYPE_VECTOR, 0), c4d.DescLevel(ID_DIRS[i_dir], c4d.DTYPE_REAL, 0)) track = self.__object.FindCTrack(desc_id) if track is None: track = c4d.CTrack(self.__object, desc_id) self.__object.InsertTrackSorted(track) curve = track.GetCurve() key = curve.AddKey(c4d.BaseTime(frame, get_fps()))['key'] if key is None: print('Error: Failed to add keys!') continue track.FillKey(context_doc, self.__object, key) key.SetValue(curve, transform[i_type][i_dir])
def main(): # Creates the object in memory obj = c4d.BaseObject(c4d.Ocube) # Creates the track in memory. Defined by it's DescID trackY = c4d.CTrack(obj, c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_POSITION, c4d.DTYPE_VECTOR, 0), c4d.DescLevel(c4d.VECTOR_Y, c4d.DTYPE_REAL, 0))) # Gets curves for the track curveY = trackY.GetCurve() # Creates a key in the Y curve with value 0 at 0 frame with a spline interpolation keyA, keyAIndex = CreateKey(curveY, c4d.BaseTime(0), value=0, interpolation=c4d.CINTERPOLATION_SPLINE) # Retrieves time at frame 10 keyBTime = c4d.BaseTime(10, doc.GetFps()) # Creates another key in the Y curve with value 100 at 10 frame with a spline interpolation keyB, keyBIndex = CreateKey(curveY, keyBTime, value=100, interpolation=c4d.CINTERPOLATION_SPLINE) # Inserts the track containing the Y curve to the object obj.InsertTrackSorted(trackY) # Inserts the object in document doc.InsertObject(obj) # Pushes an update event to Cinema 4D c4d.EventAdd()
def new_rig(obj, cachetype): #create a Python tag and attach it to the selected tag's object pythontag = c4d.BaseTag(c4d.Tpython) #set the Python code inside the tag pythontag[ c4d.TPYTHON_CODE] = copyright + pythontagcode + pythontagcode_dict[ cachetype] #add userdata to the Python tag userdata = c4d.GetCustomDataTypeDefault(c4d.DTYPE_REAL) userdata[c4d.DESC_NAME] = "Frame" pythontag.AddUserData(userdata) pythontag[c4d.ID_USERDATA, 1] = 0.0 #add an animation track to the userdata we just created track = c4d.CTrack( pythontag, c4d.DescID(c4d.DescLevel(c4d.ID_USERDATA, c4d.DTYPE_SUBCONTAINER, 0), c4d.DescLevel(1, c4d.DTYPE_REAL, 0))) pythontag.InsertTrackSorted(track) #get the curve of our new track (we'll attach keyframes to this curve) curve = track.GetCurve() #make some keyframes, setting their time, value and curve key1 = c4d.CKey() key1.SetTime(curve, doc.GetMinTime()) key1.SetValue(curve, doc.GetMinTime().Get() * doc.GetFps()) key1.SetTimeRight(curve, c4d.BaseTime(0.5)) key2 = c4d.CKey() key2.SetTime(curve, doc.GetMaxTime()) key2.SetValue(curve, doc.GetMaxTime().Get() * doc.GetFps()) key2.SetTimeLeft(curve, c4d.BaseTime(-0.5)) #add the keyframes to the curve curve.InsertKey(key1) curve.InsertKey(key2) #set the Python tag's priority priority = c4d.PriorityData() priority.SetPriorityValue(c4d.PRIORITYVALUE_MODE, c4d.CYCLE_GENERATORS) priority.SetPriorityValue(c4d.PRIORITYVALUE_PRIORITY, -1) pythontag[c4d.EXPRESSION_PRIORITY] = priority #add the Python tag to the selected object, and add an undo doc.StartUndo() obj.InsertTag(pythontag) doc.AddUndo(c4d.UNDOTYPE_NEW, pythontag) doc.EndUndo() c4d.EventAdd(c4d.EVENT_FORCEREDRAW) print "Cache retimer successfully added to " + obj.GetName() + "!"
def Bake(source, target): """ Bake function """ doc = c4d.documents.GetActiveDocument() # Get active Cinema 4D document fps = doc.GetFps() # Get Frame Rate startFrame = doc.GetLoopMinTime().GetFrame( fps) # Get first frame of Preview Range endFrame = doc.GetLoopMaxTime().GetFrame( fps) # Get last frame of Preview Range for i in range(startFrame, endFrame + 1): # Iterate through Preview Range SetCurrentFrame(i, doc) # Set current frame frame = doc.GetTime().GetFrame(fps) # Get current frame dataVault = [ [903, c4d.DTYPE_REAL, 1000, c4d.DTYPE_VECTOR], [903, c4d.DTYPE_REAL, 1001, c4d.DTYPE_VECTOR], [903, c4d.DTYPE_REAL, 1002, c4d.DTYPE_VECTOR], # Position [904, c4d.DTYPE_REAL, 1000, c4d.DTYPE_VECTOR], [904, c4d.DTYPE_REAL, 1001, c4d.DTYPE_VECTOR], [904, c4d.DTYPE_REAL, 1002, c4d.DTYPE_VECTOR], # Rotation [905, c4d.DTYPE_REAL, 1000, c4d.DTYPE_VECTOR], [905, c4d.DTYPE_REAL, 1001, c4d.DTYPE_VECTOR], [905, c4d.DTYPE_REAL, 1002, c4d.DTYPE_VECTOR], # Scale ] for data in dataVault: # Iterate through data vault if len(data) == 2: # Float desc = c4d.DescID(c4d.DescLevel(data[0], data[1], 0)) value = source[data[0]] if len(data) == 4: # Vector desc = c4d.DescID(c4d.DescLevel(data[0], data[3], 0), c4d.DescLevel(data[2], data[1], 0)) value = source[data[0], data[2]] track = target.FindCTrack(desc) # Try to find CTrack if not track: # If CTrack does not exists track = c4d.CTrack(target, desc) # Initialize CTrack target.InsertTrackSorted(track) # Insert CTrack to the object curve = track.GetCurve() # Get Curve of the CTrack currentTime = c4d.BaseTime(frame, fps) # Get current time key = curve.AddKey(currentTime)["key"] track.FillKey(doc, target, key) if data[1] == c4d.DTYPE_REAL: # Float key.SetValue(curve, value) else: # If boolean or integer key.SetValue(curve, value) key.SetGeData( curve, value) # Keyframe value needs to be set with SetGeData
def getXYZtrack(obj, trackID, channelID, doc): # Find the Track param = c4d.DescID(c4d.DescLevel(trackID, c4d.DTYPE_VECTOR, 0), c4d.DescLevel(channelID, c4d.DTYPE_REAL, 0)) track = obj.FindCTrack(param) # Create if no track found if not track: track = c4d.CTrack(obj, param) doc.AddUndo(c4d.UNDOTYPE_NEW, track) obj.InsertTrackSorted(track) return track
def createKey(op, id, value, forFrame=None): doc = op.GetDocument() if not doc: raise Exception, "object must be in a document" if forFrame == None: forFrame = frame(doc) # First check if the track type already exists, otherwise create it... track = op.FindCTrack(id) if not track: track = c4d.CTrack(op, id) op.InsertTrackSorted(track) curve = track.GetCurve() key = curve.AddKey(c4d.BaseTime(forFrame, doc.GetFps())) if type(value) == int or type(value) == float: key["key"].SetValue(curve, value) else: key["key"].SetGeData(curve, value)
def insertKeys(id, keyArray): keyCount = len( keyBrowsInnerUp ) #Finding the length of one to the AU arrays finds the length of them all, as well as the number of frames in the imported animation FPS = doc.GetFps() #Get the frames per second of the current scene uDataTrack = c4d.CTrack( op, id) #Save the animation track, we'll need it to insert keys uDataCurve = uDataTrack.GetCurve() i = 0 while (i < keyCount): #loop through the values of the AUs and insert keys frameNo = (startKeyingFrame + i) frameTime = c4d.BaseTime(frameNo, FPS) auKey = c4d.CKey() #Create a key auKey.SetTime(uDataCurve, frameTime) auKey.SetValue(uDataCurve, float(keyArray[i])) uDataCurve.InsertKey(auKey) i += 1 op.InsertTrackSorted(uDataTrack)
def key( Parameter ): # Define a function called "key", which will act as a container for the script to be implemented in other scripts. CurrentTime = doc.GetTime( ) # Define CurrentTime to look for the current time in the project CurrentFrame = CurrentTime.GetFrame( doc.GetFps() ) # Define CurrentFrame to calculate what the current frame is based on the frame rate of the project Active = doc.GetActiveObject( ) # Define Active to look for the currently selected object in the manager if Active == None: return # If there is no active object, quit Track = Active.FindCTrack( Parameter ) # Define Track to look for whether there is an animation track for the parameter in question if not Track: # If there is no animation track... doc.StartUndo( ) # Marks the beginning of a range of code that should be reversible Track = c4d.CTrack( Active, Parameter ) # Define Track to create a new animation track instead doc.AddUndo( c4d.UNDOTYPE_CHANGE, Active ) # Make the following placement of the new animation track reversible Active.InsertTrackSorted( Track) # Place the new animation track in the timeline Curve = Track.GetCurve( ) # Define Curve to look for the new animation track's curve Key = Curve.AddKey( c4d.BaseTime(CurrentFrame, doc.GetFps()) ) # Define Key to add a keyframe to the new animation track at the current frame doc.AddUndo( c4d.UNDOTYPE_CHANGE, Track) # Make the following filling of the keyframe reversible Track.FillKey(doc, Active, Key["key"]) # Fill the keyframe (make it red) doc.EndUndo( ) # Marks the end of a range of code that should be reversible c4d.EventAdd() # Refresh the scene to update the change
def set_key_with_id(obj, desc_id, val=None, frm=None): if frm == None: frm = get_current_frm() if val == None: val = obj[desc_id] # if type(val) != float: # raise ValueError("val must be float!") if type(val) == c4d.Vector or type(obj[desc_id]) == c4d.Vector: # c4d.VECTOR_X (1000) ~ c4d.VECTOR_Z (1002) for dim in range(3): desc_id_dim = (desc_id, 1000 + dim) set_key_with_id(obj, desc_id_dim, val[dim], frm) return else: pass key = get_key_with_id(obj, desc_id, frm) if type(key) == int: if key == -2: trk = c4d.CTrack(obj, desc_id) obj.InsertTrackSorted(trk) else: trk = obj.FindCTrack(desc_id) crv = trk.GetCurve() key = c4d.CKey() key.SetTime(crv, frm2bt(frm)) crv.InsertKey(key) else: crv = key.GetCurve() key = crv.FindKey(frm2bt(frm))["key"] idx = crv.FindKey(frm2bt(frm))["idx"] key.SetValue(crv, val) # http://www.plugincafe.com/forum/forum_posts.asp?TID=14107&PID=56307#56307 # https://plugincafe.maxon.net/topic/11698/beginner-how-can-i-set-a-key-frame-and-value-to-a-cube-by-python/3 key.SetInterpolation(crv, c4d.CINTERPOLATION_SPLINE) # kidx = crv.FindKey(frm2bt(frm))["idx"] crv.SetKeyDefault(doc, idx)
def main(): dlg = Dialog() dlg.Open(c4d.DLG_TYPE_MODAL_RESIZEABLE, defaultw=500) if not dlg.didPressOK: return DOCUMENT_FPS = dlg.document_fps CAMERA_FOV = dlg.camera_fov path = storage.LoadDialog(flags=2) if not path: print "No path found" return camInfoArr = parseXML(path) lastEl = camInfoArr[len(camInfoArr) - 1] pprint.pprint(camInfoArr) # Setup document doc = documents.GetActiveDocument() doc.SetFps(DOCUMENT_FPS) doc.SetMaxTime(c4d.BaseTime(lastEl['startTime'] + lastEl['length'])) rd = doc.GetActiveRenderData() rd[c4d.RDATA_FRAMERATE] = DOCUMENT_FPS # Create, setup and insert Camera object camera = c4d.BaseObject(c4d.Ocamera) camera[c4d.CAMERAOBJECT_FOV_VERTICAL] = CAMERA_FOV * math.pi / 180 doc.InsertObject(camera) posXtrack = c4d.CTrack(camera, [c4d.ID_BASEOBJECT_REL_POSITION, c4d.VECTOR_X]) posYtrack = c4d.CTrack(camera, [c4d.ID_BASEOBJECT_REL_POSITION, c4d.VECTOR_Y]) posZtrack = c4d.CTrack(camera, [c4d.ID_BASEOBJECT_REL_POSITION, c4d.VECTOR_Z]) rotXtrack = c4d.CTrack(camera, [c4d.ID_BASEOBJECT_REL_ROTATION, c4d.VECTOR_X]) rotYtrack = c4d.CTrack(camera, [c4d.ID_BASEOBJECT_REL_ROTATION, c4d.VECTOR_Y]) rotZtrack = c4d.CTrack(camera, [c4d.ID_BASEOBJECT_REL_ROTATION, c4d.VECTOR_Z]) camera.InsertTrackSorted(posXtrack) camera.InsertTrackSorted(posYtrack) camera.InsertTrackSorted(posZtrack) camera.InsertTrackSorted(rotXtrack) camera.InsertTrackSorted(rotYtrack) camera.InsertTrackSorted(rotZtrack) posXcurve = posXtrack.GetCurve() posYcurve = posYtrack.GetCurve() posZcurve = posZtrack.GetCurve() rotXcurve = rotXtrack.GetCurve() rotYcurve = rotYtrack.GetCurve() rotZcurve = rotZtrack.GetCurve() previousTransform = [0, 0, 0, 0, 0, 0] previousEndTime = 0 for camInfo in camInfoArr: startTime = camInfo['startTime'] length = camInfo['length'] endTime = startTime + length curveType = camInfo['curveType'] if round(previousEndTime, 5) != round(startTime, 5): # Set StartTime values posXkeyStart = c4d.CKey() posYkeyStart = c4d.CKey() posZkeyStart = c4d.CKey() rotXkeyStart = c4d.CKey() rotYkeyStart = c4d.CKey() rotZkeyStart = c4d.CKey() posXkeyStart.SetTime(posXcurve, c4d.BaseTime(startTime)) posXkeyStart.SetValue(posXcurve, previousTransform[0]) posYkeyStart.SetTime(posYcurve, c4d.BaseTime(startTime)) posYkeyStart.SetValue(posYcurve, previousTransform[1]) posZkeyStart.SetTime(posZcurve, c4d.BaseTime(startTime)) posZkeyStart.SetValue(posZcurve, previousTransform[2]) rotXkeyStart.SetTime(rotXcurve, c4d.BaseTime(startTime)) rotXkeyStart.SetValue(rotXcurve, previousTransform[3]) rotYkeyStart.SetTime(rotYcurve, c4d.BaseTime(startTime)) rotYkeyStart.SetValue(rotYcurve, previousTransform[4]) rotZkeyStart.SetTime(rotZcurve, c4d.BaseTime(startTime)) rotZkeyStart.SetValue(rotZcurve, previousTransform[5]) if (curveType == "Sinus"): tangentLength = c4d.BaseTime(length * (4.0 / 15.0)) nTangentLength = c4d.BaseTime(length * (4.0 / 15.0) * -1) # posXkeyStart.SetTimeLeft(posXcurve, nTangentLength) posXkeyStart.SetTimeRight(posXcurve, tangentLength) # posYkeyStart.SetTimeLeft(posYcurve, nTangentLength) posYkeyStart.SetTimeRight(posYcurve, tangentLength) # posZkeyStart.SetTimeLeft(posZcurve, nTangentLength) posZkeyStart.SetTimeRight(posZcurve, tangentLength) # rotXkeyStart.SetTimeLeft(rotXcurve, nTangentLength) rotXkeyStart.SetTimeRight(rotXcurve, tangentLength) # rotYkeyStart.SetTimeLeft(rotYcurve, nTangentLength) rotYkeyStart.SetTimeRight(rotYcurve, tangentLength) # rotZkeyStart.SetTimeLeft(rotZcurve, nTangentLength) rotZkeyStart.SetTimeRight(rotZcurve, tangentLength) posXcurve.InsertKey(posXkeyStart) posYcurve.InsertKey(posYkeyStart) posZcurve.InsertKey(posZkeyStart) rotXcurve.InsertKey(rotXkeyStart) rotYcurve.InsertKey(rotYkeyStart) rotZcurve.InsertKey(rotZkeyStart) # Set EndTime values posXkeyEnd = c4d.CKey() posYkeyEnd = c4d.CKey() posZkeyEnd = c4d.CKey() rotXkeyEnd = c4d.CKey() rotYkeyEnd = c4d.CKey() rotZkeyEnd = c4d.CKey() posXkeyEnd.SetTime(posXcurve, c4d.BaseTime(endTime)) posXkeyEnd.SetValue(posXcurve, camInfo['transform'][0]) posYkeyEnd.SetTime(posYcurve, c4d.BaseTime(endTime)) posYkeyEnd.SetValue(posYcurve, camInfo['transform'][1]) posZkeyEnd.SetTime(posZcurve, c4d.BaseTime(endTime)) posZkeyEnd.SetValue(posZcurve, camInfo['transform'][2]) rotXkeyEnd.SetTime(rotXcurve, c4d.BaseTime(endTime)) rotXkeyEnd.SetValue(rotXcurve, camInfo['transform'][3]) rotYkeyEnd.SetTime(rotYcurve, c4d.BaseTime(endTime)) rotYkeyEnd.SetValue(rotYcurve, camInfo['transform'][4]) rotZkeyEnd.SetTime(rotZcurve, c4d.BaseTime(endTime)) rotZkeyEnd.SetValue(rotZcurve, camInfo['transform'][5]) if (curveType == "Sinus"): tangentLength = c4d.BaseTime(length * (4.0 / 15.0)) nTangentLength = c4d.BaseTime(length * (4.0 / 15.0) * -1) posXkeyEnd.SetTimeLeft(posXcurve, nTangentLength) # posXkeyEnd.SetTimeRight(posXcurve, tangentLength) posYkeyEnd.SetTimeLeft(posYcurve, nTangentLength) # posYkeyEnd.SetTimeRight(posYcurve, tangentLength) posZkeyEnd.SetTimeLeft(posZcurve, nTangentLength) # posZkeyEnd.SetTimeRight(posZcurve, tangentLength) rotXkeyEnd.SetTimeLeft(rotXcurve, nTangentLength) # rotXkeyEnd.SetTimeRight(rotXcurve, tangentLength) rotYkeyEnd.SetTimeLeft(rotYcurve, nTangentLength) # rotYkeyEnd.SetTimeRight(rotYcurve, tangentLength) rotZkeyEnd.SetTimeLeft(rotZcurve, nTangentLength) # rotZkeyEnd.SetTimeRight(rotZcurve, tangentLength) posXcurve.InsertKey(posXkeyEnd) posYcurve.InsertKey(posYkeyEnd) posZcurve.InsertKey(posZkeyEnd) rotXcurve.InsertKey(rotXkeyEnd) rotYcurve.InsertKey(rotYkeyEnd) rotZcurve.InsertKey(rotZkeyEnd) # Set previousTransform to endTime values previousTransform = [ camInfo['transform'][0], camInfo['transform'][1], camInfo['transform'][2], camInfo['transform'][3], camInfo['transform'][4], camInfo['transform'][5] ] previousEndTime = endTime
def addRecording(mainDialog, exchangeData): if mainDialog.targetLink is None: createNewTarget(mainDialog) shapetracks = [] userDataCount = 0 for id, bc in mainDialog.targetLink.GetUserDataContainer(): userDataCount += 1 if userDataCount <= 53 and userDataCount > 1: shapeTrack = mainDialog.targetLink.FindCTrack(id) if shapeTrack is None: shapeTrack = c4d.CTrack(mainDialog.targetLink, id) mainDialog.targetLink.InsertTrackSorted(shapeTrack) shapetracks.append(shapeTrack) IDPOSX = c4d.DescID( c4d.DescLevel(c4d.ID_BASEOBJECT_POSITION, c4d.DTYPE_VECTOR, 0), c4d.DescLevel(c4d.VECTOR_X, c4d.DTYPE_REAL, 0)) IDPOSY = c4d.DescID( c4d.DescLevel(c4d.ID_BASEOBJECT_POSITION, c4d.DTYPE_VECTOR, 0), c4d.DescLevel(c4d.VECTOR_Y, c4d.DTYPE_REAL, 0)) IDPOSZ = c4d.DescID( c4d.DescLevel(c4d.ID_BASEOBJECT_POSITION, c4d.DTYPE_VECTOR, 0), c4d.DescLevel(c4d.VECTOR_Z, c4d.DTYPE_REAL, 0)) IDROTX = c4d.DescID( c4d.DescLevel(c4d.ID_BASEOBJECT_ROTATION, c4d.DTYPE_VECTOR, 0), c4d.DescLevel(c4d.VECTOR_X, c4d.DTYPE_REAL, 0)) IDROTY = c4d.DescID( c4d.DescLevel(c4d.ID_BASEOBJECT_ROTATION, c4d.DTYPE_VECTOR, 0), c4d.DescLevel(c4d.VECTOR_Y, c4d.DTYPE_REAL, 0)) IDROTZ = c4d.DescID( c4d.DescLevel(c4d.ID_BASEOBJECT_ROTATION, c4d.DTYPE_VECTOR, 0), c4d.DescLevel(c4d.VECTOR_Z, c4d.DTYPE_REAL, 0)) trackIDS = [IDPOSX, IDPOSY, IDPOSZ, IDROTX, IDROTY, IDROTZ] matrixTracks = [] trackCount = 0 while trackCount < len(trackIDS): newTrack = mainDialog.targetLink.FindCTrack(trackIDS[trackCount]) if newTrack is None: newTrack = c4d.CTrack(mainDialog.targetLink, trackIDS[trackCount]) mainDialog.targetLink.InsertTrackSorted(newTrack) matrixTracks.append(newTrack) trackCount += 1 #print ("frames to do")+str(len(exchangeData.recordetFrames)) frameCnt = 0 doc = c4d.documents.GetActiveDocument() testobj = c4d.BaseObject(c4d.Onull) curTime = c4d.documents.GetActiveDocument().GetTime().Get() * 1000 while frameCnt < len(exchangeData.recordetFrames): curFrame = exchangeData.recordetFrames[frameCnt] frameCnt += 1 frameTime = c4d.BaseTime( float(float(curTime) + float(curFrame.frameTime)) / 1000) curve = matrixTracks[0].GetCurve() key = c4d.CKey() key.SetTime(curve, frameTime) key.SetValue(curve, float(curFrame.headPosition.x)) curve.InsertKey(key) curve = matrixTracks[1].GetCurve() key = c4d.CKey() key.SetTime(curve, frameTime) key.SetValue(curve, float(curFrame.headPosition.y)) curve.InsertKey(key) curve = matrixTracks[2].GetCurve() key = c4d.CKey() key.SetTime(curve, frameTime) key.SetValue(curve, float(curFrame.headPosition.z)) curve.InsertKey(key) testobj.SetMl(curFrame.headRotation) rotationVec = testobj.GetRelRot() curve = matrixTracks[3].GetCurve() key = c4d.CKey() key.SetValue(curve, float(rotationVec.x)) key.SetTime(curve, frameTime) curve.InsertKey(key) curve = matrixTracks[4].GetCurve() key = c4d.CKey() key.SetValue(curve, float(rotationVec.y)) key.SetTime(curve, frameTime) curve.InsertKey(key) curve = matrixTracks[5].GetCurve() key = c4d.CKey() key.SetValue(curve, float(rotationVec.z)) key.SetTime(curve, frameTime) curve.InsertKey(key) shapesCounter = 0 while shapesCounter < len(curFrame.blendShapeValues): if shapesCounter > len(shapetracks): break if shapesCounter < len(shapetracks): shapeCurve = shapetracks[shapesCounter].GetCurve() keyShape = c4d.CKey() keyShape.SetTime(shapeCurve, frameTime) keyShape.SetValue(shapeCurve, curFrame.blendShapeValues[shapesCounter]) shapeCurve.InsertKey(keyShape) shapesCounter += 1 eyeGazeCounter = 48 eyeGazeCounter2 = 0 while eyeGazeCounter2 < len(curFrame.eyeGazeValues): if eyeGazeCounter > len(shapetracks): break if eyeGazeCounter < len(shapetracks): shapeCurve = shapetracks[eyeGazeCounter].GetCurve() keyShape = c4d.CKey() keyShape.SetTime(shapeCurve, frameTime) keyShape.SetValue(shapeCurve, curFrame.eyeGazeValues[eyeGazeCounter2]) shapeCurve.InsertKey(keyShape) eyeGazeCounter2 += 1 eyeGazeCounter += 1
def main(): # Open a file chooser wav_path = c4d.storage.LoadDialog(c4d.FSTYPE_ANYTHING, title="Select a WAVE (*.wav) File", flags=False) wave_name = os.path.basename(wav_path) # default name = filename if debug: print "wave_name: ", wave_name # Open the file wav = wave.open(wav_path, 'rb') #Get framerate and length wav_frame_rate = wav.getframerate() wav_num_frames = wav.getnframes() length_in_seconds = float(wav_num_frames) / float(wav_frame_rate) if debug: print "wav_frame_rate = ", wav_frame_rate print "wav_num_frames = ", wav_num_frames print "length_in_seconds = ", length_in_seconds #Create and name the Sound null object sound_obj = c4d.BaseObject(c4d.Onull) sound_obj.SetName("Sound: " + wave_name) #Add and hide the Sound object doc.InsertObject(sound_obj) doc.SetActiveObject(sound_obj) sound_obj.SetEditorMode(c4d.MODE_OFF) sound_obj.SetRenderMode(c4d.MODE_OFF) #Tell C4D something has changed c4d.EventAdd() #Add a Sound track sound_track = c4d.CTrack( sound_obj, c4d.DescID(c4d.DescLevel(c4d.CTsound, c4d.CTsound, 0))) sound_track[c4d.CID_SOUND_START] = c4d.BaseTime(1.0) sound_track[c4d.CID_SOUND_NAME] = wav_path sound_obj.InsertTrackSorted(sound_track) # #Set the Sound property to the wav file NOT WORKING # sound_track[c4d.CID_SOUND_NAME] = "Test.wav" # # if debug: # print "sound_track[c4d.CID_SOUND_NAME] = ", sound_track[c4d.CID_SOUND_NAME] #Tell C4D something has changed c4d.EventAdd() #Update Document Properties doc_frame_rate = doc.GetFps() rounded_max_time = round( round((length_in_seconds + 2.0) * doc_frame_rate) / doc_frame_rate) doc_max_time = c4d.BaseTime(rounded_max_time) doc.SetMaxTime(doc_max_time) #Store the current time old_time = doc.GetTime() #Open Timeline 4 (so marker command works) c4d.CallCommand(465001513) #Open Timeline 4 #Marker at 0 doc.SetTime(c4d.BaseTime(0.0)) c4d.CallCommand(465001124) #Add a Marker #Marker at 1 doc.SetTime(c4d.BaseTime(1.0)) c4d.CallCommand(465001124) #Add a Marker #Marker at 1 second til end doc.SetTime(c4d.BaseTime(rounded_max_time - 1.0)) c4d.CallCommand(465001124) #Add a Marker #Marker at end doc.SetTime(c4d.BaseTime(rounded_max_time)) c4d.CallCommand(465001124) #Add a Marker #Set Preview Range Min/Max doc.SetLoopMinTime(c4d.BaseTime(0.0)) doc.SetLoopMaxTime(c4d.BaseTime(rounded_max_time)) c4d.EventAdd() #Close Timeline 4 (to cleanup view) c4d.CallCommand(12392) #CloseWindow #Restore the time to before script doc.SetTime(old_time) c4d.EventAdd()
def Bake(source, target): """ Bake function """ doc = c4d.documents.GetActiveDocument() # Get active Cinema 4D document fps = doc.GetFps() # Get Frame Rate startFrame = doc.GetLoopMinTime().GetFrame( fps) # Get first frame of Preview Range endFrame = doc.GetLoopMaxTime().GetFrame( fps) # Get last frame of Preview Range for i in range(startFrame, endFrame + 1): # Iterate through Preview Range SetCurrentFrame(i, doc) # Set current frame frame = doc.GetTime().GetFrame(fps) # Get current frame dataVault = [ [903, c4d.DTYPE_REAL, 1000, c4d.DTYPE_VECTOR], [903, c4d.DTYPE_REAL, 1001, c4d.DTYPE_VECTOR], [903, c4d.DTYPE_REAL, 1002, c4d.DTYPE_VECTOR], # Position [904, c4d.DTYPE_REAL, 1000, c4d.DTYPE_VECTOR], [904, c4d.DTYPE_REAL, 1001, c4d.DTYPE_VECTOR], [904, c4d.DTYPE_REAL, 1002, c4d.DTYPE_VECTOR], # Rotation [905, c4d.DTYPE_REAL, 1000, c4d.DTYPE_VECTOR], [905, c4d.DTYPE_REAL, 1001, c4d.DTYPE_VECTOR], [905, c4d.DTYPE_REAL, 1002, c4d.DTYPE_VECTOR], # Scale # Basic [901, c4d.DTYPE_LONG], # Visible in Editor [902, c4d.DTYPE_LONG], # Visible in Renderer [907, c4d.DTYPE_LONG], # User Color [908, c4d.DTYPE_REAL, 1000, c4d.DTYPE_COLOR], [908, c4d.DTYPE_REAL, 1001, c4d.DTYPE_COLOR], [908, c4d.DTYPE_REAL, 1002, c4d.DTYPE_COLOR], # Display Color # Object [1001, c4d.DTYPE_LONG], # Projection [500, c4d.DTYPE_REAL], # Focal Length [1006, c4d.DTYPE_REAL], # Sensor Size [1008, c4d.DTYPE_REAL], # Field of View (Horizontal) [4600, c4d.DTYPE_REAL], # Field of View (Vertical) [1000, c4d.DTYPE_REAL], # Zoom [1118, c4d.DTYPE_REAL], # Film Offset X [1119, c4d.DTYPE_REAL], # Film Offset Y [1010, c4d.DTYPE_REAL], # Focus Distance #[1009, c4d.DTYPE_BOOL], #Use Target Object #[1130], # Focus Object [1311, c4d.DTYPE_REAL], # White Balance [1312, c4d.DTYPE_BOOL], # Affect Lights Only [1344, c4d.DTYPE_BOOL], # Export to Compositing # Physical #[1343, c4d.DTYPE_BOOL], # Movie Camera [1201, c4d.DTYPE_REAL], # F-Stop [1220, c4d.DTYPE_BOOL], # Exposure [1220, c4d.DTYPE_REAL], # ISO [1220, c4d.DTYPE_REAL], # Gain (dB) [1211, c4d.DTYPE_REAL], # Shutter Speed (s) [1212, c4d.DTYPE_REAL], # Shutter Angle [1213, c4d.DTYPE_REAL], # Shutter Offset [1213, c4d.DTYPE_REAL], # Shutter Effiency [1331, c4d.DTYPE_REAL], # Lens Distortion - Quadratic [1333, c4d.DTYPE_REAL], # Lens Distortion - Cubic [1321, c4d.DTYPE_REAL], # Vignetting Intensity [1322, c4d.DTYPE_REAL], # Vignetting Offset [1341, c4d.DTYPE_REAL], # Chromatic Aberration [1300, c4d.DTYPE_BOOL], # Diaphragm Shape [1301, c4d.DTYPE_LONG], # Blades [1302, c4d.DTYPE_REAL], # Angle [1303, c4d.DTYPE_REAL], # Bias [1306, c4d.DTYPE_REAL], # Anistropy # Details [1123, c4d.DTYPE_BOOL], # Enable Near Clipping [1122, c4d.DTYPE_REAL], # Near Clipping [1129, c4d.DTYPE_BOOL], # Enable Far Clipping [1128, c4d.DTYPE_REAL], # Far Clipping [1007, c4d.DTYPE_BOOL], # Show Cone [1111, c4d.DTYPE_BOOL], # DOF Map Front Blur [1112, c4d.DTYPE_REAL], # Front Blur Start [1113, c4d.DTYPE_REAL], # Front Blur End [1114, c4d.DTYPE_BOOL], # DOF Map Rear Blur [1115, c4d.DTYPE_REAL], # Rear Blur Start [1116, c4d.DTYPE_REAL], # Rear Blur End # Stereoscopic #[4200, c4d.DTYPE_LONG], # Mode #[4201, c4d.DTYPE_REAL], # Eye Separation #[4202, c4d.DTYPE_LONG], # Placement #[4207, c4d.DTYPE_BOOL], # Show All Cameras #[4205, c4d.DTYPE_REAL], # Zero Parallax #[4208, c4d.DTYPE_LONG], # Auto Planes #[4204, c4d.DTYPE_REAL], # Near Plane #[4206, c4d.DTYPE_REAL], # Far Plane #[4209, c4d.DTYPE_BOOL], # Show Floating Frame # Spherical [1160, c4d.DTYPE_BOOL], # Enable [1003, c4d.DTYPE_LONG], # FOV Helper [1004, c4d.DTYPE_LONG], # Mapping [1162, c4d.DTYPE_BOOL], # Fit Frame [1161, c4d.DTYPE_BOOL], # Use Full Range [1170, c4d.DTYPE_REAL], # Long Min [1171, c4d.DTYPE_REAL], # Long Max [1172, c4d.DTYPE_REAL], # Lat Min [1173, c4d.DTYPE_REAL], # Lat Max [1180, c4d.DTYPE_REAL] # Latitude ] for data in dataVault: # Iterate through data vault if len(data) == 2: # Float desc = c4d.DescID(c4d.DescLevel(data[0], data[1], 0)) value = source[data[0]] if len(data) == 4: # Vector desc = c4d.DescID(c4d.DescLevel(data[0], data[3], 0), c4d.DescLevel(data[2], data[1], 0)) value = source[data[0], data[2]] track = target.FindCTrack(desc) # Try to find CTrack if not track: # If CTrack does not exists track = c4d.CTrack(target, desc) # Initialize CTrack target.InsertTrackSorted(track) # Insert CTrack to the object curve = track.GetCurve() # Get Curve of the CTrack currentTime = c4d.BaseTime(frame, fps) # Get current time key = curve.AddKey(currentTime)["key"] track.FillKey(doc, target, key) if data[1] == c4d.DTYPE_REAL: # Float key.SetValue(curve, value) else: # If boolean or integer key.SetValue(curve, value) key.SetGeData( curve, value) # Keyframe value needs to be set with SetGeData