Beispiel #1
0
        def freezeChilds(parentObj=""):
            doc = c4d.documents.GetActiveDocument()
            obj = doc.SearchObject(parentObj)
            if obj:
                for x in obj.GetChildren():
                    c4d.CallButton(x, c4d.ID_BASEOBJECT_FREEZE_R)
                    c4d.CallButton(x, c4d.ID_BASEOBJECT_FREEZE_P)

                c4d.EventAdd()
Beispiel #2
0
def CreateSpline(interpolation = 2):
    doc = c4d.documents.GetActiveDocument() # Get active Cinema 4D document
    selection = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_SELECTIONORDER) # Get active object selection (selection order enabled)
    positions = [] # Initialize empty list for objects' positions
    points = [] # Initialize empty list for spline points
    if interpolation < 2: interpolation = 2 # If too few points, fix it
    try: # Try to execute following script
        for obj in selection: # Loop through object in selection
            pos = obj.GetMg().off # Get objects global position
            positions.append(pos) # Insert object's position to position list
            doc.AddUndo(c4d.UNDOTYPE_BITS, obj) # Add undo command for changing bits
            obj.DelBit(c4d.BIT_ACTIVE) # Deselect object in Object Manager
        pointCount = interpolation*(len(positions)-1) # Calculate point count
        for x in range(0, len(positions)-1): # Loop through
            for i in range(0, interpolation): # Loop through
                step = 1.0/float((interpolation-1.0)) # Calculate new step for point
                point = u.MixVec(positions[x],positions[x+1],step*float(i)) # Calculate point position
                points.append(point) # Insert point position to points list
        spline = c4d.SplineObject(pointCount, c4d.SPLINETYPE_LINEAR) # Initialize spline object
        spline.SetAllPoints(points) # Set spline points from points list
        doc.InsertObject(spline) # Insert spline object to document
        doc.AddUndo(c4d.UNDOTYPE_NEW, spline) # Add undo command for creating new object
        spline[c4d.SPLINEOBJECT_TYPE] = 3 # Set spline's type to B-Spline
        spline[c4d.SPLINEOBJECT_INTERPOLATION] = 2 # Set spline's interpolation to Uniform
        doc.AddUndo(c4d.UNDOTYPE_CHANGE, spline) # Add undo command for making changes to spline object
        CenterAxis(spline) # Center spline's axis
        splinePointsCount = len(spline.GetAllPoints()) # Get spline point count
        pointSelection = spline.GetPointS() # Get spline point selection
        # Point A
        pointSelection.DeselectAll() # Deselect all spline points
        pointSelection.Select(0) # Select spline's first point
        objectA = selection[0] # First object
        constraintTagA = spline.MakeTag(1018074) # Create hair constraint tag
        constraintTagA[c4d.HAIR_CONSTRAINTS_TAG_ANCHOR_LINK] = objectA # Set link
        doc.ExecutePasses(None, 0, 1, 1, 0) # Needed when pressing buttons virtually
        c4d.CallButton(constraintTagA, c4d.HAIR_CONSTRAINTS_TAG_SET_ANCHOR) # Press 'Set' button
        c4d.EventAdd() # Refresh Cinema 4D
        # Point B
        pointSelection.DeselectAll() # Deselect all spline points
        pointSelection.Select(splinePointsCount-1) # Select spline's first point
        objectB = selection[1] # Second object
        constraintTagB = spline.MakeTag(1018074) # Create hair constraint tag
        constraintTagB[c4d.HAIR_CONSTRAINTS_TAG_ANCHOR_LINK] = objectB # Set link
        doc.ExecutePasses(None, 0, 1, 1, 0) # Needed when pressing buttons virtually
        c4d.CallButton(constraintTagB, c4d.HAIR_CONSTRAINTS_TAG_SET_ANCHOR) # Press 'Set' button
        c4d.EventAdd() # Refresh Cinema 4D
        # Rest of the stuff
        spline.InsertTag(c4d.BaseTag(1018068)) # Insert spline dynamics tag
        doc.AddUndo(c4d.UNDOTYPE_BITS, spline) # Add undo command for changing bits
        spline.SetBit(c4d.BIT_ACTIVE) # Select spline object in Object Manager
        c4d.CallCommand(14039) # Optimize, remove overlapping points
    except: # If something went wrong
        pass # Do nothing
def fireAction(pObj):
    tool = plugins.FindPlugin(doc.GetAction(), c4d.PLUGINTYPE_TOOL)
    if tool is not None:
        #gui.MessageDialog(tool)
        tool[c4d.MDATA_TRANSFER_OBJECT_LINK] = pObj
        c4d.CallButton(tool, c4d.MDATA_APPLY)
        c4d.EventAdd()
Beispiel #4
0
 def reset_bind_pose(self, c_meshes):
     for obj in c_meshes:
         tags = TagIterator(obj)
         for tag in tags:
             tag_type = tag.GetType()
             if tag_type == c4d.Tweights:
                 if c4d.GetC4DVersion() <= 22123:
                     tag[c4d.ID_CA_WEIGHT_TAG_SET] = 2005
                     c4d.CallButton(tag, c4d.ID_CA_WEIGHT_TAG_SET)
                     c4d.EventAdd()
                     break
                 else:
                     tag[c4d.ID_CA_WEIGHT_TAG_SET_BUTTON] = 2005
                     c4d.CallButton(tag, c4d.ID_CA_WEIGHT_TAG_SET_BUTTON)
                     c4d.EventAdd()
                     break
def CreateConnectorDynamics(obj):
    doc = c4d.documents.GetActiveDocument()  # Get active Cinema 4D document
    voroFrac = c4d.BaseObject(1036557)  # Initialize voronoi fracture object
    voroFrac[c4d.ID_BASELIST_NAME] = "Connector Dynamics"  # Set name
    voroFrac[c4d.ID_FRACTURE_COLORIZE] = 0  # Don't colorize fragments
    dynTag = c4d.BaseTag(180000102)  # Initialize dynamics body tag
    dynTag[
        c4d.
        RIGID_BODY_SPLIT_CACHE] = 2  # Set 'individual elements'' to 'top level'
    doc.AddUndo(c4d.UNDOTYPE_NEW,
                voroFrac)  # Add undo command for creating new object
    doc.InsertObject(voroFrac, None,
                     obj)  # Insert voronoi fracture object to document
    doc.AddUndo(c4d.UNDOTYPE_NEW,
                dynTag)  # Add undo command for creating new tag
    voroFrac.InsertTag(dynTag)  # Insert tag to voronoi fracture object
    doc.AddUndo(c4d.UNDOTYPE_CHANGE, obj)  # Add undo command
    obj.InsertUnder(voroFrac)  # Insert object under voronoi fracture object
    doc.ExecutePasses(None, 0, 1, 1,
                      0)  # Needed when pressing buttons virtually
    c4d.CallButton(
        voroFrac,
        c4d.ID_FRACTURE_AUTOCONNECTOR_ENABLE)  # Press 'Create Fixed Connector'
    connector = voroFrac.GetDown()  # Get connector object
    doc.AddUndo(c4d.UNDOTYPE_BITS,
                connector)  # Add undo command for changing bits
    connector.SetBit(c4d.BIT_ACTIVE)  # Select connector object
Beispiel #6
0
 def update_rig_axis(self, joint, rig_joint):
     joint_data = self.get_orientation(joint)
     if len(joint_data) == 0:
         return
     rotation_order = joint_data[0]
     index = self.find_order(rotation_order)
     rig_joint[c4d.ID_BASEOBJECT_ROTATION_ORDER] = index
     rig_joint.SetMg(joint.GetMg())
     c4d.CallButton(rig_joint, c4d.ID_BASEOBJECT_FREEZE_R)
 def CreateConstraintTag(spline, obj):
     constraintTag = spline.MakeTag(1018074)  # Create hair constraint tag
     doc.AddUndo(c4d.UNDOTYPE_NEW,
                 constraintTag)  # Add undo for creating a tag
     constraintTag[c4d.HAIR_CONSTRAINTS_TAG_ANCHOR_LINK] = obj  # Set link
     doc.ExecutePasses(None, 0, 1, 1,
                       0)  # Needed when pressing buttons virtually
     c4d.CallButton(
         constraintTag,
         c4d.HAIR_CONSTRAINTS_TAG_SET_ANCHOR)  # Press 'Set' button
Beispiel #8
0
def main():
    doc.StartUndo()
    selo = doc.GetActiveObjects(0)

    if len(selo) > 0:
        positions = []
        for o in selo:
            # store positions

            md = mo.GeGetMoData(o)
            if md is None: return False
            cnt = md.GetCount()
            marr = md.GetArray(c4d.MODATA_MATRIX)
            for i in reversed(xrange(0, cnt)):
                positions.append(marr[i].off + o.GetAbsPos())
            o.DelBit(c4d.BIT_ACTIVE)

        # make splines
        matrixA = positions[:len(positions) / 2]
        matrixB = positions[len(positions) / 2:]

        for x in xrange(0, len(matrixA)):
            points = []
            c = 10
            spline = c4d.SplineObject(c, c4d.SPLINETYPE_LINEAR)
            a = matrixA[x]  # first point
            b = matrixB[x]  # last point

            # subd spline
            for k in xrange(0, c):
                t = u.RangeMap(k, 0, c - 1, 0, 1, True)
                point = u.MixVec(a, b, t)
                points.append(point)

            spline.SetAllPoints(points)

            select_points = spline.GetPointS()
            pc = len(spline.GetAllPoints())
            select_points.DeselectAll()
            select_points.Select(0)
            select_points.Select(pc - 1)
            spline.InsertTag(c4d.BaseTag(1018068))
            tag = spline.MakeTag(1018068)
            doc.InsertObject(spline)
            doc.AddUndo(c4d.UNDOTYPE_NEW, spline)

            spline.SetBit(c4d.BIT_ACTIVE)

            c4d.CallButton(tag, c4d.HAIR_SDYNAMICS_TAG_SET_FIXED)
            c4d.EventAdd()
            doc.EndUndo()
def main():
    doc = c4d.documents.GetActiveDocument()
    selo = doc.GetActiveObjects(0)
    if len(selo) > 0:
        for o in selo:
                select_points = o.GetPointS()
                pc = len(o.GetAllPoints())
                select_points.DeselectAll()
                select_points.Select(0)
                name = o.GetName()
                nulla = c4d.BaseObject(c4d.Onull)
                if nulla is None:
                    return
                nulla[c4d.NULLOBJECT_DISPLAY] = 2
                nulla.SetAbsPos(c4d.Vector(o.GetPoint(0)[0],o.GetPoint(0)[1],o.GetPoint(0)[2]))
                nulla.SetName(name+" A")
                doc.InsertObject(nulla)
                aTag = o.MakeTag(1018074)
                aTag[c4d.HAIR_CONSTRAINTS_TAG_ANCHOR_LINK] = nulla
                doc.ExecutePasses(None, 0, 1, 1, 0)
                c4d.CallButton(aTag, c4d.HAIR_CONSTRAINTS_TAG_SET_ANCHOR)
                c4d.EventAdd()                
                select_points.DeselectAll()
                select_points.Select(pc-1)
                nullb = c4d.BaseObject(c4d.Onull)
                if nullb is None:
                    return
                nullb[c4d.NULLOBJECT_DISPLAY] = 2
                nullb.SetAbsPos(c4d.Vector(o.GetPoint(pc-1)[0],o.GetPoint(pc-1)[1],o.GetPoint(pc-1)[2]))
                nullb.SetName(name+" B")
                doc.InsertObject(nullb)
                bTag = o.MakeTag(1018074)
                bTag[c4d.HAIR_CONSTRAINTS_TAG_ANCHOR_LINK] = nullb
                doc.ExecutePasses(None, 0, 1, 1, 0)
                c4d.CallButton(bTag, c4d.HAIR_CONSTRAINTS_TAG_SET_ANCHOR)
                c4d.EventAdd()                
                o.InsertTag(c4d.BaseTag(1018068))
    c4d.EventAdd()
def makeConnections(spline,selo):    
    select_points = spline.GetPointS()
    pc = len(spline.GetAllPoints())
    select_points.DeselectAll()
    select_points.Select(0)
    
    # point a
    aTag = spline.MakeTag(1018074)
    aTag[c4d.HAIR_CONSTRAINTS_TAG_ANCHOR_LINK] = selo[0]
    doc.ExecutePasses(None, 0, 1, 1, 0)
    c4d.CallButton(aTag, c4d.HAIR_CONSTRAINTS_TAG_SET_ANCHOR)
    c4d.EventAdd()
    
    select_points.DeselectAll()
    select_points.Select(pc-1)
    
    # point b
    bTag = spline.MakeTag(1018074)
    bTag[c4d.HAIR_CONSTRAINTS_TAG_ANCHOR_LINK] = selo[1]
    doc.ExecutePasses(None, 0, 1, 1, 0)
    c4d.CallButton(bTag, c4d.HAIR_CONSTRAINTS_TAG_SET_ANCHOR)
    c4d.EventAdd()
    spline.InsertTag(c4d.BaseTag(1018068))
def main():
    fn = s.LoadDialog(c4d.FILESELECTTYPE_ANYTHING, "Select reference file",
                      c4d.FILESELECT_LOAD)
    if fn == None: return None
    res = g.InputDialog("Resolution", "1280x720")
    width = float(res.split("x")[0])
    height = float(res.split("x")[1])
    ren = doc.GetActiveRenderData()
    zpos = ren[c4d.RDATA_XRES_VIRTUAL]
    c4d.CallCommand(12544)  # Create new viewport
    bd = doc.GetActiveBaseDraw()
    cam = c4d.BaseObject(c4d.Ocamera)
    cam.SetName("REFERENCE_CAMERA")
    cam[c4d.CAMERAOBJECT_TARGETDISTANCE] = width
    cam[c4d.ID_BASEOBJECT_VISIBILITY_RENDER] = 2
    doc.InsertObject(cam)
    plane = c4d.BaseObject(c4d.Oplane)
    plane[c4d.ID_BASEOBJECT_VISIBILITY_RENDER] = 2
    plane.SetName("REFERENCE_PLANE")
    plane[c4d.PRIM_AXIS] = 5
    plane[c4d.PRIM_PLANE_SUBW] = 1
    plane[c4d.PRIM_PLANE_SUBH] = 1
    plane[c4d.PRIM_PLANE_WIDTH] = width
    plane[c4d.PRIM_PLANE_HEIGHT] = height
    plane[c4d.ID_BASEOBJECT_REL_POSITION, c4d.VECTOR_Z] = zpos
    plane.InsertUnder(cam)
    mat = c4d.BaseMaterial(c4d.Mmaterial)
    mat.SetName("REFERENCE_MATERIAL")
    mat[c4d.MATERIAL_USE_REFLECTION] = 0
    mat[c4d.MATERIAL_ANIMATEPREVIEW] = 1
    color = c4d.BaseShader(c4d.Xbitmap)
    color[c4d.BITMAPSHADER_FILENAME] = fn
    doc.ExecutePasses(None, 0, 1, 1, 0)
    c4d.CallButton(color, c4d.BITMAPSHADER_CALCULATE)
    mat[c4d.MATERIAL_COLOR_SHADER] = color
    mat.InsertShader(color)
    mat.Message(c4d.MSG_UPDATE)
    mat.Update(True, True)
    doc.InsertMaterial(mat)
    t = c4d.BaseTag(5616)
    plane.InsertTag(t)
    tag = plane.GetFirstTag()
    tag[c4d.TEXTURETAG_MATERIAL] = mat
    tag[c4d.TEXTURETAG_PROJECTION] = 6
    bd[c4d.BASEDRAW_DATA_TINTBORDER_OPACITY] = 1
    bd[c4d.BASEDRAW_DATA_CAMERA] = cam
    bd[c4d.BASEDRAW_TITLE] = "REFERENCE_VIEWPORT"
    cam[c4d.ID_BASEOBJECT_REL_POSITION, c4d.VECTOR_X] = 5000000
    c4d.EventAdd()
Beispiel #12
0
def main():  # Define the main function of the script

    tool = plugins.FindPlugin(
        doc.GetAction(), c4d.PLUGINTYPE_TOOL
    )  # Define tool to find what the currently selected tool
    if tool is not None:  # If there is a tool:
        doc.StartUndo(
        )  # Marks the beginning of a range of code that should be reversible
        doc.AddUndo(c4d.UNDOTYPE_CHANGE,
                    tool)  # Make the following button click reversible
        c4d.CallButton(tool, c4d.MDATA_APPLY)  # Make the "Apply" button click
        c4d.EventAdd()  # Refresh the scene to update the change
        doc.EndUndo(
        )  # Marks the end of a range of code that should be reversible
    c4d.EventAdd()  # Refresh the scene to update the change
Beispiel #13
0
 def update_axis(self, joint):
     joint_data = self.get_orientation(joint)
     if len(joint_data) == 0:
         return
     rotation_order = joint_data[0]
     index = self.find_order(rotation_order)
     x = joint_data[1]
     y = joint_data[2]
     z = joint_data[3]
     joint[c4d.ID_BASEOBJECT_ROTATION_ORDER] = index
     self.store_incorrect_orientations(joint)
     matrix = joint.GetMl() * c4d.utils.MatrixRotX(c4d.utils.Rad(x))
     matrix = matrix * c4d.utils.MatrixRotY(c4d.utils.Rad(y))
     matrix = matrix * c4d.utils.MatrixRotZ(c4d.utils.Rad(-1 * z))
     self.move_axis(joint, matrix)
     c4d.CallButton(joint, c4d.ID_BASEOBJECT_FREEZE_R)
Beispiel #14
0
def main():
    name = "cube"
    if doc.SearchObject(name) == None:
        return
    else:
        obj = doc.SearchObject(name)  #defines the obj which i cube. OK
        dis = obj.GetTag(c4d.Tdisplay)  #defines the tag which is display.OK
        doc.SetActiveTag(dis, mode=c4d.SELECTION_NEW)  #Selects tag. OK
        dis[c4d.
            DISPLAYTAG_SDISPLAYMODE] = 2  # How do I enable the Use button? In level of detail it is automatically enabled.
        dis[c4d.DISPLAYTAG_WDISPLAYMODE] = 1  #
        dis[c4d.
            DISPLAYTAG_AFFECT_LEVELOFDETAIL] = 80  #Gives me an error: invalid cross-threadcall. I searched for the c4d.utils if there is an option to translate a number to percentage but I can't seem to find any.
        dis[c4d.
            DISPLAYTAG_AFFECT_BACKFACECULLING] = TRUE  # I was under the impression that boolean only takes True or False. correct me if I'm wrong but this Gives me an error:TRUE is not defined.
        c4d.CallButton(dis, c4d.ONION_CALCULATE)  #Calculates the cache. OK

    c4d.EventAdd()
Beispiel #15
0
def SkinInitial(a, b, op):
    global i
    op[c4d.ID_BASELIST_NAME] = "combine" + str(i)
    c4d.CallCommand(1019363, 1019363)  # 蒙皮
    meng = doc.GetActiveObject()
    meng.InsertUnder(op)
    meng[c4d.ID_CA_SKIN_OBJECT_INCEXC] = 0
    data = meng[c4d.ID_CA_SKIN_OBJECT_INCLUDE]
    data.InsertObject(op, 1)
    meng[c4d.ID_CA_SKIN_OBJECT_INCLUDE] = data

    op.KillTag(c4d.Tweights, 1)
    tagweight = op.GetTag(c4d.Tweights, 0)
    first = op.GetFirstTag()
    op.InsertTag(tagweight, first)
    op.InsertTag(first, tagweight)
    tagweight[c4d.ID_CA_WEIGHT_TAG_TOTALWEIGHT] = 0
    c4d.CallButton(tagweight, c4d.ID_CA_WEIGHT_TAG_SET)
    tagweight[c4d.ID_CA_WEIGHT_TAG_TOTALWEIGHT] = 1
    c4d.EventAdd()
Beispiel #16
0
def add_redshift_tag(obj, layer, geometry, tessellation, tess_min, tess_max,
                     displacement, dis_max, dis_scale, dis_autobump, reference,
                     ref_source, obj_id, obj_id_value):
    # get obj tags
    obj_tags = obj.GetTags()
    # define tag
    if not obj_tags:
        tag = obj.MakeTag(TAG_REDSHIFT_ID)  # new tag
    else:
        obj_tags_types = []  # list of tag types
        for t in obj_tags:
            obj_tags_types.append(t.GetType())
            if t.GetType() == TAG_REDSHIFT_ID:
                tag = t
        if not TAG_REDSHIFT_ID in obj_tags_types:
            tag = obj.MakeTag(TAG_REDSHIFT_ID)

    # basic tab
    tag[c4d.ID_LAYER_LINK] = layer
    # geometry tab
    if geometry:
        tag[c4d.REDSHIFT_OBJECT_GEOMETRY_OVERRIDE] = geometry
        tag[c4d.REDSHIFT_OBJECT_GEOMETRY_SUBDIVISIONENABLED] = tessellation
        tag[c4d.REDSHIFT_OBJECT_GEOMETRY_MINTESSELLATIONLENGTH] = tess_min
        tag[c4d.REDSHIFT_OBJECT_GEOMETRY_MAXTESSELLATIONSUBDIVS] = tess_max
    # displacement tab
    if displacement:
        tag[c4d.REDSHIFT_OBJECT_GEOMETRY_DISPLACEMENTENABLED] = displacement
        tag[c4d.REDSHIFT_OBJECT_GEOMETRY_MAXDISPLACEMENT] = dis_max
        tag[c4d.REDSHIFT_OBJECT_GEOMETRY_DISPLACEMENTSCALE] = dis_scale
        tag[c4d.REDSHIFT_OBJECT_GEOMETRY_AUTOBUMPENABLED] = dis_autobump
    # reference projection
    if reference:
        tag[c4d.REDSHIFT_OBJECT_REFERENCE_SOURCE] = ref_source
        c4d.CallButton(tag(), c4d.REDSHIFT_OBJECT_REFERENCE_BUTTON_CAPTURE)
    # object id tab
    if obj_id:
        tag[c4d.REDSHIFT_OBJECT_OBJECTID_OVERRIDE] = obj_id
        tag[c4d.REDSHIFT_OBJECT_OBJECTID_ID] = obj_id_value

    return tag
def main():
    if op is None:
        return

    #Run Split Command
    s = Command_Split(op)

    #Insert FFD-Deformer under Split-Object and Fit
    ffd = c4d.BaseObject(c4d.Offd)
    doc.AddUndo(c4d.UNDOTYPE_NEW, ffd)
    doc.InsertObject(ffd)
    ffd.InsertUnder(s)
    c4d.CallButton(ffd, c4d.FFDOBJECT_FITTOPARENT)

    #Clone that FFD-Deformer under our Original Object
    clone = ffd.GetClone()
    doc.AddUndo(c4d.UNDOTYPE_NEW, clone)
    clone.InsertUnder(op)

    #Remove Split-Object
    doc.AddUndo(c4d.UNDOTYPE_DELETE, s)
    s.Remove()

    c4d.EventAdd()
def main():
    fn = s.LoadDialog(c4d.FILESELECTTYPE_ANYTHING, "Select reference file",
                      c4d.FILESELECT_LOAD)  # Load file
    if fn == None: return None  # If no file, stop the script

    # Material
    mat = c4d.BaseMaterial(c4d.Mmaterial)  # Initialize material
    mat.SetName("REFERENCE_MATERIAL")  # Set material name
    mat[c4d.MATERIAL_USE_REFLECTION] = 0  # Disable reflection channel
    mat[c4d.MATERIAL_ANIMATEPREVIEW] = 1  # Enable 'Animate Preview'
    mat[c4d.
        MATERIAL_PREVIEWSIZE] = 1  # Set 'Texture Preview Size' to 'No Scaling'
    shader = c4d.BaseShader(c4d.Xbitmap)  # Initialize bitmap shader
    shader[c4d.BITMAPSHADER_FILENAME] = fn  # Set bitmap file
    doc.ExecutePasses(None, 0, 1, 1,
                      0)  # Needed when pressing buttons virtually
    c4d.CallButton(
        shader,
        c4d.BITMAPSHADER_CALCULATE)  # Press 'Animation>Calculate' button
    mat[c4d.
        MATERIAL_COLOR_SHADER] = shader  # Set shader to material's color channel
    mat.InsertShader(shader)  # Insert shader to color channel
    mat.Message(c4d.MSG_UPDATE)  # Update material
    mat.Update(True, True)  # Update material
    irs = c4d.modules.render.InitRenderStruct(
    )  # Needed to get shader's bitmap info
    if shader.InitRender(irs) == c4d.INITRENDERRESULT_OK:
        bitmap = shader.GetBitmap()  # Get bitmap
        shader.FreeRender()  # Frees all resources used by this shader
        if bitmap is not None:  # If there is bitmap
            width = bitmap.GetSize()[0]  # Get bitmap width in pixels
            height = bitmap.GetSize()[1]  # Get bitmap height in pixels
    doc.InsertMaterial(mat)  # Insert material to document

    # Camera
    cam = c4d.BaseObject(c4d.Ocamera)  # Initialize camera object
    cam.SetName("REFERENCE_CAMERA")  # Set camera name
    cam[c4d.
        CAMERAOBJECT_TARGETDISTANCE] = width  # Set camera focus to match bitmap width
    cam[c4d.
        ID_BASEOBJECT_VISIBILITY_RENDER] = 1  # Set camera's visible in rendeerr to off
    doc.InsertObject(cam)  # Insert camera to document

    # Plane
    plane = c4d.BaseObject(c4d.Oplane)  # Initialize plane object
    plane[
        c4d.
        ID_BASEOBJECT_VISIBILITY_RENDER] = 1  # Set plane's visible in renderer to off
    plane.SetName("REFERENCE_PLANE")  # Set plane name
    plane[c4d.PRIM_AXIS] = 5  # Set plane's orientation to -z
    plane[c4d.PRIM_PLANE_SUBW] = 1  # Set plane's width segments
    plane[c4d.PRIM_PLANE_SUBH] = 1  # Set plane's height segments
    plane[c4d.PRIM_PLANE_WIDTH] = width  # Set plane's width
    plane[c4d.PRIM_PLANE_HEIGHT] = height  # Set planes height
    plane[c4d.ID_BASEOBJECT_REL_POSITION,
          c4d.VECTOR_Z] = width  # Set plane's z position
    plane.InsertUnder(cam)  # Insert plane object under camera object

    # Tags
    t = c4d.BaseTag(5616)  # Initialize texture tag
    plane.InsertTag(t)  # Insert texture tag to object
    tag = plane.GetFirstTag()  # Get object's first tag
    tag[c4d.TEXTURETAG_MATERIAL] = mat  # Set material to texture tag
    tag[c4d.TEXTURETAG_PROJECTION] = 6  # Set texture projection to uvw mapping
    d = c4d.BaseTag(5613)  # Initialize display tag
    d[c4d.DISPLAYTAG_AFFECT_DISPLAYMODE] = True  # Use custom shading mode
    d[c4d.DISPLAYTAG_SDISPLAYMODE] = 7  # Use 'Constant Shading'
    d[c4d.DISPLAYTAG_AFFECT_TEXTURES] = True  # Use textures
    plane.InsertTag(d)  # Insert display tag to object

    # Base view
    c4d.CallCommand(12544)  # Create new viewport
    bd = doc.GetActiveBaseDraw()  # Get active base draw
    bd[c4d.
       BASEDRAW_DATA_TINTBORDER_OPACITY] = 1  # Set tinted borders for base view
    bd[c4d.BASEDRAW_DATA_CAMERA] = cam  # Set base view's camera
    bd[c4d.BASEDRAW_TITLE] = "REFERENCE_VIEWPORT"  # Set base view name

    cam[c4d.ID_BASEOBJECT_REL_POSITION,
        c4d.VECTOR_X] = 5000000  # Move camera far away
    c4d.EventAdd()  # Refresh Cinema 4D
Beispiel #19
0
def solo_layer(layer, state):
    layer_data = layer.GetLayerData(doc)
    layer_data["solo"] = state
    layer.SetLayerData(doc, layer_data)
    c4d.CallButton(layer, SOLO) # Solo Layer
    c4d.EventAdd()
Beispiel #20
0
def main():
    #get layers
    layerRoot = doc.GetLayerObjectRoot()
    layers = layerRoot.GetChildren()

    if len(layers) < 1:
        gui.MessageDialog('There Are No Layers...')
    else:
        c4d.CallCommand(1029486)  #open texture manager
        c4d.CallCommand(1029813)  #select all textures in texture manager
        c4d.CallCommand(1029820)  #globalize filenames
        #get renderpath
        userFilePath = c4d.storage.SaveDialog()

        if userFilePath == None:
            pass
        else:
            renderPath = os.path.dirname(userFilePath)
            renderFile = os.path.basename(userFilePath)
            #if it not yet exists create temp folder
            if not os.path.exists(renderPath + '/_tmp files'):
                os.makedirs(renderPath + '/_tmp files')
            #get rendersettings
            rd = doc.GetActiveRenderData()
            #get renderqueue
            rq = c4d.documents.GetBatchRender()
            rq.Open()
            cnt = 1

            #find light layer
            for i in layers:
                if i.GetName() == '_light':
                    lightLayer = i
                else:
                    lightLayer = None

            for i in layers:
                if i != lightLayer:
                    #un-solo all layers
                    for j in layers:
                        j[c4d.ID_LAYER_SOLO] = 0
                        #you need a callbutton command for this to work somehow...
                        c4d.CallButton(j, 100004726)
                    #solo layer
                    i[c4d.ID_LAYER_SOLO] = 1
                    c4d.CallButton(i, 100004726)
                    #solo light layer
                    if lightLayer != None:
                        lightLayer[c4d.ID_LAYER_SOLO] = 1
                        c4d.CallButton(i, 100004726)
                    c4d.EventAdd()
                    #set image path
                    rd[c4d.RDATA_PATH] = renderPath + '/' + "%02d" % (
                        cnt, ) + ' ' + renderFile + '_' + i.GetName()  #beauty
                    rd[c4d.
                       RDATA_MULTIPASS_FILENAME] = renderPath + '/' + "%02d" % (
                           cnt, ) + ' ' + renderFile + '_' + i.GetName(
                           ) + '_mp'  #mp
                    #turn on alpha
                    rd[c4d.RDATA_ALPHACHANNEL] = 1
                    rd[c4d.RDATA_STRAIGHTALPHA] = 1
                    #set format to PNG
                    rd[c4d.RDATA_FORMAT] = 1023671  #beauty
                    rd[c4d.RDATA_MULTIPASS_SAVEFORMAT] = 1023671  #mp
                    #set frame range to current frame
                    rd[c4d.RDATA_FRAMESEQUENCE] = 1
                    #save the document
                    outputFile = renderPath + '/_tmp files/' + "%02d" % (
                        cnt, ) + ' ' + renderFile + '_' + i.GetName()
                    c4d.documents.SaveDocument(doc, outputFile,
                                               c4d.SAVEDOCUMENTFLAGS_0,
                                               c4d.FORMAT_C4DEXPORT)
                    #add the file to the renderqueue
                    rq.AddFile(outputFile, cnt)
                    c4d.EventAdd()
                    #next
                    cnt += 1

                #un-solo all layers
                for i in layers:
                    i[c4d.ID_LAYER_SOLO] = 0
                    c4d.CallButton(i, 100004726)
Beispiel #21
0
def main():
	
	print
	print "======================================================================="
	print "Starting Coordinate System (Right to Left Y-up) Conversion"
	print "======================================================================="
	
	#Grab the active document
	doc = c4d.documents.GetActiveDocument()
	
	doc.StartUndo()
	
	
	# Disable all skin objects
	skinEnableMap = SetAllSkinEnable(False)

	
	# Move the joints to their new positions
	myobject = doc.GetFirstObject()
	if myobject == None: return

	while myobject:
	
		if myobject.CheckType(c4d.Ojoint):
			
			myobject.SetAbsRot(c4d.Vector(myobject.GetRelRot().x + c4d.utils.Rad(180), -myobject.GetRelRot().y, -myobject.GetRelRot().z)) # needs to be Radians
			newMatrix = myobject.GetMg()
			myobject.SetAbsRot(c4d.Vector(myobject.GetRelRot().x - c4d.utils.Rad(180), -myobject.GetRelRot().y, -myobject.GetRelRot().z)) # needs to be Radians
			
			print "Updating: " + myobject.GetName() + ", while freezing children"
			UpdateOnlyObject(myobject, newMatrix)
	
		myobject = GetNextObject(myobject)
		
	print "----------------------------------"
	
	
	
	
	# Set bind pose on all weight tags
	myobject = doc.GetFirstObject()
	if myobject == None: return

	while myobject:
		
		# Loop through all tags on object
		for tag in myobject.GetTags():
			# If we find a weigth tag
			if isinstance(tag, c4d.modules.character.CAWeightTag):
				print "Set bind pose of " + myobject.GetName()
				# Emulate a button click of "Set Bind Pose" on the Weight tag
				doc.AddUndo(c4d.UNDOTYPE_CHANGE, myobject)
				c4d.CallButton(tag, c4d.ID_CA_WEIGHT_TAG_SET)
				
		
		myobject = GetNextObject(myobject)
		
	print "----------------------------------"
	
	
	
	
	# Re-enable all skin objects that were enabled in the first place
	SetAllSkinEnable(True, skinEnableMap)
	
	
	
	
	
	# TODO: Now we rotate the null around the bones 180 degrees
	# Then put the axis back in place
	rootBoneObject = doc.GetFirstObject()
	if rootBoneObject == None: return

	while rootBoneObject:
		if rootBoneObject.CheckType(c4d.Onull) and rootBoneObject.GetDown().CheckType(c4d.Ojoint):
			print "Rotating All Bones via " + rootBoneObject.GetName()
		
			rootBoneObject.SetAbsRot(c4d.Vector(rootBoneObject.GetRelRot().x + c4d.utils.Rad(180), -rootBoneObject.GetRelRot().y, -rootBoneObject.GetRelRot().z)) # needs to be Radians
			newMatrix = rootBoneObject.GetMg()
			rootBoneObject.SetAbsRot(c4d.Vector(rootBoneObject.GetRelRot().x - c4d.utils.Rad(180), -rootBoneObject.GetRelRot().y, -rootBoneObject.GetRelRot().z)) # needs to be Radians
					
			# Rotate the matrix for this object
			UpdateOnlyObject(rootBoneObject, newMatrix)
			
			# Now that the axis is rotated, go back to normal
			doc.AddUndo(c4d.UNDOTYPE_CHANGE, rootBoneObject)
			rootBoneObject.SetAbsRot(c4d.Vector(rootBoneObject.GetRelRot().x + c4d.utils.Rad(180), -rootBoneObject.GetRelRot().y, -rootBoneObject.GetRelRot().z)) # needs to be Radians
			
		
		rootBoneObject = GetNextObject(rootBoneObject)
		
	print "----------------------------------"
	
	
	
	
	
	
	doc.EndUndo()
	c4d.EventAdd()
		
	print "Done..."