C4D script : Basic Test Scene

Hi,
My first python script for Cinema 4D that I made in order to create a simple scene for tests (floor + sphere + light).
Source Code:


import c4d
from c4d import Vector, BaseMaterial


def main():

    def assign_material(name, color, obj):
        material = BaseMaterial(c4d.Mmaterial)
        material.SetName(name)
        material[c4d.MATERIAL_COLOR_COLOR] = color
        doc.InsertMaterial(material)
        texture_tag = obj.MakeTag(c4d.Ttexture)
        texture_tag[c4d.TEXTURETAG_MATERIAL] = material
    
    sphere = c4d.BaseObject(c4d.Osphere)
    floor = c4d.BaseObject(c4d.Ofloor)
    light = c4d.BaseObject(c4d.Olight)

    doc.InsertObject(sphere)
    doc.InsertObject(floor)
    doc.InsertObject(light)
    
    light.SetAbsPos(Vector(-400, 400, -400))
    light[c4d.LIGHT_SHADOWTYPE] = 1

    sphere[c4d.PRIM_SPHERE_RAD] = 50
    sphere[c4d.PRIM_SPHERE_SUB] = 24
    sphere.SetAbsPos(Vector(0, 50, 0))
    sphere.SetPhong(True, True, 0.698132)
    
    assign_material('Sphere', Vector(0.925, 0.3, 0.053), sphere)
    assign_material('Floor', Vector(0.247, 0.247, 0.247), floor)

    c4d.EventAdd()

if __name__ == "__main__":
    main()

2 comments

  1. 44 string wrong

    must like this^
    if __name__=='__main__':

    ReplyDelete
  2. I forgot to move main() to the right at the end of the script.
    indentation can cause problems in python
    Thank you :), I corrected it now

    ReplyDelete