コード例 #1
0
 def _clear_groups(cls):
     """Deletes all groups 
     """
     groups = rs.GroupNames()
     if groups:
         for group in groups:
             rs.DeleteGroup(group)
コード例 #2
0
def clear_groups():
    groups = rs.GroupNames()
    if not groups:
        print('No groups to clear')
        groups = []
    for group in groups:
        group_deleted = rs.DeleteGroup(group)
        print('%s deleted: %s' % (group, group_deleted))
コード例 #3
0
def main():

    cyls = []
    radius = 0

    gname = "Enclosure"

    extantGroups = rs.GroupNames()
    print "groups: ", extantGroups
    enclosures = [s for s in extantGroups if "Enclosure" in s]
    print "enclosures: ", enclosures

    if rs.IsGroup("Enclosure"):
        num = len(enclosures)
        gname += "_" + ` num `
    encGroup = rs.AddGroup(gname)
    print "group: ", encGroup

    focus = rs.GetPoint("center of fence")
    if (focus is None): return
    rpt = rs.GetPoint("enclosure radius", focus)
    if (rpt is None): return
    else:
        radius = (rpt - focus).Length
        rs.AddObjectsToGroup(rs.AddCircle(focus, radius), encGroup)

    count = rs.GetInteger("number of cylinders")
    if (count is None): return
    cyldiam = rs.GetReal("cylinder diameter")
    if (cyldiam is None): return
    minheight = rs.GetReal("minimum height")
    if (minheight is None): return
    maxheight = rs.GetReal("maximum height")
    if (maxheight is None): return
    #   arcjitter = rs.GetReal("amount of arc jitter")
    #   if (arcjitter is None): return
    #   radialjitter = rs.GetReal("amount of radial jitter")
    #   if (radialjitter is None): return

    for i in range(count):
        cyl = rs.AddCylinder(rpt, random.uniform(minheight, maxheight),
                             cyldiam / 2, True)
        rs.RotateObject(cyl, focus, (360 / count) * (i + 1))
        cyls.append(cyl)
    if cyls: rs.AddObjectsToGroup(cyls, encGroup)
    print "Enclosure built:"
    print "focus: (", focus, ")"
    print "radius:", radius
    print "cylinders:", count, "ranging from", minheight, "to", maxheight, "units in length."
コード例 #4
0
import rhinoscriptsyntax as rs

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

rs.Redraw()
コード例 #5
0
ファイル: addPartList.py プロジェクト: syl1130/pythonscripts
def createTable(partlist):
    if not "partlistgroup" in rs.GroupNames():
        rs.AddGroup("partlistgroup")
    #clean the group
    group = sc.doc.Groups.FindName("partlistgroup")
    objs = sc.doc.ActiveDoc.Groups.GroupMembers(group.Index)
    rs.DeleteObjects(objs)

    #rs.DeleteObjects
    twidth = 100

    def addTexts(texts, y):
        for i, text in enumerate(texts):
            if i == 0:
                a = 6
                just = Rhino.Geometry.TextJustification.BottomRight

            elif i == 1:
                a = 9.5
                just = Rhino.Geometry.TextJustification.BottomLeft
            else:
                a = 14 + twidth
                just = Rhino.Geometry.TextJustification.BottomRight
            plane = Rhino.Geometry.Plane.WorldXY
            plane.Origin = Rhino.Geometry.Point3d(a, y - 4, 0)

            textobject = sc.doc.Objects.AddText(text, plane, 2.0,
                                                'Courier New', False, False,
                                                just)
            rs.AddObjectToGroup(textobject, "partlistgroup")

    def addBorders(i, y):

        start = Rhino.Geometry.Point3d(0, y - 6, 0)
        end = Rhino.Geometry.Point3d(16 + twidth, y - 6, 0)
        line = sc.doc.Objects.AddLine(start, end)  #bottom border
        rs.AddObjectToGroup(line, "partlistgroup")
        if i == 0:
            #add top border
            trans = Rhino.Geometry.Transform.Translation(0, 6, 0)
            h_line = Rhino.Geometry.Line(start, end)
            h_line.Transform(trans)
            line = sc.doc.Objects.AddLine(h_line)
            rs.AddObjectToGroup(line, "partlistgroup")
        #add vertical lines
        v_start = Rhino.Geometry.Point3d(0, y, 0)
        v_end = Rhino.Geometry.Point3d(0, y - 6, 0)

        v_line = Rhino.Geometry.Line(v_start, v_end)
        line = sc.doc.Objects.AddLine(v_line)
        rs.AddObjectToGroup(line, "partlistgroup")

        trans = Rhino.Geometry.Transform.Translation(8, 0, 0)
        v_line.Transform(trans)
        line = sc.doc.Objects.AddLine(v_line)
        rs.AddObjectToGroup(line, "partlistgroup")

        trans = Rhino.Geometry.Transform.Translation(twidth, 0, 0)
        v_line.Transform(trans)
        line = sc.doc.Objects.AddLine(v_line)
        rs.AddObjectToGroup(line, "partlistgroup")

        trans = Rhino.Geometry.Transform.Translation(8, 0, 0)
        v_line.Transform(trans)
        line = sc.doc.Objects.AddLine(v_line)
        rs.AddObjectToGroup(line, "partlistgroup")

    y = len(partlist) * 6
    for i, texts in enumerate(partlist):
        addTexts(texts, y)
        addBorders(i, y)
        y -= 6
    #sc.doc.Views.Redraw()
    group = sc.doc.Groups.FindName("partlistgroup")
    objs = sc.doc.ActiveDoc.Groups.GroupMembers(group.Index)

    rs.MoveObjects(objs, (10, 10, 0))
コード例 #6
0
def clear_groups():
    groups = rs.GroupNames()
    if not groups:
        print('No groups to clear')
        groups = []
    for group in groups:
        group_deleted = rs.DeleteGroup(group)
        print('%s deleted: %s' % (group, group_deleted))


g.Grammar.clear_all()
clear_groups()
print('Number of groups (GroupCount): %i' % rs.GroupCount())
##  GroupCount seems to show the past, not the present
print('Groups: %s' % rs.GroupNames())
##  GroupNames appears to show the present
names = rs.GroupNames()
if not names:
    names = []
n_names = len(names)
print('Number of groups(len(GroupNames)): %i' % n_names)
group = 'kilroy'
group_out = rs.AddGroup(group)
print('New group: %s' % group_out)
print('Groups: %s' % rs.GroupNames())
print('%s is a group: %s' % (group_out, rs.IsGroup(group_out)))
print('%s is empty: %s' % (group_out, rs.IsGroupEmpty(group_out)))
##  IsGroupEmpty appears to return IsGroupNonEmpty
p1, p2 = (0, 0, 0), (20, 20, 0)
line = rs.AddLine(p1, p2)
コード例 #7
0
def create_table(partlist):
    g = rs.GroupNames()
    if not g or not "partlistgroup" in g:
        rs.AddGroup("partlistgroup")
    #clean the group
    group = sc.doc.Groups.FindName("partlistgroup")
    objs = sc.doc.ActiveDoc.Groups.GroupMembers(group.Index)
    rs.DeleteObjects(objs)
    #base table width on largest name
    blocknames = get_block_names()
    twidth = 3 + max(blocknames, key=len).Length * 2.1
    desc = 3 + max(get_block_descriptions(blocknames), key=len).Length * 2.1
    if desc < 3 + 5 * 2.1:
        desc = 3 + 5 * 2.1

    def addTexts(texts, y):
        for i, text in enumerate(texts):
            if i == 0:
                a = 10
                just = Rhino.Geometry.TextJustification.BottomRight

            elif i == 1:
                a = 13.5
                just = Rhino.Geometry.TextJustification.BottomLeft
            elif i == 2:
                a = 13.5 + twidth
                just = Rhino.Geometry.TextJustification.BottomLeft
            else:
                a = 20 + twidth + desc
                just = Rhino.Geometry.TextJustification.BottomRight
            plane = Rhino.Geometry.Plane.WorldXY
            plane.Origin = Rhino.Geometry.Point3d(a, y - 4, 0)

            textobject = sc.doc.Objects.AddText(text, plane, 2.0,
                                                'Courier New', False, False,
                                                just)
            rs.AddObjectToGroup(textobject, "partlistgroup")

    def get_partlist_alignment():

        point = Rhino.Geometry.Point3d(0, 0, 0)
        listValues = "LowerLeft", "LowerRight", "UpperLeft", "UpperRight"
        listIndex = 1
        gp = Rhino.Input.Custom.GetPoint()
        gp.SetCommandPrompt("Choose alignment and insertion point")
        opList = gp.AddOptionList("Alignment", listValues, listIndex)
        while True:
            get_rc = gp.Get()
            if gp.CommandResult() != Rhino.Commands.Result.Success:
                return point, 0
            if get_rc == Rhino.Input.GetResult.Point:
                point = gp.Point()

            elif get_rc == Rhino.Input.GetResult.Option:
                if gp.OptionIndex() == opList:
                    listIndex = gp.Option().CurrentListOptionIndex
                continue
            break
        return point, listIndex

    def add_borders(i, y):

        start = Rhino.Geometry.Point3d(0, y - 6, 0)
        end = Rhino.Geometry.Point3d(22 + twidth + desc, y - 6, 0)
        line = sc.doc.Objects.AddLine(start, end)  #bottom border
        rs.AddObjectToGroup(line, "partlistgroup")
        if i == 0:
            #add top border
            trans = Rhino.Geometry.Transform.Translation(0, 6, 0)
            h_line = Rhino.Geometry.Line(start, end)
            h_line.Transform(trans)
            line = sc.doc.Objects.AddLine(h_line)
            rs.AddObjectToGroup(line, "partlistgroup")
        #add vertical lines
        v_start = Rhino.Geometry.Point3d(0, y, 0)
        v_end = Rhino.Geometry.Point3d(0, y - 6, 0)

        v_line = Rhino.Geometry.Line(v_start, v_end)
        line = sc.doc.Objects.AddLine(v_line)
        rs.AddObjectToGroup(line, "partlistgroup")

        trans = Rhino.Geometry.Transform.Translation(12, 0, 0)
        v_line.Transform(trans)
        line = sc.doc.Objects.AddLine(v_line)
        rs.AddObjectToGroup(line, "partlistgroup")

        trans = Rhino.Geometry.Transform.Translation(twidth, 0, 0)
        v_line.Transform(trans)
        line = sc.doc.Objects.AddLine(v_line)
        rs.AddObjectToGroup(line, "partlistgroup")

        trans = Rhino.Geometry.Transform.Translation(desc, 0, 0)
        v_line.Transform(trans)
        line = sc.doc.Objects.AddLine(v_line)
        rs.AddObjectToGroup(line, "partlistgroup")

        trans = Rhino.Geometry.Transform.Translation(10, 0, 0)
        v_line.Transform(trans)
        line = sc.doc.Objects.AddLine(v_line)
        rs.AddObjectToGroup(line, "partlistgroup")

    y = len(partlist) * 6
    #get insertion point
    point, listIndex = get_partlist_alignment()
    if point:
        target = Rhino.Geometry.Point3d(0, 0, 0)
        if listIndex == 0:  #lower left
            target[0] = point[0]
            target[1] = point[1]
        elif listIndex == 1:  #lower right
            target[0] = point[0] - (22 + twidth + desc)
            target[1] = point[1]
        elif listIndex == 2:  #upper left
            target[0] = point[0]
            target[1] = point[1] - len(partlist) * 6
        else:  #upper right
            target[0] = point[0] - (22 + twidth + desc)
            target[1] = point[1] - len(partlist) * 6

    for i, texts in enumerate(partlist):
        addTexts(texts, y)
        add_borders(i, y)
        y -= 6

    group = sc.doc.Groups.FindName("partlistgroup")
    objs = sc.doc.ActiveDoc.Groups.GroupMembers(group.Index)
    rs.MoveObjects(objs, (target))
コード例 #8
0
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)