__init__.py 1.5 KB
Newer Older
R
repsac 已提交
1 2
import os
import bpy
3
from . import object as object_, mesh, material, camera, light
R
repsac 已提交
4 5 6 7
from .. import logger


def active_object():
8 9 10 11 12
    """

    :return: The actively selected object

    """
R
repsac 已提交
13 14 15
    return bpy.context.scene.objects.active


M
mese79 已提交
16 17 18 19 20
def batch_mode():
    """

    :return: Whether or not the session is interactive
    :rtype: bool
21

M
mese79 已提交
22 23
    """
    return bpy.context.area is None
24

M
mese79 已提交
25

26 27 28 29 30 31 32 33 34 35 36 37
def data(node):
    """

    :param node: name of an object node
    :returns: the data block of the node

    """
    try:
        return bpy.data.objects[node].data
    except KeyError:
        pass

R
repsac 已提交
38

R
repsac 已提交
39
def init():
40 41 42 43 44
    """Initializing the api module. Required first step before
    initializing the actual export process.
    """
    logger.debug("Initializing API")
    object_.clear_mesh_map()
R
repsac 已提交
45 46 47


def selected_objects(valid_types=None):
48 49 50 51 52 53
    """Selected objects.

    :param valid_types: Filter for valid types (Default value = None)

    """
    logger.debug("api.selected_objects(%s)", valid_types)
R
repsac 已提交
54 55 56 57 58 59 60 61
    for node in bpy.context.selected_objects:
        if valid_types is None:
            yield node.name
        elif valid_types is not None and node.type in valid_types:
            yield node.name


def set_active_object(obj):
62 63 64 65 66 67
    """Set the object as active in the scene

    :param obj:

    """
    logger.debug("api.set_active_object(%s)", obj)
R
repsac 已提交
68 69 70 71
    bpy.context.scene.objects.active = obj


def scene_name():
72 73 74 75 76
    """

    :return: name of the current scene

    """
R
repsac 已提交
77
    return os.path.basename(bpy.data.filepath)