Hello,
I found a script online which coverts c4d position and rotation values into a csv which I need for a broadcast graphics program I use. I converted that script into a plugin and it works well except I have to set the frame range every time I use it.
What I'm trying to do is have the range read the base document loop bar min and max time (frame) to avoid having to enter the frame range manually but am having no luck as I'm a python noob.
Any help is appreciated.
(Also I apologize if I put this in the wrong place..... I'm new here)
Here is the code.... It always defaults to Start at 0 and End at 90 currently.
# Dialog for frame range
class OptionsDialog(gui.GeDialog):
LOGO = BANNER()
def CreateLayout(self):
self.SetTitle('XPression CSV Animation Exporter')
self.GroupBegin(0, c4d.BFH_CENTER | c4d.BFV_CENTER, cols=1)
self.GroupBorderNoTitle(c4d.BORDER_NONE)
self.GroupBorderSpace(0, 0, 0, 20)
self.AddUserArea(1, c4d.BFV_CENTER | c4d.BFV_CENTER)
self.AttachUserArea(self.LOGO, 1)
#self.GroupEnd()
# end logo group
self.AddStaticText(LBL_INFO1, c4d.BFH_LEFT, name='Start Frame')
self.AddEditNumber(START_FRAME, c4d.BFH_SCALEFIT)
self.SetInt32(START_FRAME, 0) # Default 'start' string.
self.AddStaticText(LBL_INFO2, c4d.BFH_LEFT, name='End Frame')
self.AddEditNumber(END_FRAME, c4d.BFH_SCALEFIT)
self.SetInt32(END_FRAME, 90) # Default 'end' string.
# Buttons - an Ok and Cancel button:
self.GroupBegin(GROUP_OPTIONS, c4d.BFH_CENTER, 2, 1)
self.AddButton(BTN_OK, c4d.BFH_SCALE, name='Export CSV')
self.AddButton(BTN_CANCEL, c4d.BFH_SCALE, name='Cancel')
self.GroupEnd()
self.ok = False
return True
# React to user's input:
def Command(self, id, msg):
if id==BTN_CANCEL:
self.Close()
elif id==BTN_OK:
self.ok = True
obj = doc.GetActiveObject()
#if len(obj) <= 0:
#gui.MessageDialog('Must select objects!')
name = obj.GetName()
file = c4d.storage.SaveDialog(c4d.FILESELECTTYPE_ANYTHING, title='Save csv file as', force_suffix='csv')
csv_file = open(file, 'w')
for frame in range(self.GetInt32(START_FRAME), self.GetInt32(END_FRAME)+1) :
btNum = frame
btDen = doc.GetFps()
bt = c4d.BaseTime(btNum, btDen)
doc.SetTime(bt)
doc.ExecutePasses(None, True, True, True, c4d.BUILDFLAGS_0)
obj_matrix = obj.GetMg()
position = obj_matrix.off
rotation_rad = c4d.utils.MatrixToHPB(obj_matrix,c4d.ROTATIONORDER_HPB)
rotation_deg = c4d.Vector(c4d.utils.Deg(rotation_rad.x), c4d.utils.Deg(rotation_rad.y), c4d.utils.Deg(rotation_rad.z))
line = '%s, %s, %s, %s, %s, %s, %s'%(frame,
position.x,
position.y,
position.z,
rotation_deg.y,
rotation_deg.x,
rotation_deg.z)
csv_file.write(line + '\n')
csv_file.close()
self.Close()
return True