def hide_all_groups(cfg):
    for g, group_info in enumerate(cfg['groups_info']):
        rs.HideGroup(group_info['name'])
def isolate_group(idx, cfg):
    for g, group_info in enumerate(cfg['groups_info']):
        if idx == g: rs.ShowGroup(group_info['name'])
        else: rs.HideGroup(group_info['name'])
import rhinoscriptsyntax as rs

names = rs.GroupNames()
for group in names:
    rs.HideGroup(group)

rs.Redraw()
def main():
    cfg = setup()
    rs.CurrentView(cfg['view'].ActiveViewportID)
    # MAIN LOOP

    msg0 = "{} views at {} zoom levels across {} xforms of {} objects.".format(
        cfg['view_count'], len(cfg['obj_bbox_pads']), cfg['xform_count'],
        len(cfg['groups_info']))
    msg1 = "{} images will result.".format(cfg['total_image_count'])
    print(msg0)
    print(msg1)
    if rs.MessageBox(
            "This script will plot {}\n{}\nThe folder {} has been created for this purpose.\nShall we proceed?"
            .format(msg0, msg1, cfg['pth_save']), 4,
            "Ready to plot {} images?".format(cfg['total_image_count'])) != 6:
        teardown(cfg)
        exit()

    cfg['tmp_obj_ids'] = False
    cfg['rot_group'] = False
    cfg['tot_rot'] = False

    try:
        #raise Exception("nope")

        for g, group_info in enumerate(cfg['groups_info']):
            print("##### {} ({} of {})".format(group_info['name'].lower(),
                                               g + 1, len(cfg['groups_info'])))
            #print("{} objects in this group".format(len(group_info['obj_ids'])))
            #set_camera(group_info['bbox'], cfg)
            isolate_group(g, cfg)

            deg = 360.0 / cfg['view_count']
            rxf = rs.XformRotation2(deg, (0, 0, 1), group_info['bbox'].Center)

            cfg['rot_group'] = group_info
            cfg['tot_rot'] = 0

            for r in range(cfg['view_count']):

                for x, xf in enumerate(
                        xforms_to_apply(group_info['bbox'], cfg, DEBUG)):

                    all_layers_on(cfg)
                    cfg['tmp_obj_ids'] = apply_xf(
                        xf, group_info['obj_ids'])  # apply this transformation
                    rs.RemoveObjectsFromGroup(cfg['tmp_obj_ids'],
                                              group_info['name'])
                    rs.HideGroup(group_info['name'])

                    for p, pad in enumerate(cfg['obj_bbox_pads']):
                        xbbox = bbox_of_objects(cfg['tmp_obj_ids'])
                        set_camera(xbbox, pad, cfg)

                        name = "{}_r{:03}_x{:02}_p{:02}_{}".format(
                            group_info['name'].lower(), r, x, p,
                            cfg['layer_info']['parent'].Name.lower())
                        is_first = (r == 0 and x == 0)
                        do_capture(name, is_first, cfg)  # capture view

                    isolate_group(g, cfg)
                    all_layers_on(cfg)
                    rs.DeleteObjects(cfg['tmp_obj_ids'])
                    cfg['tmp_obj_ids'] = False

                    Rhino.RhinoApp.Wait()
                    if (sc.escape_test(False)):
                        raise Exception('Esc key caught in main()')

                rs.TransformObjects(group_info['obj_ids'], rxf)
                cfg['tot_rot'] += deg

            cfg['rot_group'] = False
            cfg['tot_rot'] = 0

    except Exception as e:
        print("!!!! SCRIPT STOPPED !!!!")
        print e
        exc_type, exc_obj, exc_tb = sys.exc_info()
        fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
        print(exc_type, fname, exc_tb.tb_lineno)
    finally:
        teardown(cfg)
Beispiel #5
0
def hide_group(group):
    n_objects_hidden = rs.HideGroup(group)
    print('Hid %i objects in %s' % (n_objects_hidden, group))