From K-3D

Jump to: navigation, search


Script node that acts as a render engine
Plugin Status:Stable
Categories:All Plugins, Stable Plugins, Script Plugins


Name Value


Label Description Type Script Name
Script Script source code k3d::string_t script
Visible Nodes Visible Nodes std::vector<k3d::inode*> visible_nodes


RenderEngineScript can be used to do custom rendering under script control. "Rendering" in this context means simply converting the contents of a K-3D document into some alternate representation that can be stored in a file on disk. You might write a script that scans the contents of a document and dumps a description to a text file, or one that generates a POVRAY file and pipes it to a waiting render engine - the sky is literally the limit! The following example creates a DOT file (a type of graph representation) and starts a copy of AT&T GraphViz that renders the file to an SVG image:


import k3d

graph = """
digraph G {

node [ shape="box" style="filled" color="black" fillcolor="white" ];


for node in Document.nodes():
        graph += str(hash(node))
        graph += "[\n"
        graph += "label=\"" + + "\"\n"
        graph += "URL=\"" + node.factory().name + "\"\n"
        graph += "]\n"

for node in Document.nodes():
        for prop in

                if prop.type == "k3d::inode*":
                        referenced_node = prop.internal_value
                        if referenced_node:
                                graph += str(hash(referenced_node)) + "->" + str(hash(node))
                                graph += "[\n"
                                graph += "style=dotted\n"
                                graph += "label=\"" + + "\"\n"
                                graph += "]\n"

                source_prop = Document.get_dependency(prop)
                if source_prop:
                        graph += str(hash(source_prop.node)) + "->" + str(hash(prop.node))
                        graph += "[\n"
                        graph += "taillabel=\"" + + "\"\n"
                        graph += "headlabel=\"" + + "\"\n"
                        graph += "]\n"

graph += "}"

from subprocess import *
Popen(["dot", "-Tsvg", "-o" + OutputImage], stdin=PIPE).communicate(graph)

Script Environment

The following parameters will be available to your script at runtime (see the documentation for your script engine for details on how these parameters can be accessed programmatically).

Name Description
Document A reference to the document that owns this node.
Node A reference to this node.
OutputImage The name of the file to be rendered.
ViewImage Boolean value indicating whether the rendered image should be displayed to the user (can be ignored).