Created
August 24, 2017 19:11
-
-
Save gr4ph0s/0badf708657aaa117be0f84dd176e2b8 to your computer and use it in GitHub Desktop.
Exemple for add / get marker inside c4d through python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Exemple for add / get marker inside c4d through python. | |
24/08/2017 | |
More informations => https://www.c4dcafe.com/ipb/forums/topic/99715-xpresso-using-marker-data/ | |
""" | |
import c4d | |
def get_all_marker(doc): | |
markers_list = list() | |
marker = c4d.documents.GetFirstMarker(doc) | |
while marker: | |
markers_list.append(marker) | |
marker = marker.GetNext() #Since a marker is a BaseList2D we can use GetNext for iterate | |
return markers_list | |
def get_marker_frame(markers_list, frame): | |
marker_list = list() | |
for marker in markers_list: | |
doc = marker.GetDocument() #Get the doc related to the marker | |
#Get the time of the marker in fps | |
time = marker[c4d.TLMARKER_TIME] | |
fps_time = time.GetFrame(doc.GetFps()) | |
#Get the time of the length in fps | |
length = marker[c4d.TLMARKER_LENGTH] | |
fps_length = length.GetFrame(doc.GetFps()) | |
#if user frame is betwen we add to the list | |
if fps_time <= frame <= fps_time + fps_length: | |
marker_list.append(marker) | |
return marker_list | |
def get_time_from_fps(doc, fps): | |
#Utility function that return a c4d.BaseTime from a given doc / fps | |
doc_fps = doc.GetFps() | |
return c4d.BaseTime(float(fps) / doc_fps) | |
def main(): | |
#Create marker | |
doc = c4d.documents.GetActiveDocument() | |
first_marker = c4d.documents.AddMarker(doc, None, get_time_from_fps(doc, 30), "first") | |
second_marker = c4d.documents.AddMarker(doc, None, get_time_from_fps(doc, 27), "second") | |
second_marker[c4d.TLMARKER_LENGTH] = get_time_from_fps(doc, 5) | |
c4d.EventAdd() | |
#Get data from them | |
markers = get_all_marker(doc) | |
marker_30fps = get_marker_frame(markers, 30) | |
print marker_30fps | |
if __name__=='__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment