Beispiel #1
0
def main():
    # Retrieves render data and its container
    renderData = doc.GetActiveRenderData()
    bc = renderData.GetDataInstance()

    # Gets image filters options
    saveOptions = bc.GetContainerInstance(c4d.RDATA_SAVEOPTIONS)

    # Sets OpenEXR output format
    bc[c4d.RDATA_FORMAT] = c4d.FILTER_EXR

    # Defines OpenEXR settings
    compressionmethodID = maxon.Id('net.maxon.mediasession.openexr.export.compressionmethod')
    halffloatID = maxon.Id('net.maxon.mediasession.openexr.export.halffloat')
    layernumberingID = maxon.Id('net.maxon.mediasession.openexr.export.layernumbering')

    # Configures OpenEXR format options with a maxon.DataDictionary
    exportSettings = maxon.DataDictionary()
    exportSettings.Set(compressionmethodID, maxon.Id("rle"))
    exportSettings.Set(halffloatID, True)
    exportSettings.Set(layernumberingID, True)

    # Stores settings in render data container
    c4d.bitmaps.SetImageSettingsDictionary(exportSettings, saveOptions, c4d.FILTER_EXR)

    # Pushes an update event to Cinema 4D
    c4d.EventAdd()

    # Retrieves OpenEXR images settings
    settings = c4d.bitmaps.GetImageSettingsDictionary(saveOptions, c4d.FILTER_EXR)

    # Reads and prints OpenEXR format options
    print("openexr.export.compressionmethod: " + str(settings.Get(compressionmethodID)))
    print("openexr.export.halffloat: " + str(settings.Get(halffloatID)))
    print("openexr.export.layernumbering: " + str(settings.Get(layernumberingID)))
Beispiel #2
0
def main():
    # Retrieve the selected BaseMaterial
    mat = doc.GetActiveMaterial()
    if mat is None:
        raise ValueError("Cannot create a BaseMaterial")

    # Retrieve the reference of the material as a node material.
    nodeMaterial = mat.GetNodeMaterialReference()
    if nodeMaterial is None:
        raise ValueError("Cannot retrieve node material reference")

    # Retrieve the current node space Id
    nodespaceId = c4d.GetActiveNodeSpaceId()

    # Retrieve the Nimbus reference for a specific node space
    nimbusRef = mat.GetNimbusRef(nodespaceId)
    if nimbusRef is None:
        raise ValueError("Cannot retrieve the nimbus ref for that node space")

    # Retrieve the graph corresponding to that node space.
    graph = nimbusRef.GetGraph()
    if graph is None:
        raise ValueError("Cannot retrieve the graph of this nimbus ref")

    # Get the root of the GraphNode
    root = graph.GetRoot()

    # Retrieve all nodes, child of the root node
    nodes = list()
    root.GetChildren(nodes, maxon.frameworks.graph.NODE_KIND.NODE)

    # Create a list of the selected ones.
    selectedNodes = list()

    for node in nodes:
        if node.IsSelected():
            selectedNodes.append(node)

    # Group all the selected nodes in an empty node.
    groupRoot = maxon.frameworks.graph.GraphNode()

    # To modify a graph, modification must be done inside a transaction. After
    # modifications are done, the transaction must be committed.
    with graph.BeginTransaction() as transaction:
        graph.MoveToGroup(groupRoot, maxon.Id("idOfMyGroup"), selectedNodes)
        transaction.Commit()

    # Pushes an update event to Cinema 4D
    c4d.EventAdd()
def main():

    # Retrieve the current node space Id
    nodespaceId = c4d.GetActiveNodeSpaceId()

    # Create the material and retrieve the root of the graph
    root = CreateMaterialForNodeSpace(nodespaceId)

    # Start the recursive process on the first node
    PrintChildren(root)

    # Do the same with the Redshift node space. The Redshift plugin is not
    # installed by default, so we call the function in an exception handling
    # context.
    redShiftNodeSpPaceId = maxon.Id(
        'com.redshift3d.redshift4c4d.class.nodespace')
    try:
        root = CreateMaterialForNodeSpace(redShiftNodeSpPaceId)
        PrintChildren(root)
    except:
        print(f"The node space with id {redShiftNodeSpPaceId} does not exist")

    # Pushes an update event to Cinema 4D
    c4d.EventAdd()
Beispiel #4
0
def main():
    # Retrieve the selected baseMaterial
    mat = c4d.BaseMaterial(c4d.Mmaterial)
    if mat is None:
        raise ValueError("Cannot create a BaseMaterial")

    # Retrieve the reference of the material as a node Material.
    nodeMaterial = mat.GetNodeMaterialReference()
    if nodeMaterial is None:
        raise ValueError("Cannot retrieve nodeMaterial reference")

    # Create the node space ID for the standard's node space
    nodespaceId = maxon.Id("net.maxon.nodespace.standard")

    # Add a graph for the standard node space
    addedGraph = nodeMaterial.AddGraph(nodespaceId)
    if addedGraph is None:
        raise ValueError("Cannot add a graph node for this node space")

    # Retrieve the Nimbus reference for a specific node space from which we 
    # will retrieve the graph. One could also use 'addedGraph' defined above.
    nimbusRef = mat.GetNimbusRef(nodespaceId)
    if nimbusRef is None:
        raise ValueError("Cannot retrieve the nimbus ref for that node space")

    # Retrieve the graph corresponding to that node space.
    graph = nimbusRef.GetGraph()
    if graph is None:
        raise ValueError("Cannot retrieve the graph of this nimbus ref")

    # Retrieve the end node of this graph
    endNodePath = nimbusRef.GetPath(
        maxon.frameworks.nodespace.NIMBUS_PATH.MATERIALENDNODE)
    endNode = graph.GetNode(endNodePath)
    if endNode is None:
        raise ValueError("Cannot retrieve the end-node of this graph")

    # Retrieve the predecessors
    predecessor = list()
    endNode.GetDirectPredecessors(predecessor)
    bsdfNode = predecessor[0]
    if bsdfNode is None:
        raise ValueError("Cannot retrieve the node connected to end-node")

    # Retrieve the outputs list of the BDSF node
    bsdfNodeInputs = bsdfNode.GetInputs()
    if bsdfNode is None:
        raise ValueError(
            "Cannot retrieve the inputs list of the bsdfNode node")

    colordePort = bsdfNodeInputs.FindChild("color")
    if colordePort is None:
        return

    with graph.BeginTransaction() as transaction:
        # Define the value of the Color's port.
        colordePort.SetDefaultValue(maxon.ColorA(1, 0, 0, 1))
        transaction.Commit()

    # Insert the material to the document.
    doc.InsertMaterial(mat)

    # Pushes an update event to Cinema 4D
    c4d.EventAdd()