示例#1
0
def duplicateAndRotate():
    obj_ids = rs.GetObjects("Select object(s) to duplicate and rotate", 0,
                            True, True)
    if obj_ids is None: return

    box = rs.BoundingBox(obj_ids)
    if not isinstance(box, list): return
    origin = rs.PointDivide(rs.PointAdd(box[0], box[6]), 2)

    endpt = rs.GetPoint("To point")
    ndups = rs.GetInteger("Number of duplications")
    maxd = rs.GetReal("Max Distance")

    translation = rs.VectorCreate(endpt, origin)
    for i in range(0, ndups, 1):
        xr = random() if random() < 0.5 else -1 * random()
        yr = random() if random() < 0.5 else -1 * random()
        zr = random() if random() < 0.5 else -1 * random()
        newpt = [xr * maxd, yr * maxd, zr * maxd]
        translation1 = rs.VectorCreate(endpt, newpt)
        translation2 = rs.VectorCreate(translation1, origin)
        copied_obj_ids = rs.CopyObjects(obj_ids, translation2)
        xyp = rs.WorldXYPlane()
        rs.RotateObjects(copied_obj_ids, newpt, random() * 360, xyp[0])
        rs.RotateObjects(copied_obj_ids, newpt, random() * 360, xyp[1])
        rs.RotateObjects(copied_obj_ids, newpt, random() * 360, xyp[2])
示例#2
0
def transformMatrix():
    obj_ids = rs.GetObjects("Select object(s) from which to create matrix", 0,
                            True, True)
    if obj_ids is None: return

    box = rs.BoundingBox(obj_ids)
    if not isinstance(box, list): return
    origin = rs.PointDivide(rs.PointAdd(box[0], box[6]), 2)
    endpt = rs.GetPoint("To point")

    newpt = [1, 1, 1]
    translation1 = rs.VectorCreate(endpt, newpt)
    translation2 = rs.VectorCreate(translation1, origin)
    copied_obj_ids = rs.CopyObjects(obj_ids, translation2)

    for obj in copied_obj_ids:
        matrix = []
        degrees = 90.0  # Some angle
        radians = math.radians(degrees)
        c = math.cos(radians)
        s = math.sin(radians)
        matrix.append([c, -s, 0, 0])
        matrix.append([s, c, 0, 0])
        matrix.append([0, 0, 1, 0])
        matrix.append([0, 0, 0, 1])
        pprint.pprint(matrix)
        rs.ScaleObject(obj, newpt, [3, 1, -9])
        plane = rs.ViewCPlane()
        pprint.pprint(plane)
        rs.RotateObject(obj, newpt, uniform(0, 360), plane.XAxis)
        rs.RotateObject(obj, newpt, uniform(0, 360), plane.YAxis)
        rs.RotateObject(obj, newpt, uniform(0, 360), plane.ZAxis)
示例#3
0
def testDuplications():
    print("\n testDuplications commands \n")

    obj_ids = rs.GetObjects(
        "Select object(s) from which to create the rectangular matrix", 0,
        True, True)
    if obj_ids is None: return

    box = rs.BoundingBox(obj_ids)
    if not isinstance(box, list): return
    origin = rs.PointDivide(rs.PointAdd(box[0], box[6]), 2)

    nXdups = rs.GetInteger("Duplications X", 1, 1)
    rXdups = rs.GetReal("Duplications X rand", 0, 0, 100) / 100

    nYdups = rs.GetInteger("Duplications Y", 1, 1)
    rYdups = rs.GetReal("Duplications Y rand", 0, 0, 100) / 100

    nZdups = rs.GetInteger("Duplications Z", 1, 1)
    rZdups = rs.GetReal("Duplications Z rand", 0, 0, 100) / 100

    rKeep = 1 - rs.GetReal("Percent to erase", 0, 0, 100) / 100

    endpt = rs.GetPoint("To point")

    calc_val_real = lambda val, rand: val + random.uniform(
        -rand * val, rand * val)
    calc_val_int = lambda val, rand: val + int(
        round(random.uniform(-rand * val, rand * val)))

    xspace = 3
    yspace = 3
    zspace = 3

    xdups = calc_val_int(nXdups, rXdups)
    ydups = calc_val_int(nYdups, rYdups)
    zdups = calc_val_int(nZdups, rZdups)

    translations = []
    # Copy Points with Spacing
    for k in range(zdups):
        for j in range(ydups):
            for i in range(xdups):
                newpt = [
                    origin[0] + i * xspace, origin[1] + j * yspace,
                    origin[2] + k * zspace
                ]
                translations = translations + [rs.VectorCreate(endpt, newpt)]

    nObjs = len(translations)
    print(nObjs)
    objs_to_keep = random.sample(range(nObjs), int(round(nObjs * rKeep)))
    translations = [translations[i] for i in objs_to_keep]

    copied_objs = []
    for tr in translations:
        copied_objs = copied_objs + rs.CopyObjects(obj_ids, tr)
示例#4
0
def main():
    objs = rs.GetObjects("Select Objects to Number", preselect = True)
    if objs is None: return
    pts = []
    for obj in objs:
        pt0 = rs.BoundingBox(obj)[0]
        pt2 = rs.BoundingBox(obj)[2]
        centerPt = rs.PointDivide(rs.PointAdd(pt0, pt2), 2)
        pts.append(centerPt)
    sortedPts = proximityPts(pts,0)
    addNumberTag(sortedPts, objs)
    print len(sortedPts)
def nameTag(obj):
    roomName = rs.ObjectName(obj)

    try:
        text = str(roomName)
        pt0 = rs.BoundingBox(obj)[0]
        pt2 = rs.BoundingBox(obj)[2]
        pt = rs.PointDivide(rs.PointAdd(pt0, pt2), 2)
        areaTag = rs.AddText(text, pt, 1, justification=131074)
    except:
        print "Object has no name"
        return

    parentLayer = rs.ParentLayer(rs.ObjectLayer(obj))
    hostLayer = rs.AddLayer("ANNO_NAME", (128, 128, 128), parent=parentLayer)
    rs.ObjectLayer(areaTag, hostLayer)
    return None
示例#6
0
def duplicateN():
    obj = rs.GetObject("Select object to duplicate", 16, True)
    if obj is None: return

    box = rs.BoundingBox(obj)
    if not isinstance(box, list): return
    origin = rs.PointDivide(rs.PointAdd(box[0], box[6]), 2)

    endpt = rs.GetPoint("To point")
    ndups = rs.GetInteger("Number of duplications")
    maxd = rs.GetReal("Max Distance")

    translation = rs.VectorCreate(endpt, origin)
    for i in range(0, ndups, 1):
        xr = random() if random() < 0.5 else -1*random()
        yr = random() if random() < 0.5 else -1*random()
        zr = random() if random() < 0.5 else -1*random()
        newpt = [xr*maxd, yr*maxd, zr*maxd]
        translation1 = rs.VectorCreate(endpt, newpt)
        translation2 = rs.VectorCreate(translation1, origin)
        rs.CopyObject(obj, translation2)
def layerTag(obj):

    roomName = rs.LayerName(rs.ObjectLayer(obj), False)
    #add text tag
    try:
        text = str(roomName)
        pt0 = rs.BoundingBox(obj)[0]
        pt2 = rs.BoundingBox(obj)[2]
        pt = rs.AddPoint(rs.PointDivide(rs.PointAdd(pt0, pt2), 2))
        rs.MoveObject(pt, [0, 1.5, 0])
        areaTag = rs.AddText(text, pt, 1, justification=131074)
    except:
        print "Object has no name"
        return
    rs.DeleteObject(pt)
    parentLayer = rs.ParentLayer(rs.ObjectLayer(obj))
    hostLayer = rs.AddLayer("ANNO_LAYER", (128, 128, 128), parent=parentLayer)
    rs.ObjectLayer(areaTag, hostLayer)

    #te = rs.coercerhinoobject(id, True, True)
    #te.Geometry.TextFormula = text
    #te.CommitChanges()
    #sc.doc.Views.Redraw()
    return None
def testDuplicationsAndSpaceAndScaleAndRotate():
    print("\n testDuplicationsAndSpaceAndScaleAndRotate commands \n")

    obj_ids = rs.GetObjects(
        "Select object(s) from which to create the rectangular matrix", 0,
        True, True)
    if obj_ids is None: return

    box = rs.BoundingBox(obj_ids)
    if not isinstance(box, list): return
    origin = rs.PointDivide(rs.PointAdd(box[0], box[6]), 2)

    nXdups = rs.GetInteger("Max Duplications X", 1, 1)
    nYdups = rs.GetInteger("Max Duplications Y", 1, 1)
    nZdups = rs.GetInteger("Max Duplications Z", 1, 1)

    nXspace = rs.GetReal("Spacing X", 1, 0)
    rXspace = rs.GetReal("Spacing X rand", 0, 0, 100) / 100

    nYspace = rs.GetReal("Spacing Y", 1, 0)
    rYspace = rs.GetReal("Spacing Y rand", 0, 0, 100) / 100

    nZspace = rs.GetReal("Spacing Z", 1, 0)
    rZspace = rs.GetReal("Spacing Z rand", 0, 0, 100) / 100

    nXscale = rs.GetReal("Scale X", 1, 0)
    rXscale = rs.GetReal("Scale X rand", 0, 0, 100) / 100

    nYscale = rs.GetReal("Scale Y", 1, 0)
    rYscale = rs.GetReal("Scale Y rand", 0, 0, 100) / 100

    nZscale = rs.GetReal("Scale Z", 1, 0)
    rZscale = rs.GetReal("Scale Z rand", 0, 0, 100) / 100

    nXrotate = rs.GetReal("Rotate X", 0, 0, 360)
    rXrotate = rs.GetReal("Rotate X rand", 0, 0, 100) / 100

    nYrotate = rs.GetReal("Rotate Y", 0, 0, 360)
    rYrotate = rs.GetReal("Rotate Y rand", 0, 0, 100) / 100

    nZrotate = rs.GetReal("Rotate Z", 0, 0, 360)
    rZrotate = rs.GetReal("Rotate Z rand", 0, 0, 100) / 100

    rKeep = 1 - rs.GetReal("Percent to erase", 0, 0, 100) / 100

    endpt = rs.GetPoint("To point")

    sample_near_val = lambda val, rand: random.uniform(-rand * val, rand * val)

    translations = []
    # Copy Points with Spacing
    for k in range(nZdups):
        for j in range(nYdups):
            for i in range(nXdups):
                newpt = [
                    origin[0] + i * nXspace +
                    sample_near_val(nXspace, rXspace), origin[1] +
                    j * nYspace + sample_near_val(nYspace, rYspace),
                    origin[2] + k * nZspace +
                    sample_near_val(nZspace, rZspace)
                ]
                translations = translations + [rs.VectorCreate(endpt, newpt)]

    nObjs = len(translations)
    objs_to_keep = random.sample(range(nObjs), int(round(nObjs * rKeep)))
    translations = [translations[i] for i in objs_to_keep]

    copied_objs = []
    for tr in translations:
        copied_objs = copied_objs + rs.CopyObjects(obj_ids, tr)

    for obj in copied_objs:
        bb = rs.BoundingBox(obj)
        if bb:
            center_point = rs.PointDivide(rs.PointAdd(bb[0], bb[6]), 2)
            # pt = rs.SurfaceVolumeCentroid(obj)
            rs.ScaleObject(obj, center_point, [
                nXscale + sample_near_val(nXscale, rXscale),
                nYscale + sample_near_val(nYscale, rYscale),
                nZscale + sample_near_val(nZscale, rZscale)
            ])
            plane = rs.ViewCPlane()
            rs.RotateObject(obj, center_point,
                            nXrotate + sample_near_val(nXrotate, rXrotate),
                            plane.XAxis)
            rs.RotateObject(obj, center_point,
                            nYrotate + sample_near_val(nYrotate, rYrotate),
                            plane.YAxis)
            rs.RotateObject(obj, center_point,
                            nZrotate + sample_near_val(nZrotate, rZrotate),
                            plane.ZAxis)
 def getMidpoint3D(self, b2):
     return rs.PointDivide(
         rs.PointAdd(self.getLocationAsPoint(), b2.getLocationAsPoint()), 2)
import rhinoscriptsyntax as rs
import Rhino
import scriptcontext as sc

### Objects to rotate about their center ###
opobj = rs.GetObjects(message="Select objects to rotate.")

for obj in opobj:
    bounds = rs.BoundingBox(obj)
    ptAdd = bounds[0]
    for p in bounds[1:4]:
        ptAdd = rs.PointAdd(ptAdd, p)

    center = rs.PointDivide(ptAdd, 4)

    rs.RotateObject(obj, center, 180)
示例#11
0
def createRectangularMatrix():
    print("\n createRectangularMatrix commands \n")

    obj_ids = rs.GetObjects(
        "Select object(s) from which to create the rectangular matrix", 0,
        True, True)
    if obj_ids is None: return

    box = rs.BoundingBox(obj_ids)
    if not isinstance(box, list): return
    origin = rs.PointDivide(rs.PointAdd(box[0], box[6]), 2)

    nXdups = rs.GetInteger("Duplications X", 1, 1)
    rXdups = rs.GetReal("Duplications X rand", 0, 0, 100) / 100

    nYdups = rs.GetInteger("Duplications Y", 1, 1)
    rYdups = rs.GetReal("Duplications Y rand", 0, 0, 100) / 100

    nZdups = rs.GetInteger("Duplications Z", 1, 1)
    rZdups = rs.GetReal("Duplications Z rand", 0, 0, 10) / 100

    nXspace = rs.GetReal("Spacing X", 1, 0)
    rXspace = rs.GetReal("Spacing X rand", 0, 0, 100)

    nYspace = rs.GetReal("Spacing Y", 1, 0)
    rYspace = rs.GetReal("Spacing Y rand", 0, 0, 100)

    nZspace = rs.GetReal("Spacing Z", 1, 0)
    rZspace = rs.GetReal("Spacing Z rand", 0, 0, 100)

    nXscale = rs.GetReal("Scale X", 1, 0)
    rXscale = rs.GetReal("Scale X rand", 0, 0, 100)

    nYscale = rs.GetReal("Scale Y", 1, 0)
    rYscale = rs.GetReal("Scale Y rand", 0, 0, 100)

    nZscale = rs.GetReal("Scale Z", 1, 0)
    rZscale = rs.GetReal("Scale Z rand", 0, 0, 100)

    nXrotate = rs.GetReal("Rotate X", 0, 0)
    rXrotate = rs.GetReal("Rotate X rand", 0, 0, 100)

    nYrotate = rs.GetReal("Rotate Y", 0, 0)
    rYrotate = rs.GetReal("Rotate Y rand", 0, 0, 100)

    nZrotate = rs.GetReal("Rotate Z", 0, 0)
    rZrotate = rs.GetReal("Rotate Z rand", 0, 0, 100)

    endpt = rs.GetPoint("To point")

    calc_val_real = lambda val, rand: val + uniform(-rand * val, rand * val)
    calc_val_int = lambda val, rand: val + int(
        round(uniform(-rand * val, rand * val)))

    xdups = calc_val_int(nXdups, rXdups)
    ydups = calc_val_int(nYdups, rYdups)
    zdups = calc_val_int(nZdups, rZdups)

    xspace = calc_val_real(nXspace, rXspace)
    yspace = calc_val_real(nYspace, rYspace)
    zspace = calc_val_real(nZspace, rZspace)

    xscale = calc_val_real(nXscale, rXscale)
    yscale = calc_val_real(nYscale, rYscale)
    zscale = calc_val_real(nZscale, rZscale)

    xrotate = calc_val_real(nXrotate, rXrotate)
    yrotate = calc_val_real(nYrotate, rYrotate)
    zrotate = calc_val_real(nZrotate, rZrotate)

    # Copy Points with Spacing
    for k in range(zdups):
        for j in range(ydups):
            for i in range(xdups):
                newpt = [
                    origin[0] + i * xspace, origin[1] + j * yspace,
                    origin[2] + k * zspace
                ]
                translation1 = rs.VectorCreate(endpt, newpt)
                #                translation2 = rs.VectorCreate(translation1, origin)
                copied_obj_ids = rs.CopyObjects(obj_ids, translation1)
                for obj in copied_obj_ids:
                    rs.ScaleObject(obj, newpt, [xscale, yscale, zscale])
                    plane = rs.ViewCPlane()
                    rs.RotateObject(obj, newpt, xrotate, plane.XAxis)
                    rs.RotateObject(obj, newpt, yrotate, plane.YAxis)
                    rs.RotateObject(obj, newpt, zrotate, plane.ZAxis)