This documentation is for the free plugin Py4D in CINEMA 4D R11.5 and not for the C4DSDK of Python in CINEMA 4D R12. For R12, please visit PluginCafe.com

c4d.gui.TreeviewFunctions – a TreeviewFunctions class

Maybe this class is much more simple than it looks, depends on your skills. Just take a look at examples to get involved how to use this construction. A simple node class could like like:

# the node class
class NodeElement:
    __open = False
    __name = "default"
    __value = None

    next = None
    pred = None
    up = None
    down = None

    def __init__(self, value):
            self.__value = value

    def set_openstate(self, state):
            self.__open = state

    def get_openstate(self):
            return __open

    def get_name(self):
            return __name

    def set_name(self, name):
            self.name = name


# and the tree class. Needless to say you can write your own
# this is just a simple example
class Tree:                         # the tree which contains all node elements
    __first         = None  # reference to the highest list of elements

    # inserts an object to the list. optional argument to set the parent
    def insert_object(self, obj, parent=None, pred=None):

            # depends which arguments were set
            if self.__first is None and obj is not None and parent is None:
                    element = NodeElement(obj)
                    # create an empty list
                    self.__first = []
                    # append the element to the list and
                    self.__first.append(element)
                    # return it (to edit the color, open_state, etc.)
                    return element

            # is True if the parent was not set
            if obj is not None and parent is None:
                    # create the node which will be put in the treeview
                    element = NodeElement(obj)
                    # set the parent to the node
                    element.pred = self.__first[len(self.__first)-1]
                    # returns the count of elements
                    last_element = len(self.__first)-1
                    # set the 'next' reference to the last element
                    self.__first[last_element].next = element
                    # append the new element to the list
                    self.__first.append(element)
                    # return the new created element ( to edit the color, open_state, etc.)
                    return element

            # is True if the parent was set
            if obj is not None and parent is not None:
                    p = parent.down
                    # if the object has no childs
                    if p is None:
                            # create the node element
                            element = NodeElement(obj)
                            # set reference of the parent to the first child
                            parent.down = element
                            # and set the reference of the new child to its parent
                            element.up = parent
                            # return it (to edit the color, open_state, etc.)
                            return element

                    # iterates all childs of the parent
                    while p is not None:
                            # (*) if p is the last element
                            if p.next is None:
                                    # create the node element
                                    element = NodeElement(obj)
                                    # tell the last element it has a next node
                                    p.next = element
                                    # tell the new created node, it has a previous node
                                    element.pred = p
                                    # break while
                                    break
                                    # set next element if its not None. See (*) few lines above
                            p = p.next
                    # return the new created element ( to edit the color, open_state, etc.)
                    return element

    # returns the first hierarchy as list
    def return_rootlist(self):
            return self.__first

    # returns the first element of the treeview
    def get_first(self):
            return self.__first[0]

    #iterates the treeview and print out the value in the terminal
    def print_out(self, node=None, indention=""):
            if node is None:
                    node = self.__first

            for x in node:
                    print indention + str(x.get_value())
                    if x.down is not None:
                            if len(x.down) > 0:
                                    self.print_out(x.down, indention + "    ")
class c4d.gui.TreeviewFunctions

//Methods to override

Methods

TreeviewFunctions.get_first(self)

Returns the first element of the treeview.

Return type:anything
Returns:The first element or None if there is no first element.
TreeviewFunctions.get_down(self, obj)

Returns the first child of the element obj.

Return type:anything
Returns:The first child or None if there is no child.
TreeviewFunctions.get_next(self, obj)

Returns the next element of the element obj.

Return type:anything
Returns:The next element or None if there is no next element.
TreeviewFunctions.get_up(self, obj)

Returns the parent element of the element obj.

Return type:anything
Returns:The parent element or None if there is no parent element.
TreeviewFunctions.get_pred(self, obj)

Returns the previous element of the element obj.

Return type:anything
Returns:The previous element or None if there is no previous element.
TreeviewFunctions.set_name(self, obj, name)

Returns the parent element of the element obj.

Parameter:name (str) – The new name of the element
TreeviewFunctions.get_name(self, obj)

Return the name of the element obj.

Return type:str
Returns:The name of the element.
TreeviewFunctions.is_opened(self, obj)

Return the open state of the element obj (see childs or not)

Return type:bool
Returns:The open state of the element.
TreeviewFunctions.open(self, obj, onoff)

Called if the user clicked on the arrow of obj. Set the bool value to the open state value of your node.

Parameter:onoff (bool) – The state of the object
TreeviewFunctions.get_color(self, obj)

Return the color of the elements name.

Return type:Vector
Returns:The color.
TreeviewFunctions.select(self, obj, mode)

Called if the user selected an object. On multiselection this method is called for each obj

Parameter:mode (int) – The mode.
Return type:Vector
Returns:The color.

Table Of Contents

This Page