예제 #1
0
ghenv.Component.AdditionalHelpFromDocStrings = '3'

try:
    from ladybug_rhino.viewport import viewport_by_name, open_viewport, \
        set_iso_view_direction, set_view_display_mode
    from ladybug_rhino.grasshopper import all_required_inputs, component_guid
except ImportError as e:
    raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e))


if all_required_inputs(ghenv.Component):
    view_name = 'ViewFromSun_{}'.format(component_guid(ghenv.Component))
    print view_name  # print so that the user has the name if needed

    # get the viewport from which the direction will be set
    view_port = None
    if not width_ and not height_:  # no need to generate new view; get existing one
        try:
            view_port = viewport_by_name(view_name)
        except ValueError:  # the viewport does not yet exist
            pass
    if view_port is None:
        view_port = open_viewport(view_name, width_, height_)

    # set the direction of the viewport camera
    set_iso_view_direction(view_port, _vector, _center_pt_)

    # set the display mode if requested
    if mode_:
        set_view_display_mode(view_port, mode_)
예제 #2
0
                                  'captured_views')
except:
    home_folder = os.getenv('HOME') or os.path.expanduser('~')
    default_folder = os.path.join(home_folder, 'captured_views')

try:
    from ladybug_rhino.grasshopper import all_required_inputs, bring_to_front
    from ladybug_rhino.viewport import viewport_by_name, capture_view
except ImportError as e:
    raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e))

if all_required_inputs(ghenv.Component) and _capture:
    # ensure the component runs last on the canvas
    bring_to_front(ghenv.Component)

    # prepare the folder
    folder = _folder_ if _folder_ is not None else default_folder
    preparedir(folder, remove_content=False)

    # get the viewport objects
    vp_names = viewport_ if len(viewport_) != 0 else [None]
    viewports = [viewport_by_name(vp) for vp in vp_names]

    # save the viewports to images
    for i, view_p in enumerate(viewports):
        f_name = _file_name if len(viewports) == 1 else \
            '{}_{}'.format(_file_name, vp_names[i])
        file_p = os.path.join(folder, f_name)
        fp = capture_view(view_p, file_p, width_, height_, mode_, transparent_)
        print(fp)
예제 #3
0
ghenv.Component.AdditionalHelpFromDocStrings = '4'

try:  # import the core honeybee dependencies
    from honeybee.typing import clean_and_id_rad_string
except ImportError as e:
    raise ImportError('\nFailed to import honeybee:\n\t{}'.format(e))

try:
    from honeybee_radiance.view import View
except ImportError as e:
    raise ImportError('\nFailed to import honeybee:\n\t{}'.format(e))

try:  # import ladybug_rhino dependencies
    from ladybug_rhino.grasshopper import all_required_inputs
    from ladybug_rhino.viewport import viewport_by_name, viewport_properties
except ImportError as e:
    raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e))

VIEW_TYPES = ('v', 'h', 'l', 'c', 'a')

# set the default values
_name_ = 'RadianceView' if _name_ is None else _name_
viewp = viewport_by_name(_viewport_)
v_props = viewport_properties(viewp, _view_type_)

view = View(clean_and_id_rad_string(_name_), v_props['position'],
            v_props['direction'], v_props['up_vector'],
            VIEW_TYPES[v_props['view_type']], v_props['h_angle'],
            v_props['v_angle'])
view.display_name = _name_