def main():
    objs = rs.VisibleObjects()
    cutLevel = 12
    rs.EnableRedraw(False)
    objsCopy = rs.CopyObjects(objs)
    splitModel(objsCopy, cutLevel)
    makePlan()
    rs.DeleteObjects(rs.ObjectsByGroup("Above"))
    rs.DeleteObjects(rs.ObjectsByGroup("Below"))
    cutAtPlan(cutLevel, False)
    rs.Command('_SelDupAll _delete')
    cutAtPlan(cutLevel, True)
    rs.Command('_SelDup _delete')
    rs.EnableRedraw(True)
def makePlan():
    """
    make2d from above.
    input: list of layers to make2d
    returns: None
    """
    objs = rs.ObjectsByGroup("Below")
    
    #Make2d
    rs.SelectObjects(objs)
    rs.Command("-_make2d _D _U _Enter")
    projLines = rs.GetObjects("", preselect = True)
    
    #Get make2d root layer
    make2dRootRaw = rs.ObjectLayer(projLines[0])
    make2dRoot = make2dRootRaw.split("::")[0]
    
    #Rename make2d layers
    root  = rs.AddLayer("60_PLANS")
    roofLay = rs.AddLayer("Roof", parent = root)
    for projLine in projLines:
        linesLayer = rs.ObjectLayer(projLine)
        linesColor = rs.ObjectColor(projLine)
        linesLayerName = rs.LayerName(linesLayer, fullpath = False)
        newLayers = rs.AddLayer(linesLayerName, parent = roofLay, color = linesColor)
        rs.ObjectLayer(projLine,newLayers)
        rs.ObjectColor(projLine, (200,200,200))
    
    #Delete make2d Layers
    rs.DeleteLayer(make2dRoot)
    return
def move_group(name, translation):

    global groups

    if name not in groups:
        raise NameError("Group " + name + " doesn't exist")
    else:
        guids = rs.ObjectsByGroup(name)
        for obj in guids:
            moved = rs.MoveObject(obj, translation)
            if moved == None:
                return False
        return True
Example #4
0
    def handleSelectObj(self,sender,e):
        sel=rs.SelectedObjects()
        print('handleSelectObj')
        if len(sel)==1:
            print('selected obj ID:',sel[0])

        else:
            print('selected multiple objs, len=',len(sel))
            for obj in sel:
                print('obj :',obj)
                isGroup=rs.IsGroup(obj)
                if isGroup:
                    print('group:',obj)
                    items=rs.ObjectsByGroup(obj)
                    for item in items:
                        print('item ',i,':',item)
def setup_groups(cfg):
    cfg['groups_info'] = []
    try:
        obj_guids = rs.GetObjects("Select groups of objects to draw.",
                                  group=True)
        if obj_guids is None:
            raise Exception(
                "Why are you messing with me? Select some groups please.")
        name_grps = set()
        for id in obj_guids:
            gnms = rs.ObjectGroups(id)
            if len(gnms) == 0:
                raise Exception(
                    "One or more of the selected objects was not in a group.\nEverything must be grouped!"
                )
            if len(gnms) > 1:
                raise Exception(
                    "One or more of the selected objects was in more than one group.\nEverything must be in exactly one group!"
                )
            name_grps.update(gnms)

        for name_grp in list(name_grps):
            ids = rs.ObjectsByGroup(name_grp)
            bbox = bbox_of_objects(ids)
            cfg['groups_info'].append({
                "name": name_grp,
                "bbox": bbox,
                "obj_ids": ids
            })

        if len(cfg['groups_info']) == 0:
            raise Exception("No valid groups selected.")

    except Exception as e:
        big_problem(
            "There was a problem with the selection of groups.\n{}".format(e))
Example #6
0
 def get_geom(self):
     ''' note that show should be called before this function
     '''
     return rs.ObjectsByGroup(self.group_name)
Example #7
0
 def clear(self):
     ''' clears all geometry for island'''
     objects = rs.ObjectsByGroup(self.group_name)
     rs.DeleteObjects(objects)
     self.groupToEdge_map = {}
     self.cut_edge_lines = []
Example #8
0
 def get_all_geom(self):
     return rs.ObjectsByGroup(self.group_name)
def RunCommand(is_interactive):
    #rs.EnableRedraw(False)
    cplane = rs.ViewCPlane()
    area = 0
    defaultName = ''
    areaObjs = rs.GetObjects("Select Objects", filter=65536, preselect=True)

    if not areaObjs:
        rs.EnableRedraw(True)
        print("No object selected. Exiting command.")
        return

    areaName = rs.GetString(
        "Enter name of area to be displayed", object_names(areaObjs),
        ["RETAIL", "RESIDENTIAL", "AMENITY", "BOH", "LOBBY"])

    if not areaName:
        rs.EnableRedraw(True)
        return

    # GRAPHIC SCALE OPTIONS
    nameOffset = .4
    nameTextSize = 1
    areaTextSize = .8

    scale = rs.GetReal("Text height (in Rhino Units)", defaultScale)
    if not scale:
        print("Text height not entered, exiting command")
        rs.EnableRedraw(True)
        return

    nameOffset = nameOffset * scale
    nameTextSize = nameTextSize * scale
    areaTextSize = areaTextSize * scale

    # GET AREA and Format it to Integer with commas
    area = get_area(areaObjs)
    area = area * (rs.UnitScale(9))**2
    area = int(area)
    area = "{:,} SF".format(area)
    bbox = rs.BoundingBox(areaObjs, cplane)
    pt_sum = bbox[0]
    for i in xrange(1, len(bbox)):
        pt_sum += bbox[i]
    area_avg = rs.AddPoint(pt_sum / len(bbox))

    areaCenter = rs.PointCoordinates(
        rs.MoveObject(area_avg,
                      cplane.YAxis * (nameOffset + areaTextSize) / -2))
    nameCenter = rs.PointCoordinates(
        rs.MoveObject(area_avg, cplane.YAxis * (nameOffset + nameTextSize)))
    #    print(nameCenter, areaCenter)

    # CREATE THE TEXT
    areaText = rs.AddText(area, areaCenter, areaTextSize, justification=2)
    nameText = rs.AddText(areaName, nameCenter, nameTextSize, justification=2)

    # CREATE BOX AROUND TEXT

    textBounds = rs.BoundingBox(areaText, cplane)
    textBoundary = rs.AddPolyline(textBounds[0:5])

    nameTextHeight = rs.Distance(
        rs.BoundingBox(nameText, cplane)[2],
        rs.BoundingBox(nameText, cplane)[1])
    textBorder = rs.OffsetCurve(textBoundary, (0, 0, 0), .25 * scale, style=1)

    rs.DeleteObject(textBoundary)

    rs.ObjectName(nameText, "Name Text")
    rs.ObjectName(areaText, "Area Text")
    rs.ObjectName(textBorder, "Text Border")

    parent = rs.ParentLayer(
        rs.ObjectLayer(areaObjs[0])) + '::' if rs.ParentLayer(
            rs.ObjectLayer(areaObjs[0])) else ''
    # print("LAYER NAME", rs.LayerName(parent+"A-ANNO-NOTE"))

    if not rs.IsLayer(parent + "A-ANNO-NOTE"):
        rs.AddLayer(parent + "A-ANNO-NOTE")
    rs.ObjectLayer(nameText, parent + "A-ANNO-NOTE")
    rs.ObjectLayer(areaText, parent + "A-ANNO-NOTE")
    rs.ObjectLayer(textBorder, parent + "A-ANNO-NOTE")

    areasGroup = rs.AddGroup()
    rs.AddObjectsToGroup([areaText, nameText, textBorder], areasGroup)

    rs.SelectObjects(rs.ObjectsByGroup(areasGroup))
    rs.DeleteObject(area_avg)

    rs.EnableRedraw(True)
Example #10
0
#Select object to be sliced, copy it, group it and move it to the working layer
obj_sel = rs.GetObjects(message='Select the objects to be visualized:',
                        group=True,
                        preselect=True)
#dir_tar = "/Users/Rog/Desktop"
dlg.ShowDialog()
dir_tar = dlg.SelectedPath

obj_cop = rs.CopyObjects(obj_sel)
rs.AddGroup(group_name='obj_all')

for i in obj_cop:
    rs.AddObjectToGroup(i, 'obj_all')

obj_all = rs.ObjectsByGroup('obj_all')
rs.ObjectLayer(obj_all, 'lay_wor')

#Create the directories needed to store all captures
if os.path.isdir(dir_tar + dir_mai) == True:
    #print('Directories already exists')
    pass
else:
    os.mkdir(dir_tar + dir_mai)
    os.mkdir(dir_tar + dir_mai + dir_axo)
    os.mkdir(dir_tar + dir_mai + dir_sec)
    #print('Directories created')
    pass

#Turn off all layers but the working one, also save a list of visible layers
lay_lis = rs.LayerNames()
Example #11
0
def get_group_for_selection():
    group = rs.GetString("Enter 'h' or 'v' or 'l'")
    select = True
    guids = rs.ObjectsByGroup(group, select)
    rs.SelectObjects(guids)
Example #12
0
def get_objects_in_nonexistent_group():
    g.Grammar.clear_all()
    non_existent_group = 'non-existent group'
    objects = rs.ObjectsByGroup(non_existent_group)
    print("objects: %s" % objects)  ##  error message
import rhinoscriptsyntax as rs

rs.EnableRedraw(enable=False)
groups = rs.GroupNames()
selected = rs.SelectedObjects()
if groups:
    for i, group in enumerate(groups):
        objs = rs.ObjectsByGroup(group)
        if objs:
            objName = group + str(i)
            block = rs.AddBlock(objs, (0, 0, 0), objName, True)
            rs.InsertBlock(block, (0, 0, 0))

selected = rs.SelectedObjects()

for i in range(len(selected)):
    obj = [selected[i]]
    objName = str(rs.ObjectLayer(obj[0])) + str(i)
    block = rs.AddBlock(obj, (0, 0, 0), objName, True)
    rs.InsertBlock(block, (0, 0, 0))

rs.EnableRedraw(enable=True)
Example #14
0
def RunCommand(is_interactive):

    rs.EnableRedraw(False)

    defaultName = ''
    areaObj = rs.GetObject("Select Object:", filter=65536, preselect=True)
    areaName = rs.ObjectName(areaObj)

    if not areaName:
        defaultName = rs.ObjectLayer(areaObj).split("-")[-1].replace("_", " ")
        print("default", defaultName)
        areaName = rs.GetString(
            "Enter name of area to be displayed", defaultName,
            ["RETAIL", "RESIDENTIAL", "AMENITY", "BOH", "LOBBY"])
    else:
        areaName = areaName.upper()
    #areaName = areaName.replace(" ", "\n")

    nameOffset = 20
    nameTextSize = 50
    areaTextSize = 40
    scale = rs.GetReal("Scale for text (.5 for towers)", 1)

    nameOffset = nameOffset * scale
    nameTextSize = nameTextSize * scale
    areaTextSize = areaTextSize * scale

    areaObjExp = rs.ExplodeHatch(areaObj)
    try:
        area = rs.Area(areaObjExp)
    except:
        print("Object not a solid hatch")
        rs.DeleteObject(areaObjExp)

    area = area * (rs.UnitScale(9))**2

    area = int(area)
    area = "{:,} SF".format(area)

    areaCenter = rs.SurfaceAreaCentroid(areaObjExp)[0]
    rs.DeleteObject(areaObjExp)

    areaCenter = rs.PointAdd(areaCenter,
                             (0, ((nameOffset + areaTextSize) / -2), 0))
    nameCenter = rs.PointAdd(areaCenter, (0, nameOffset + nameTextSize, 0))
    print(nameCenter, areaCenter)

    areaText = rs.AddText(area, areaCenter, areaTextSize, justification=2)
    nameText = rs.AddText(areaName, nameCenter, nameTextSize, justification=2)
    textBounds = rs.BoundingBox(areaText)
    textBoundary = rs.AddPolyline(textBounds[0:5])

    nameTextHeight = rs.Distance(
        rs.BoundingBox(nameText)[2],
        rs.BoundingBox(nameText)[1])
    print("AreaNameHeight", nameTextHeight)

    textBorder = rs.OffsetCurve(textBoundary, (0, 0, 0), 5 * scale, style=1)

    rs.DeleteObject(textBoundary)

    rs.ObjectName(nameText, "Name Text")
    rs.ObjectName(areaText, "Area Text")
    rs.ObjectName(textBorder, "Text Border")

    parent = rs.ParentLayer(rs.ObjectLayer(areaObj))

    rs.ObjectLayer(nameText, parent + "::A-ANNO-NOTE")
    rs.ObjectLayer(areaText, parent + "::A-ANNO-NOTE")
    rs.ObjectLayer(textBorder, parent + "::A-ANNO-NOTE")

    areasGroup = rs.AddGroup()
    rs.AddObjectsToGroup([areaText, nameText, textBorder], areasGroup)

    rs.SelectObjects(rs.ObjectsByGroup(areasGroup))

    rs.EnableRedraw(True)