Hi
Been using Cinema R20 for 3 months now and I am trying to create this camera rig.
No problem creating it manually innside cinema, but as a learning challenge i also wanted to try recreate it using python.
I got 2-3 weeks of python experience, so this code is a result of alot of googeling and hack and slash from other codes. Constructive feeback is always welcome of course 🙂
It's a simple camera right with multiple nulls in a hierarchy. The master has a couple of sliders that will be used to control the camera ( see attached file)
The creation of all the elements is in place. they are also in correct hierarchy.
The part i am struggling with now is how i am gonna connect the different parameters to the different sliders.
I have been trying to use python to create xpresso nodes and ports, with no luck.... that stuff is a mess for a beginner.
I did however have a bit more luck making python tags and adding python code there to link together the parameters and slider.
Here the issue is, i don't know how to add that inn to the "MAIN" python script that creates everything.
like:
pytag[c4d.TPYTHON_CODE] = # am i suppose to type the whole python tag code as a string innside here?????
Hope someone one have time to spare to help me out with this one 🙂 thanks!
"The code as far as i have come noe"
import c4d
import math
from c4d import gui
# Welcome to the world of Python
# Script state in the menu or the command palette
# Return True or c4d.CMD_ENABLED to enable, False or 0 to disable
# Alternatively return c4d.CMD_ENABLED|c4d.CMD_VALUE to enable and check/mark
#def state():
# return True
# User Data functions
def HeadingDataType(x):
if x is None: return
bc = c4d.GetCustomDataTypeDefault(c4d.DTYPE_REAL) # Create default container
bc[c4d.DESC_NAME] = "Heading" # Rename the entry
bc[c4d.DESC_UNIT] = c4d.DESC_UNIT_DEGREE
bc[c4d.DESC_STEP] = math.radians(0.1)
bc[c4d.DESC_CUSTOMGUI] = c4d.CUSTOMGUI_REALSLIDER
bc[c4d.DESC_MIN] = math.radians(-360)
bc[c4d.DESC_MAX] = math.radians(360)
element = x.AddUserData(bc) # Add userdata container
c4d.EventAdd() # Update
def PitchDataType(x):
if x is None: return
bc = c4d.GetCustomDataTypeDefault(c4d.DTYPE_REAL) # Create default container
bc[c4d.DESC_NAME] = "Pitch" # Rename the entry
bc[c4d.DESC_UNIT] = c4d.DESC_UNIT_DEGREE
bc[c4d.DESC_STEP] = math.radians(0.1)
bc[c4d.DESC_CUSTOMGUI] = c4d.CUSTOMGUI_REALSLIDER
bc[c4d.DESC_MIN] = math.radians(-360)
bc[c4d.DESC_MAX] = math.radians(360)
element = x.AddUserData(bc) # Add userdata container
c4d.EventAdd() # Update
def BankDataType(x):
if x is None: return
bc = c4d.GetCustomDataTypeDefault(c4d.DTYPE_REAL) # Create default container
bc[c4d.DESC_NAME] = "Bank" # Rename the entry
bc[c4d.DESC_UNIT] = c4d.DESC_UNIT_DEGREE
bc[c4d.DESC_STEP] = math.radians(0.1)
bc[c4d.DESC_CUSTOMGUI] = c4d.CUSTOMGUI_REALSLIDER
bc[c4d.DESC_MIN] = math.radians(-360)
bc[c4d.DESC_MAX] = math.radians(360)
element = x.AddUserData(bc) # Add userdata container
c4d.EventAdd() # Update
def FocusDataType(x):
if x is None: return
bc = c4d.GetCustomDataTypeDefault(c4d.DTYPE_REAL) # Create default container
bc[c4d.DESC_NAME] = "Focus" # Rename the entry
bc[c4d.DESC_UNIT] = c4d.DESC_UNIT_REAL
bc[c4d.DESC_STEP] = 0.1
bc[c4d.DESC_CUSTOMGUI] = c4d.CUSTOMGUI_REALSLIDER
bc[c4d.DESC_MIN] = -1000
bc[c4d.DESC_MAX] = 1000
element = x.AddUserData(bc) # Add userdata container
c4d.EventAdd() # Update
# Main function
def main():
nMaster = c4d.BaseObject(c4d.Onull)
nMaster.SetRelPos(c4d.Vector(0))
nMaster[c4d.NULLOBJECT_DISPLAY]= c4d.NULLOBJECT_DISPLAY_HEXAGON
nMaster[c4d.NULLOBJECT_ORIENTATION] = c4d.NULLOBJECT_ORIENTATION_XY
nMaster.SetName("Camera_" + "Master")
nBank = c4d.BaseObject(c4d.Onull)
nBank.SetRelPos(c4d.Vector(0))
nBank[c4d.NULLOBJECT_DISPLAY]= c4d.NULLOBJECT_DISPLAY_HEXAGON
nBank[c4d.NULLOBJECT_ORIENTATION] = c4d.NULLOBJECT_ORIENTATION_XY
nBank.SetName("Camera_" + "Bank")
nPitch = c4d.BaseObject(c4d.Onull)
nPitch.SetRelPos(c4d.Vector(0))
nPitch[c4d.NULLOBJECT_DISPLAY]= c4d.NULLOBJECT_DISPLAY_POINT
nPitch[c4d.NULLOBJECT_ORIENTATION] = c4d.NULLOBJECT_ORIENTATION_XY
nPitch.SetName("Camera_" + "Pitch")
nHeading = c4d.BaseObject(c4d.Onull)
nHeading.SetRelPos(c4d.Vector(0))
nHeading[c4d.NULLOBJECT_DISPLAY]= c4d.NULLOBJECT_DISPLAY_CUBE
nHeading[c4d.NULLOBJECT_ORIENTATION] = c4d.NULLOBJECT_ORIENTATION_XY
nHeading.SetName("Camera_" + "Heading")
nFocus = c4d.BaseObject(c4d.Onull)
nFocus.SetRelPos(c4d.Vector(0))
nFocus[c4d.NULLOBJECT_DISPLAY]= c4d.NULLOBJECT_DISPLAY_STAR
nFocus[c4d.NULLOBJECT_ORIENTATION] = c4d.NULLOBJECT_ORIENTATION_XY
nFocus.SetName("Camera_" + "Focus")
newCam = c4d.BaseObject(c4d.Ocamera)
newCam[c4d.ID_BASEOBJECT_REL_POSITION,c4d.VECTOR_Z] = -50
newCam[c4d.CAMERAOBJECT_TARGETOBJECT] = nFocus
#Tags
expTag = nMaster.MakeTag(c4d.Texpresso)
#Camera Tags
camTarget = newCam.MakeTag(c4d.Ttargetexpression)
camTarget[c4d.TARGETEXPRESSIONTAG_LINK] = nMaster
focusTarget = nFocus.MakeTag(c4d.Ttargetexpression)
focusTarget[c4d.TARGETEXPRESSIONTAG_LINK] = newCam
#Protection Tags
nBank.MakeTag(c4d.Tprotection)
nPitch.MakeTag(c4d.Tprotection)
nHeading.MakeTag(c4d.Tprotection)
nFocus.MakeTag(c4d.Tprotection)
newCam.MakeTag(c4d.Tprotection)
doc.InsertObject(nMaster)
doc.InsertObject(nBank)
doc.InsertObject(nPitch)
doc.InsertObject(nHeading)
doc.InsertObject(newCam)
doc.InsertObject(nFocus)
nHeading.InsertUnder(nMaster)
nPitch.InsertUnder(nHeading)
nBank.InsertUnder(nPitch)
newCam.InsertUnder(nBank)
nFocus.InsertUnder(nBank)
HeadingDataType(nMaster)
PitchDataType(nMaster)
BankDataType(nMaster)
FocusDataType(nMaster)
c4d.EventAdd()
# Execute main()
if __name__ == "__main__":
main()
Camera_rig_01.c4d