Exemplo n.º 1
0
def MakeBlockUnique(block, newName):
    """
    Explodes a block and makes a new one with 'newName'
    """
    xform = rs.BlockInstanceXform(block)
    insertPt = rs.BlockInstanceInsertPoint(block)
    objs = rs.ExplodeBlockInstance(block, False)
    rs.TransformObjects(objs, rs.XformInverse(xform))
    pt = rs.TransformObject(insertPt, rs.XformInverse(xform))
    rs.AddBlock(objs, insertPt, newName, True)
    newBlock = rs.InsertBlock2(newName, xform)
    rs.DeleteObject(pt)
    return newBlock
Exemplo n.º 2
0
def main():
    cfg = setup(PARENT_LAYER, VIEW_COUNT, IMG_SIZE, DEBUG, DO_CAPTURE_Z_BUFFER)
    # MAIN LOOP
    print("plottting {} layers taken from {} views across {} xforms.".format(
        len(cfg['layer_info']['children']), len(cfg['view_locs']),
        len(cfg['xforms'])))
    print("{} images will result.".format(
        len(cfg['layer_info']['children']) * len(cfg['view_locs']) *
        len(cfg['xforms'])))
    try:
        for l, layer in enumerate(cfg['layer_info']['children']):
            isolate_layer(cfg['layer_info'], l)
            for x, xf in enumerate(cfg['xforms']):
                print("##### xform {} of {}".format(x + 1, len(cfg['xforms'])))
                apply_xf_to_all_objects(xf)  # apply transformation
                for c, cam in enumerate(cfg['view_locs']):
                    do_capture(cam, "{}_{:04}_{:02}".format(layer.Name, c, x),
                               cfg)  # capture view
                apply_xf_to_all_objects(
                    rs.XformInverse(xf))  # restore transformation

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

    except Exception as e:
        print e
    finally:
        teardown(cfg)
Exemplo n.º 3
0
def RemoveFromBlock():
    block = rs.GetObject("Select Block to extract objects from",
                         rs.filter.instance,
                         preselect=True)
    if not block: return

    blockName = rs.BlockInstanceName(block)
    objref = rs.coercerhinoobject(block)
    idef = objref.InstanceDefinition
    idefIndex = idef.Index

    XformBlock = rs.BlockInstanceXform(block)
    blockObjects = rs.BlockObjects(blockName)
    blockInstanceObjects = rs.TransformObjects(blockObjects, XformBlock, True)

    objs = rs.GetObjects("Select Objects to extract from Block",
                         objects=blockInstanceObjects)
    if not objs:
        rs.DeleteObjects(blockInstanceObjects)
        return

    keep = []  #List to keep in block
    delete = []  #list to delete from block and add to doc

    rs.EnableRedraw(False)

    for object in blockInstanceObjects:
        if object in objs: delete.append(object)
        else: keep.append(object)

    if rs.IsBlockReference(blockName):
        print "Block is referenced from file; unable to modify block"
        rs.DeleteObjects(keep)
        return

    rs.TransformObjects(keep, rs.XformInverse(XformBlock), False)

    newGeometry = []
    newAttributes = []
    for object in keep:
        newGeometry.append(rs.coercegeometry(object))
        ref = Rhino.DocObjects.ObjRef(object)
        attr = ref.Object().Attributes
        newAttributes.append(attr)

    InstanceDefinitionTable = sc.doc.ActiveDoc.InstanceDefinitions
    InstanceDefinitionTable.ModifyGeometry(idefIndex, newGeometry,
                                           newAttributes)

    rs.DeleteObjects(keep)
    rs.EnableRedraw(True)
Exemplo n.º 4
0
def BlockTxt(block, str = False, cstr = False, boolFlipHeb=True):
    if not block: return
    
    blockName = rs.BlockInstanceName(block)
    objref = rs.coercerhinoobject(block)
    idef = objref.InstanceDefinition
    idefIndex = idef.Index
    
    XformBlock = rs.BlockInstanceXform(block)
    blockObjects = rs.BlockObjects(blockName)
    
    txtobjs = False
    
    for obj in blockObjects:
        if rs.IsText(obj):
            if not str: txtobjs = True
            elif rs.TextObjectText(obj) == str: txtobjs = True
    
    if txtobjs:
        
        blockInstanceObjects = rs.TransformObjects(blockObjects, XformBlock, True)
        
        keep = []
        
        rs.EnableRedraw(False)
        
        for obj in blockInstanceObjects:
            if rs.IsText(obj):
                if not str and not cstr:
                    str = rs.TextObjectText(obj)
                    cstr = ConvTxt(str, boolFlipHeb)
                if not cstr == str:
                    rs.TextObjectText(obj, cstr)
                keep.append(obj)
            else: keep.append(obj)
        
        rs.TransformObjects(keep, rs.XformInverse(XformBlock), False)
        
        newGeometry = []
        newAttributes = []
        for object in keep:
            newGeometry.append(rs.coercegeometry(object))
            ref = Rhino.DocObjects.ObjRef(object)
            attr = ref.Object().Attributes
            newAttributes.append(attr)
        
        InstanceDefinitionTable = sc.doc.ActiveDoc.InstanceDefinitions
        InstanceDefinitionTable.ModifyGeometry(idefIndex, newGeometry, newAttributes)
        
        rs.DeleteObjects(keep)
Exemplo n.º 5
0
def AddToBlock():
    objects = rs.GetObjects("Choose Objects to Add to Block", preselect=True)
    if not objects: return

    block = rs.GetObject("Choose Block to Add Object to", rs.filter.instance)
    if not block: return

    rs.EnableRedraw(False)

    blockName = rs.BlockInstanceName(block)
    objref = rs.coercerhinoobject(block)
    idef = objref.InstanceDefinition
    idefIndex = idef.Index

    if rs.IsBlockReference(blockName):
        print "Block is referenced from file; unable to add object(s)"
        return

    blnCopy = False

    XformBlock = rs.BlockInstanceXform(block)

    rs.TransformObjects(objects, rs.XformInverse(XformBlock), blnCopy)

    objects.extend(rs.BlockObjects(blockName))

    newGeometry = []
    newAttributes = []
    for object in objects:
        newGeometry.append(rs.coercegeometry(object))
        ref = Rhino.DocObjects.ObjRef(object)
        attr = ref.Object().Attributes
        newAttributes.append(attr)

    InstanceDefinitionTable = sc.doc.ActiveDoc.InstanceDefinitions
    InstanceDefinitionTable.ModifyGeometry(idefIndex, newGeometry,
                                           newAttributes)

    rs.DeleteObjects(objects)

    rs.EnableRedraw(True)