Cinema 4D - Python Generator Object

From NoskeWiki
Revision as of 02:37, 6 February 2019 by NoskeWiki (talk | contribs) (Created page with "==About== {{DaughterPage|mother=Cinema 4D}} {{Incomplete}} ==Python Generator, Example 1: Generate Cube From Scratch== * Add a <b>Python Generator</b> object. ** The...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

About

NOTE: This page is a daughter page of: Cinema 4D


This represents a page the author has not finished yet, but hopefully will finish soon! As a wiki I can't guarantee the accuracy on any of these pages, but pages with this logo I can almost certainly guarantee DO contain errors and/or big omissions.


Python Generator, Example 1: Generate Cube From Scratch

  • Add a Python Generator object.
    • The default code for this will render a cube.
import c4d

def main():


Python Generator, Example 2: Generate Spline From Scratch

import c4d

def main():


Python Generator, Example 3: Modify a Sphere

import c4d

def main():


Python Generator, Example 4: Turn a Spline into Sweep Nurbs using User Data Variable to set Radius

  • Add a Python Generator object.
    • Replace this code with this:
import c4d
 
def main():
  # Get the child object (to use as the sweep spline)
  # Use GetClone so we aren't working on the object itself
  source = op.GetDown().GetClone() 
 
  # Create a Circle Primitive to act as the sweep profile
  circle = c4d.BaseObject(c4d.Osplinecircle) 
  # Set the radius based on UserData 1
  circle[c4d.PRIM_CIRCLE_RADIUS] = op[c4d.ID_USERDATA,1]
   
  # Create a new SweepNURBS
  sweep = c4d.BaseObject(c4d.Osweep)
   
  # Insert the source sweep spline under the SweepNURBS
  source.InsertUnder(sweep)
   
  # Insert the circle profile spline under the SweepNURBS
  circle.InsertUnder(sweep)
   
  # Return the SweepNURBS
  return sweep
  • Click Linear and draw a spline with a few points.
  • Place the spline as the child of "Python Generator".
  • In the Attributes window click User Data > Manage User Data
    • Rename this first user input from "Data" to "CircleRadius", float, float and minimum value to 0. Click okay.
    • Play with user data and see the change.
  • To extract the generated content (in this case a mesh) out, select "Python Generator" then "Make Editable"... and you'll have to remove the last spline (it was cloned).

NOTE: This exact example is from the Python: Generator - Cineversity, but doesn't have instructions on the Cineversity page.


Python Generator, Example 5: Generate a Grid of Text Numbers

import c4d
def main():
    SPACING = 200
    TEXT_SIZE = 100
    NUM_COLS = 5
    NUM_ROWS = 5
    
    master_txt = c4d.BaseObject(5178)  # Text
    master_txt[c4d.PRIM_TEXT_TEXT]=""  # Will just use as container
    for z in range(0, NUM_ROWS):
      for x in range(0, NUM_COLS):
        txt = c4d.BaseObject(5178)  # Text
        txt[c4d.PRIM_TEXT_TEXT] = str(x) + "," + str(z)  # Set text
        txt[c4d.PRIM_TEXT_HEIGHT] = TEXT_SIZE
        txt[c4d.ID_BASEOBJECT_REL_ROTATION,c4d.VECTOR_Y] = -1.571    # Rotate 90 degs
        txt[c4d.ID_BASEOBJECT_REL_POSITION,c4d.VECTOR_X] = x * SPACING
        txt[c4d.ID_BASEOBJECT_REL_POSITION,c4d.VECTOR_Z] = -z * SPACING
        txt.InsertUnder(master_txt)
    return master_txt


See Also


Links