def tree_gen(self, radius, height):
   result = []
   summary = []
   if radius < self.terminal_radius:
     if self.for_reals:
       result.append(self.get_leaf())
     summary.append("leaf")
   else:
     if self.for_reals:
       result.append(self.twig_gen(radius, radius, height))
     summary.append("twig " + str(radius) + " " + str(height))
     subs = []
     sub_radius = radius * self.radius_fraction
     sub_height = height * self.height_fraction
     sub_angle_y = self.bend
     for i in range(self.density):
       sub_angle_z = (i + (0.5 * random.random())) * (360 / self.density)
       sub, sub_summary = self.tree_gen(sub_radius, sub_height)
       if self.for_reals:
         sub = rs.RotateObjects(sub, (0,0,0), sub_angle_y, (0,1,0))
         sub = rs.RotateObjects(sub, (0,0,0), sub_angle_z, (0,0,1))
         sub = rs.MoveObjects(sub, (0,0,height))
       subs += sub
       summary.append(sub_summary)
     center, center_summary = self.tree_gen(sub_radius, sub_height)
     if self.for_reals:
       center = rs.MoveObjects(center, (0,0,height))
     result += subs + center
     summary.append(center_summary)
   return result, summary
Example #2
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])
Example #3
0
def rotateObjects():
    obj_ids = rs.GetObjects("Select objects", 0, True, True)
    if obj_ids is None: return

    center = rs.GetPoint("About which point?")
    if center is None: return

    xyp = rs.WorldXYPlane()
    rs.RotateObjects(obj_ids, center, random() * 360, xyp[0])
    rs.RotateObjects(obj_ids, center, random() * 360, xyp[1])
    rs.RotateObjects(obj_ids, center, random() * 360, xyp[2])
def GroupMove(rectOutlineList, objects, objCenter, rotatedAngle, movingCenter):
    for objs, rect, center, rotAngle, centerStart in zip(
            objects, rectOutlineList, objCenter, rotatedAngle, movingCenter):
        # rotate everything by center with rotatedAngle
        rs.RotateObjects(objs, center, rotAngle)
        # find vector to move from obj location to rectangle(obj center to rect center)
        boxCenter = rs.CurveAreaCentroid(rect)[0]
        moveVector = rs.VectorCreate(boxCenter, center)
        # check if object is in box
        rectPt = rs.PolylineVertices(rect)
        rectPt = PointsReorder(rectPt, 1)
        if rs.Distance(rectPt[0], rectPt[1]) > rs.Distance(
                rectPt[1], rectPt[2]):
            rs.RotateObjects(objs, center, 90)
        rs.MoveObjects(objs, moveVector)
Example #5
0
def make_stem_pieces(b):
    obj1 = []
    h = (b.tof[0].chine_hab - b.tof[1].chine_hab) * (
        b.tof[0].section - b.chine) / (b.tof[1].section -
                                       b.tof[0].section) + b.tof[0].chine_hab
    p1 = [b.chine, 0, h]
    obj1.append(rs.AddLine([0, 0, b.bow], p1))
    obj1.append(rs.AddLine([0, 0, b.bow], [b.stem_width, 0, b.bow]))
    obj1.append(
        rs.AddLine([b.stem_width, 0, b.bow], ss(p1, [b.stem_width, 0, 0])))
    obj1.append(rs.AddLine(ss(p1, [b.stem_width, 0, 0]), p1))
    obj1 = rs.MoveObjects(rs.JoinCurves(obj1, delete_input=True), sm(-1, p1))

    obj2 = []
    h = (b.tof[-1].chine_hab -
         b.tof[-2].chine_hab) * (b.loa - b.aft - b.tof[-1].section) / (
             b.tof[-1].section - b.tof[-2].section) + b.tof[-1].chine_hab
    p2 = [b.loa - b.aft, 0, h]
    obj2.append(rs.AddLine([b.loa, 0, b.stern], p2))
    obj2.append(
        rs.AddLine([b.loa, 0, b.stern], [b.loa - b.stem_width, 0, b.stern]))
    obj2.append(
        rs.AddLine([b.loa - b.stem_width, 0, b.stern],
                   ss(p2, [-b.stem_width, 0, 0])))
    obj2.append(rs.AddLine(ss(p2, [-b.stem_width, 0, 0]), p2))
    obj2 = rs.MoveObjects(rs.JoinCurves(obj2, delete_input=True), sm(-1, p2))

    return rs.RotateObjects(obj1 + obj2, [0, 0, 0], 90, [1, 0, 0])
Example #6
0
def make_jigs(b, diam, bdiam):
    jig_base_height = 4. / 12
    jig_clearance = .25 / 12

    #	for s in [b.tof[i] for i in [0,2,5,7]]:
    for s in b.tof:
        r = 90

        width = 5 * b.deckString.thickness
        height = s.keel_hab + 2 * b.deckString.width + jig_base_height
        p = [s.section, 0, 0]
        rect = x_rectangle_cut_out(
            p, width, height, b.deckString.thickness + 2 * jig_clearance,
            height - jig_base_height + jig_clearance + b.deckString.width)
        rect = [rs.MoveObject(rect, [0, 0, -jig_base_height])]
        plane = rs.PlaneFromNormal([s.section, 0, 0], [1, 0, 0])
        holes = [
            rs.MoveObject(rs.AddCircle(plane, diam / 2), [
                0, 1.5 * b.deckString.thickness,
                s.keel_hab + b.deckString.width
            ])
        ]
        holes.extend(rs.MirrorObjects(holes, p, ss(p, [1, 0, 0]), copy=True))
        bhole = rs.MoveObject(rs.AddCircle(plane, bdiam / 2),
                              [0, 0, 47. / 64 / 12 - jig_base_height])
        holes.extend([bhole, rs.CopyObject(bhole, [0, 0, 1.5 / 12])])
        rs.RotateObjects(rect + holes, p, 90, [0, 1, 0])
Example #7
0
    def update(self):
        print('update')
        #delete last generated objects
        try:
            rs.DeleteObjects(self.generatedObjs)
            self.generatedObjs = []
        except:
            print('exception in delete generated object')

        divWidth = 600
        crv = self.baseCrv
        if not rs.IsObject(crv):
            print('crv is not an object')
            return

        if not rs.IsPolyline(crv):
            pts = rs.DivideCurveEquidistant(crv, divWidth)
            rail = rs.AddPolyline(pts)
        else:
            rail = rs.CopyObject(crv)

        pts = rs.CurveEditPoints(rail)
        if len(pts) < 3:
            print('too little points')
            return

        #find vectors to move and orient the profile
        vect = pts[1] - pts[0]
        vect = rs.VectorUnitize(vect)
        a = rs.VectorAngle(vect, (0, 1, 0)) - 90

        #load the component
        path = self.loadPath
        component = None
        try:
            component = importComponent(path)
        except:
            print('exception on importing module')

        if component is None:
            print('component is None')
            return None

        #rs.MoveObjects(component.breps,pts[0])
        #rs.RotateObjects(component.breps,pts[0],a)
        for b in component.breps:
            self.generatedObjs.append(b)
            oriented = orientObjAlongPolyPts(b, pts)
            print('pts count:', len(pts), ' num gen:', len(oriented))

        rs.MoveObjects(component.polys, pts[0])
        rs.RotateObjects(component.polys, pts[0], a)
        for c in component.polys:
            self.generatedObjs.append(c)
            mesh = meshSwipPolyAlongPoly(c, rail)
            self.generatedObjs.append(mesh)
        rs.DeleteObject(rail)
        print('generated obj count:', len(self.generatedObjs))
        rs.AddGroup('gen')
        rs.AddObjectsToGroup(self.generatedObjs, 'gen')
Example #8
0
def spin():
    line = rs.AddLine((0, 0, 0), (5, 0, 0))
    circle = rs.AddCircle((5, 0, 0), 1)
    for i in range(30):
        time.sleep(0.1)
        rs.RotateObjects((line, circle), (0, 0, 0), 15)
        # call wait to ensure Rhino "catches-up" with drawing
        Rhino.RhinoApp.Wait()
Example #9
0
def Section2D():
    #"Create cross-section and rotate to 2D plane"

    # Select objects to draw section from
    objects = rs.GetObjects("Select objects to rotate", rs.filter.curve)
    # Select cross section plane
    sectionplane = rs.GetObject("Select cross-section line", rs.filter.curve)

    # Calculate orientation of cross-section plane
    startpt = rs.CurveStartPoint(sectionplane)
    midpt = rs.CurveMidPoint(sectionplane)
    endpt = rs.CurveEndPoint(sectionplane)

    x1, y1 = startpt[0], startpt[1]
    x2, y2 = endpt[0], endpt[1]

    rad2deg = 180 / math.pi
    angle = math.atan((y2 - y1) / (x2 - x1)) * rad2deg

    # rotate cross-section objects to 2D plane
    rs.RotateObjects(objects, midpt, -angle)
    rs.RotateObjects(objects, midpt, -90, [1, 0, 0])
Example #10
0
def draw_frame_layout(s, keel_str, chine_str, gunwale_str, deck_str, diam,
                      bdiam):
    objs = []
    t = [0, 2 * s.gunwale_hb, 0]
    r = 90
    #	t = [0,0,0]
    #	r = 0

    objs.append(
        rs.AddLine([s.section, 0, s.keel_hab],
                   [s.section, s.chine_hb, s.chine_hab]))
    objs.append(
        rs.AddLine([s.section, s.chine_hb, s.chine_hab],
                   [s.section, s.gunwale_hb, s.gunwale_hab]))
    objs.append(
        rs.AddLine([s.section, s.gunwale_hb, s.gunwale_hab],
                   [s.section, s.deckridge_hb, s.deckridge_hab]))
    if (s.deckridge_hb != 0):
        objs.append(
            rs.AddLine([s.section, s.deckridge_hb, s.deckridge_hab],
                       [s.section, 0., s.deckridge_hab]))
    objs.extend(rs.MirrorObjects(objs, [0, 0, 0], [1, 0, 0], copy=True))
    objs = rs.JoinCurves(objs, delete_input=True)

    #ins = rs.OffsetCurve(objs,[s.section,0,.5*s.deckridge_hab],s.width + .75*deck_str.width,normal=[1,0,0])
    #	if not ins: ins = []
    ins = []
    rs.DeleteObjects(objs)

    chine_edge = make_chine_edge([s.section, s.chine_hb, s.chine_hab],
                                 [s.section, s.gunwale_hb, s.gunwale_hab],
                                 chine_str.thickness, gunwale_str.thickness,
                                 chine_str.width, gunwale_str.width,
                                 [s.section, s.deckridge_hb, s.deckridge_hab])
    keel_edge = make_keel_edge([s.section, 0, s.keel_hab],
                               [s.section, s.chine_hb, s.chine_hab],
                               keel_str.thickness, keel_str.width,
                               [s.section, s.gunwale_hb, s.gunwale_hab])
    deck_edge = make_deck_edge([s.section, s.gunwale_hb, s.gunwale_hab],
                               [s.section, s.deckridge_hb, s.deckridge_hab],
                               deck_str.thickness, gunwale_str.thickness,
                               deck_str.width,
                               [s.section, s.chine_hb, s.chine_hab],
                               s.deck_string_place)

    edges = chine_edge + keel_edge + deck_edge
    edges.extend(rs.MirrorObjects(edges, [0, 0, 0], [1, 0, 0], copy=True))
    edges = rs.JoinCurves(edges, delete_input=True)
    edges.extend(
        rs.OffsetCurve(edges, [s.section, 0, .5 * s.deckridge_hab],
                       s.width,
                       normal=[1, 0, 0],
                       style=3))
    g = rs.AddGroup()
    rs.AddObjectsToGroup(edges, g)

    #	if s.num-1 in [0,2,5,7]:
    if 1:
        p = [s.section, 0, 0]
        plane = rs.PlaneFromNormal(p, [1, 0, 0])
        holes = [
            rs.MoveObject(
                rs.AddCircle(plane, diam / 2),
                [0, 1.5 * deck_str.thickness, s.keel_hab + deck_str.width])
        ]
        holes.extend(rs.MirrorObjects(holes, p, ss(p, [1, 0, 0]), copy=True))
    else:
        holes = []

    rs.MoveObjects(
        rs.RotateObjects(ins + edges + holes, [s.section, 0, s.keel_hab], r,
                         [0, 1, 0]), t)
 def matchWObj(self, geoList):
     ref = rs.AddPoint(0, 0, 0)
     vec = rs.VectorCreate(rs.AddPoint(self.WObj), ref)
     rot = rs.RotateObjects(geoList, rs.AddPoint(0, 0, 0), -90, copy=True)
     return rs.CopyObjects(rot, vec)
Example #12
0
def wakame():
    h1 = 3
    h2 = 6
    p1_box = []
    p2_box = []
    for t in rs.frange(0, 360, 10):
        rg = ma.sin(ma.radians(t / 3 + 30)) / 2 + 1.3
        hg = ma.sin(ma.radians(t / 2)) / 4 + 0.5
        tt = 0.7

        r_1 = 5
        theta_1 = t
        h_1 = 0
        p_1 = polar(r_1, theta_1, h_1)

        r_2 = 6
        theta_2 = t
        h_2 = 11 * hg
        p_2 = polar(r_2, theta_2, h_2)

        r_3 = 10 * rg
        theta_3 = t
        h_3 = 15 * hg
        p_3 = polar(r_3, theta_3, h_3)

        r_4 = 15 * rg
        theta_4 = t
        h_4 = 15 * hg
        p_4 = polar(r_4, theta_4, h_4)

        r_5 = 5 + tt
        theta_5 = t
        h_5 = 0
        p_5 = polar(r_5, theta_5, h_5)

        r_6 = 6 + tt
        theta_6 = t
        h_6 = 11 * hg - tt
        p_6 = polar(r_6, theta_6, h_6)

        r_7 = 10 * rg + tt
        theta_7 = t
        h_7 = 15 * hg - tt
        p_7 = polar(r_7, theta_7, h_7)

        r_8 = 15 * rg
        theta_8 = t
        h_8 = 15 * hg - tt
        p_8 = polar(r_8, theta_8, h_8)

        p_1_box = [p_1, p_2, p_3, p_4]
        cu1 = rs.AddCurve(p_1_box)

        p_2_box = [p_5, p_6, p_7, p_8]
        cu2 = rs.AddCurve(p_2_box)

        l1 = rs.AddLine(p_1, p_5)
        l2 = rs.AddLine(p_4, p_8)

        si = draw_sikaku(h1)
        p1 = rs.CurveSurfaceIntersection(cu1, si)
        p1_box.append(p1[0][1])

        si = draw_sikaku(h2)
        p2 = rs.CurveSurfaceIntersection(cu1, si)
        p2_box.append(p2[0][1])

        r1 = draw_rectangle1(p1[0][1], t)
        r2 = draw_rectangle1(p2[0][1], t)

        rs.RotateObjects(r1, (0, 0, 0), 90, polar(12, t, 0), False)
        rs.MoveObjects(r1, polar(0, t, 0))
        rs.RotateObjects(r1, (0, 0, 0), -t, None, False)
        rs.MoveObjects(r1, (t * 0.12, t * 0.12, 0))

        rs.RotateObjects(r2, (0, 0, 0), 90, polar(12, t, 0), False)
        rs.MoveObjects(r2, polar(0, t, 0))
        rs.RotateObjects(r2, (0, 0, 0), -t, None, False)
        rs.MoveObjects(r2, (t * 0.12, t * 0.12, 0))

        all = [l1, l2, cu1, cu2]
        rs.RotateObjects(all, (0, 0, 0), 90, polar(12, t, 0), False)
        rs.MoveObjects(all, polar(0, t, 0))
        rs.RotateObjects(all, (0, 0, 0), -t, None, False)
        rs.MoveObjects(all, (t * 0.12, t * 0.12, 0))

    c1 = rs.AddInterpCurve(p1_box)
    c2 = rs.AddInterpCurve(p2_box)

    rs.ScaleObject(c1, (0, 0, h1), (1.2, 1.2, 1), True)
    rs.ScaleObject(c2, (0, 0, h2), (1.1, 1.1, 1), True)
    rs.ScaleObject(c1, (0, 0, h1), (0.6, 0.6, 0.75), True)
    rs.ScaleObject(c2, (0, 0, h2), (0.9, 0.9, 1), True)
    rs.DeleteObject(c1)
    rs.DeleteObject(c2)

    all = [cu1, cu2]
    return all
Example #13
0
def draw_rectangle1((x, y, z), theta):
    t = 1
    p = (x, y, z)
    p0 = rs.AddPoint(p)
    p1 = rs.CopyObject(p0, polar(0.115, theta + 90, 0))
    p2 = rs.CopyObject(p0, polar(0.115, theta - 90, 0))
    p3 = rs.CopyObject(p2, polar(1.0, theta, 0))
    p4 = rs.CopyObject(p1, polar(1.0, theta, 0))
    rec = [
        rs.AddLine(p1, p2),
        rs.AddLine(p2, p3),
        rs.AddLine(p3, p4),
        rs.AddLine(p4, p1)
    ]
    rs.MoveObject(rec, polar(0.4, theta, 0))
    rect = rs.RotateObjects(rec, (0, 0, z), 90, (x, y, 0), True)
    rect = rs.MoveObjects(rect, polar(-1, theta, 0))
    return rect


def wakame():
    h1 = 3
    h2 = 6
    p1_box = []
    p2_box = []
    for t in rs.frange(0, 360, 10):
        rg = ma.sin(ma.radians(t / 3 + 30)) / 2 + 1.3
        hg = ma.sin(ma.radians(t / 2)) / 4 + 0.5
        tt = 0.7

        r_1 = 5
Example #14
0
def RunCommand(is_interactive):
    # get input objects
    objs = rs.GetObjects("Select object(s) to connect")
    if (objs is None):
        return 1
    # select source handle
    source = rs.GetObject("Select sender handle (L polyline)", rs.filter.curve)
    if (source is None):
        return 1
    sPoly = rs.coercecurve(source)

    # select destination handle
    receiver = rs.GetObject("Select receiver handle (L polyline)",
                            rs.filter.curve)
    if (receiver is None):
        return 1
    rPoly = rs.coercecurve(receiver)

    if not (rs.IsPolyline(sPoly) & rs.IsPolyline(rPoly)): return 1

    preview = []
    while True:
        # input rotation angle
        rotation = rs.GetReal("Rotation angle (degrees)", 0, -360, 360)
        if rotation is None: break
        rs.EnableRedraw(False)

        # precalculate points, planes and transformation
        sPts = ptsFromPolyline(sPoly)
        rPts = ptsFromPolyline(rPoly)
        sPlane = planeFromPts(sPts)
        rPlane = planeFromPts(rPts)
        origin = rPts[0]
        rPts = rs.RotateObjects(rPts, origin, 180, rPlane.YAxis)
        rPts1 = rs.RotateObjects(rPts, origin, -rotation, rPlane.ZAxis)
        for obj in objs:
            preview.append(rs.OrientObject(obj, sPts, rPts1, 1))

        rs.DeleteObjects(rPts1)
        rs.EnableRedraw(True)
        result = rs.GetString("Looks good?", "Yes", ("Yes", "No"))
        if result is None:
            rs.EnableRedraw(False)
            for obj in preview:
                rs.DeleteObject(obj)
            rs.EnableRedraw(True)
            break
        result = result.upper()
        if result == "YES":
            group_map = []
            for obj in preview:
                obj = rs.coercerhinoobject(obj)
                RhinoUpdateObjectGroups(obj, group_map)
            break
        elif result == "NO":
            rs.EnableRedraw(False)
            for obj in preview:
                rs.DeleteObject(obj)
            rs.EnableRedraw(True)

    # you can optionally return a value from this function
    # to signify command result. Return values that make
    # sense are
    #   0 == success
    #   1 == cancel
    # If this function does not return a value, success is assumed
    return 0
Example #15
0
def quad_rotate_object(object_id, center_point=(0, 0, 0), axis=None):
    _rotated = rss.RotateObject(
        object_id, center_point, 180.0, axis, copy=True)
    return [object_id, _rotated] + rss.RotateObjects((object_id, _rotated), center_point, 90.0, axis, copy=True)
Example #16
0
        beam_origin,
        rss.PointAdd(beam_origin, (0, 0, 8)),
        rss.PointAdd(beam_origin, (0, -5, BEAM_HEIGHT)),
        rss.PointAdd(beam_origin, (0, -BEAM_LENGTH + 5, BEAM_HEIGHT)),
        rss.PointAdd(beam_origin, (0, -BEAM_LENGTH, 8)),
        rss.PointAdd(beam_origin, (0, -BEAM_LENGTH, 0)),
        beam_origin
    ))
    beam = extrude_crv_along_line(beam_path, beam_origin, (BEAM_WIDTH, 0, 0))
    beam_copy = rss.RotateObject(
        rss.CopyObject(beam, (11, 0, 0)), (0, 0, 0), 90.0)
    layer2 = rss.BooleanUnion(
        [beam, beam_copy]
        + rss.RotateObjects(
            (beam, beam_copy),
            (0, 0, 0),
            180.0,
            copy=True
        ))

    if ADD_JUNCTION:
        # Original `base` is deleted during the boolean union, re-binding name `base` for later reference.
        base = rss.BooleanUnion(
            base + quad_mirror_object(
                rss.AddCylinder((CORE_RADIUS, 1, PLANE_HEIGHT), 3, 0.8)
            )
        )
        slot = add_box(
            (CORE_RADIUS, 4, PLANE_HEIGHT),
            (-1, 0, 0),
            (0, -8, 0),
            (0, 0, 5)