def set_up():
    g.Grammar.clear_all()
    message1 = "Select point 1"
    message2 = "Select point 2"
    p1 = rs.GetPoint(message1)
    p2 = rs.GetPoint(message2)
    return [p1, p2]
Пример #2
0
def export_curdatapoints():
    object_id = rs.GetObject("Select curve", rs.filter.curve)
    if( object_id==None ): return

    #Get the filename to create
    filter = "Text File (*.shf)|*.shf|All Files (*.*)|*.*||"
    filename = rs.SaveFileName("Save point coordinates as", filter)
    if( filename==None ): return
    if rs.IsCurveClosed(object_id):
        start_point = rs.GetPoint("Base point of center line")
    
        end_point = rs.GetPoint("Endpoint of center line", start_point)
        
        points = rs.CurveContourPoints(object_id, start_point, end_point)
    else:
        points = rs.CurveContourPoints(object_id,rs.CurveStartPoint(object_id),rs.CurveEndPoint(object_id))
    if not points: return
    

    file = open( filename, "w" )
    for pt in points:
        print(str(pt.X)+","+str(pt.Y)+","+str(pt.Z))
        file.write( str(pt.X) )
        file.write( ", " )
        file.write( str(pt.Y) )
        file.write( ", " )
        file.write( str(pt.Z) )
        file.write( "\n" )
    file.close()
Пример #3
0
def Height():
    try:

        pt01 = rs.GetPoint('Select first point to measure from')
        pt02 = rs.GetPoint('Select second point to measure to')

        if pt02:

            pt01Z = pt01.Z
            pt02Z = pt02.Z

            height = abs(pt01Z - pt02Z)
            height = round(height, 3)

            rs.ClipboardText(height)

            rs.MessageBox(
                height,
                buttons=0,
                title="Height difference - Value copied to clipboard")

    except:
        print("Failed to execute")
        rs.EnableRedraw(True)
        return
Пример #4
0
def connect(objects):
    points = []

    c = rs.GetPoint("inclusion radius - center")
    if not c: sys.exit("no center point specified")
    r = rs.GetPoint("inclusion radius - distance")
    if not c: sys.exit("no distance specified")

    maxradius = rs.Distance(c, r)

    blen = len(objects)
    print "before: ", blen, " objects"

    for i in range(len(objects) - 1):
        if rs.IsPoint(objects[i]):
            points.append(objects[i])

    alen = len(points)

    print "after: ", alen, " objects"

    for j in range(len(points) - 1):
        # for each point,
        for k in range(len(points) - 1):
            # go through each of the other objects:
            p1 = points[j]
            p2 = points[k]
            if p1 != p2:
                if rs.Distance(p1, p2) < maxradius:
                    rs.AddLine(p1, p2)
    def cone(self, radius):
        #        a = rs.AddPoint(self.point)
        base = rs.GetPoint("Base of cone")

        if base:

            height = rs.GetPoint("Height of cone", base)

        if height: rs.AddCone(base, height, radius, cap=False)
 def orient_block(self):
     #orient 2pt with 3d scaling enabled
     r1 = rs.GetPoint("Pick reference corner 1")
     r2 = rs.GetPoint("Pick reference corner 2")
     t1 = rs.GetPoint("Pick target corner 1")
     t2 = rs.GetPoint("Pick target corner 2")
     ref_pts = [r1, r2]
     target_pts = [t1, t2]
     moved = rs.OrientObject(self.paper_dwg, ref_pts, target_pts, flags=2)
     self.paper_dwg = moved
Пример #7
0
def Main():

    jointno = 4

    list = []

    dir0 = rs.GetPoint("from")
    dir1 = rs.GetPoint("hub")
    dir2 = rs.GetPoints(False, False, "outline_left_to_right")

    #THIS VECTOR WILL ALLOW US TO TAKE INTO ACCOUNT POSSIBLE LAYOUT OF DRAWN JOINTS ON THE PAGE
    fix = rs.VectorSubtract([0, 0, 0], dir1)

    dir0 = rs.VectorAdd(dir0, fix)
    dir1 = rs.VectorAdd(dir1, fix)
    indir = rs.VectorSubtract(dir1, dir0)

    for j in range(len(dir2)):
        pt = rs.VectorAdd(dir2[j], fix)
        dir2[j] = pt

    list.append([dir1, indir, dir2])

    for i in (range(jointno)[1:]):

        dir0 = rs.GetPoint("from")
        dir1 = rs.GetPoint("hub")
        dir2 = rs.GetPoint("to")

        #THIS VECTOR WILL ALLOW US TO TAKR INTO ACCOUNT POSSIBLE LAYOUT OF DRAWN JOINTS ON THE PAGE
        fix = rs.VectorSubtract([0, 0, 0], dir1)

        #What is this line doing???
        dir0 = rs.VectorAdd(dir0, fix)
        dir1 = rs.VectorAdd(dir1, fix)
        dir2 = rs.VectorAdd(dir2, fix)

        #Setting up direction vectors!
        indir = rs.VectorSubtract(dir1, dir0)
        outdir = rs.VectorSubtract(dir2, dir1)

        lside = rs.GetPoints(False, False, "left")
        rside = rs.GetPoints(False, False, "right")

        for j in range(len(lside)):
            pt = rs.VectorAdd(lside[j], fix)
            lside[j] = pt

        for j in range(len(rside)):
            pt = rs.VectorAdd(rside[j], fix)
            rside[j] = pt

        list.append([dir1, indir, lside, rside, outdir])

    WritePolies(addresss, list)
Пример #8
0
 def get_frame_position_from_user(cls):
     """Returns:
         origin          Point3d. The position of the frame instance. Must 
                         be in the xy plane
     """
     message_1 = "Select a point in the xy plane"
     message_2 = "The point must be in the xy plane. Try again"
     origin = rs.GetPoint(message_1)
     while not origin[2] == 0:
         origin = rs.GetPoint(message_2)
     return origin
def DrawArcSED():
    ptA = rs.GetPoint("Start of arc")
    if not ptA: return

    ptB = rs.GetPoint("End of arc")
    if not ptB: return

    ptD = rs.GetPoint("Direction of arc at start", ptA)
    if not ptD: return

    vecD = rs.PointSubtract(ptD, ptA)
    if rs.VectorLength(vecD) == 0.0: return
    AddArcDir(ptA, ptB, vecD)
Пример #10
0
def planeexample():
    origin = rs.GetPoint("Plane origin")
    if not origin: return

    ptX = rs.GetPoint("Plane X-axis", origin)
    if not ptX: return
    ptY = rs.GetPoint("Plane Y-axis", origin)
    if not ptY: return
	
    x = rs.Distance(origin, ptX)
    y = rs.Distance(origin, ptY)
    plane = rs.PlaneFromPoints(origin, ptX, ptY)
    rs.AddPlaneSurface(plane, 1.0, 1.0)
    rs.AddPlaneSurface(plane, x, y)
Пример #11
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."
Пример #12
0
def robot_script():

    sel_pt = rs.GetPoint("select point")

    #1) Use 6 values
    pose1 = urs.pose(sel_pt.X, sel_pt.Y, sel_pt.Z, 0, 0, 0)
    #2) Use two tuples - vector and orientation
    pose2_pos = (sel_pt.X, sel_pt.Y, sel_pt.Z + 0.15)
    pose2 = urs.pose_by_vectors(pose2_pos, (0, 0, 0))
    #3) Use a Rhino plane
    plane3 = rg.Plane(sel_pt, rg.Vector3d.ZAxis)
    pose3 = urs.pose_by_plane(plane3)
    #4) Use an origin and 2 vectors - same as a plane
    pose4_pos = (sel_pt.X, sel_pt.Y - 0.15, sel_pt.Z + 0.15)
    pose4 = urs.pose_by_origin_axis(pose4_pos, (1, 0, 0), (0, 1, 0))
    #5) Use a listened pose
    pose5_vals = comm.listen(ip)['tool_pose']
    pose5 = urs.pose(*pose5_vals)

    #Create a list of statements
    commands = []
    poses = (pose1, pose2, pose3, pose4)
    #Go through all poses
    for i in range(len(poses)):
        #Add a comment
        commands.append(urs.comment("Movement {}".format(i)))
        #Add a command
        commands.append(urs.movel(poses[i]))
    # return to pose 5 via movej
    commands.append(urs.movej(pose5))

    #3) Create a program using commands as argument
    my_program = urs.create_function("main", commands)
    return my_program
Пример #13
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])
Пример #14
0
    def create_board(self, size=CELL_SIZE):
        """Drawing a game board"""
        board_location_point = rs.GetPoint("Set board starter point")
        if board_location_point:
            self.board_location_point = board_location_point
        point = self.board_location_point
        self.grid = []
        for i in range(3):
            row = []
            for j in range(3):
                x1 = point[0] + i * size
                y1 = point[1] + j * size
                x2 = point[0] + (i + 1) * size
                y2 = point[1] + (j + 1) * size
                row.append([(x1, y1), (x2, y2)])
            self.grid.append(row)

        rectangles = [
            rs.AddRectangle((point[0], point[1] + size - size * .025, 0),
                            size * 3, size * .05),
            rs.AddRectangle((point[0], point[1] + 2 * size - size * .025, 0),
                            size * 3, size * .05),
            rs.AddRectangle((point[0] + size - size * .025, point[1], 0),
                            size * .05, size * 3),
            rs.AddRectangle((point[0] + 2 * size - size * .025, point[1], 0),
                            size * .05, size * 3)
        ]
        rs.CurveBooleanUnion(rectangles)
        rs.DeleteObjects(rectangles)
Пример #15
0
def ShowRL():
    try:

        def scale():
            system = rs.UnitSystem()
            if system == 2 or system == 3 or system == 4:
                scaleFactorDict = {2: 0.001, 3: 0.01, 4: 1}
                scaleFactor = scaleFactorDict[system]
                return scaleFactor

            if system != 2 or system != 3 or system != 4:
                return None

        if scale() == None:
            rs.MessageBox(
                "This tool is can only be used in mm, cm or m model units")
            return None

        point = rs.GetPoint('Select point')

        if point:
            pointZ = point.Z
        pointZ = pointZ * scale()
        rs.AddTextDot('+RL ' + str(round(pointZ, 3)), point)

        # Copy RL to Clipboard
        RL = str(round(pointZ, 3))
        rs.ClipboardText(RL)

    except:
        print("Failed to execute")
        rs.EnableRedraw(True)
        return
Пример #16
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)
Пример #17
0
def do_sierpinski_3d():
    """Prompts for a point. Draws a right-angled 3d sierpinski gasket 
    (combined before and after) at that point
    """
    message = 'Select the base point'
    base_point = rs.GetPoint(message)
    _draw_sierpinski_3d(base_point)
Пример #18
0
def align_dims():
    if not sc.doc.Views.ActiveView.ActiveViewport.CameraZ == Rhino.Geometry.Plane.WorldXY.ZAxis:
        print "this works only in top view (world XY)"
        return
    """
    align vertical dimensions horizontally or horizontal dimensions vertically
    version 1.0
    www.studiogijs.nl
    """

    dims = rs.GetObjects("select dims to align", preselect=True, filter=512)
    if not dims:
        return
    p_ref = rs.GetPoint("set basepoint for the dimensions", in_plane=True)
    if not p_ref:
        return
    p_ref = rs.coerce3dpoint(p_ref)

    dims = [rs.coercerhinoobject(dim) for dim in dims]
    for dim in dims:

        vertical = False
        horizontal = False
        rc, e1, e2, a1, a2, dp, tp = dim.Geometry.Get3dPoints()
        if not rc:
            return
        #check arrow endpoints to see if dim is vertical or horizontal
        if a1.Y == a2.Y: horizontal = True
        if a1.X == a2.X: vertical = True

        if not (horizontal or vertical): continue  #next dimension

        #make sure all points are set relative to e1
        #for SetLocations method we need positions of dimension
        #extension lines and text position
        tp -= e1
        p_r = p_ref - e1
        e2 -= e1
        if horizontal:
            #make 2dpoints for setting the new location
            #sometimes dimension plane is inverted
            #depending on where the endpoints wer picked
            px = dim.Geometry.Plane.XAxis.X  #plane x-axis is (1,0,0) or (-1,0,0)
            py = dim.Geometry.Plane.YAxis.Y  #plane y-axis is (0,1,0) or (0,-1,0)
            dp_new = Rhino.Geometry.Point2d(tp.X * px, p_r.Y * py)
            e1_new = Rhino.Geometry.Point2d(0, 0)
            e2_new = Rhino.Geometry.Point2d(e2.X * px, e2.Y * py)
        elif vertical:
            #make 2dpoints for setting the new location
            #notice that vertical dimensions have their plane rotated 90 degrees
            #sometimes dimension plane is inverted
            px = dim.Geometry.Plane.XAxis.Y  #plane x-axis is (0,-1,0) or (0,1,0)
            py = dim.Geometry.Plane.YAxis.X  #plane y-axis is (1,0,0) or (-1,0,0)
            dp_new = Rhino.Geometry.Point2d(tp.Y * px, p_r.X * py)
            e1_new = Rhino.Geometry.Point2d(0, 0)
            e2_new = Rhino.Geometry.Point2d(e2.Y * px, e2.X * py)
        #perform the move
        dim.Geometry.SetLocations(e1_new, e2_new, dp_new)
        dim.CommitChanges()
Пример #19
0
def cutPlate():
    center = rs.GetPoint("center point:")

    radius = 250

    circle = rs.AddCircle(center, radius)
    rs.AddPlanarSrf(circle)
    rs.DeleteObject(circle)
Пример #20
0
def RunCommand( is_interactive ):
    go = GetObject()
    go.SetCommandPrompt("Select objects to move randomly")
    go.GetMultiple(1, 0)
    objs = go.Objects() #stores objref
    
    if objs:
        start = rs.GetPoint("Point to move from")
        if start:
            end = rs.GetPoint("Point to move to")
            if end:
                translation = end-start
                for obj in objs:
                    rs.MoveObject(obj, translation * random.random())
    return 0

#RunCommand(True)
Пример #21
0
def RunCommand(is_interactive):
    ringSize = rs.GetReal("Ring size", 8.5, 0, 16)
    center = rs.GetPoint("Location")

    plane = rs.MovePlane(rs.ViewCPlane(), center)
    radius = (11.63 + 0.8128 * ringSize) * 0.5
    objId = rs.AddCircle(plane, radius)
    rs.SelectObject(objId)
Пример #22
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)
Пример #23
0
def main():
    objs = rs.GetObjects("Select objects to contour", preselect=True)
    if objs is None: return
    pt = rs.GetPoint("Select point to contour at")
    if objs is None: return
    rs.EnableRedraw(False)
    for obj in objs:
        contourPt(obj, pt)
    rs.EnableRedraw(True)
Пример #24
0
def RunCommand(is_interactive):
    global params

    center = rs.GetPoint(message="Select center point")

    n = rs.GetInteger(message="Number of teeth", number=params["n"], minimum=4)

    r = rs.GetReal(message="Outside Diameter", number=params["r"])

    m = rs.GetReal(message="Gear module", number=params["m"])

    pa = rs.GetReal(message="Pressure angle",
                    number=params["pa"],
                    minimum=0,
                    maximum=45)

    bool_opts = rs.GetBoolean(message="Output options",
                              items=(("PitchCircle", "No", "Yes"), ),
                              defaults=(params["pc"], ))

    if None in [center, n, m, pa, bool_opts]:
        return 1  # Cancel

    pc = bool_opts[0]

    params["n"] = n
    params["m"] = m
    params["r"] = r
    params["pa"] = pa
    params["pc"] = pc

    cplane = rs.ViewCPlane()  # Get current CPlane
    cplane = rs.MovePlane(cplane, center)
    xform = rs.XformChangeBasis(cplane, rs.WorldXYPlane())

    rs.EnableRedraw(False)
    old_plane = rs.ViewCPlane(plane=rs.WorldXYPlane())

    gear = generate_gear_crv_with_outside(teeth=params["n"],
                                          module=params["m"],
                                          outside_diam=params["r"],
                                          pressure_angle=params["pa"])

    rs.ViewCPlane(plane=old_plane)
    rs.TransformObjects(gear, xform)

    rs.EnableRedraw(True)

    if pc:
        circle = generate_pitch_circle_crv(teeth=params["n"],
                                           module=params["m"])
        rs.TransformObjects(circle, xform)
        rs.SelectObjects([gear, circle])
    else:
        rs.SelectObjects(gear)

    return 0  # Success
Пример #25
0
def GetDistance(first_pt=None,
                distance=None,
                first_pt_msg='First distance point',
                second_pt_msg='Second distance point'):
    """Pauses for user input of a distance.
    Parameters:
      first_pt [opt] = First distance point
      distance [opt] = Default distance
      first_pt_msg [opt] = Prompt for the first distance point
      second_pt_msg [opt] = Prompt for the second distance point
    Returns:
      The distance between the two points if successful.
      None if not successful, or on error.
    """
    if distance is not None and first_pt is None:
        raise Exception(
            "The 'first_pt' parameter needs a value if 'distance' is not None."
        )
    if distance is not None and not (isinstance(distance, int)
                                     or isinstance(distance, float)):
        return None
    if first_pt_msg is None or not isinstance(first_pt_msg, str): return None
    if second_pt_msg is None or not isinstance(second_pt_msg, str): return None

    if first_pt is not None:
        if first_pt == 0: first_pt = (0, 0, 0)
        first_pt = rhutil.coerce3dpoint(first_pt)
        if first_pt is None: return None

    if first_pt is None:
        first_pt = rhinoscriptsyntax.GetPoint(first_pt_msg)
        if first_pt is None: return None

    # cannot use rs.GetPoint for 2nd point because of the need do differentiate
    # between the user accepting none vs cancelling to exactly mimic RhinoScript
    gp = Rhino.Input.Custom.GetPoint()
    if distance is not None:
        gp.AcceptNothing(True)
        second_pt_msg = "{0}<{1}>".format(second_pt_msg, distance)
    gp.SetCommandPrompt(second_pt_msg)
    gp.DrawLineFromPoint(first_pt, True)
    gp.EnableDrawLineFromPoint(True)
    r = gp.Get()
    if r not in [
            Rhino.Input.GetResult.Cancel, Rhino.Input.GetResult.Point,
            Rhino.Input.GetResult.Nothing
    ]:
        return scriptcontext.errorHandler()
    if r == Rhino.Input.GetResult.Cancel: return None
    if r == Rhino.Input.GetResult.Point:
        second_pt = gp.Point()
        distance = second_pt.DistanceTo(first_pt)
    gp.Dispose()

    print "Distance: {0}".format(distance)
    return distance
Пример #26
0
def copyToOrigin(objs):

    #get left bottom
    selection_base = rs.GetPoint("Pick export base point")
    #box = rs.BoundingBox(objs)
    if selection_base:
        #selection_base = [box[0].X, box[0].Y, box[0].Z]
        vector = rs.VectorSubtract(selection_base, [0, 0, 0])

        return rs.CopyObjects(objs, rs.VectorReverse(vector))
Пример #27
0
 def player_move(self):
     """Player move"""
     while True:
         point = rs.GetPoint("{} turn".format(self.player_symbol))
         for i, j in self.get_possible_moves():
             p_x = point[0]
             p_y = point[1]
             g = self.grid[i][j]
             if g[0][0] <= p_x <= g[1][0] and \
                g[0][1] <= p_y <= g[1][1]:
                 return (i, j)
 def cylinders(self, num):
     a = rs.GetPoint("Enter start point")
     p = rs.AddPoint(a)
     h = rs.GetReal("Enter the height")
     for i in range(0, num):
         a.X = a.X + 4
         h = h + 5
         r = 2
         cylinder = rs.AddCylinder(a, h, r)
         color02 = [i * 3, i * 2, 255 - i * 6]  #magenta
         rs.ObjectColor(cylinder, color02)
Пример #29
0
def draw_lpoint():
    prompt_for_label = 'Enter the label'
    text = rs.GetString(prompt_for_label)
    prompt_for_point = 'Select the point'
    point = rs.GetPoint(prompt_for_point)
    height = 2
    lpoint = rs.AddText(text, point, height)
    radius = 0.5
    sphere = rs.AddSphere(point, radius)
    group = rs.AddGroup()
    rs.AddObjectsToGroup([lpoint, sphere], group)
Пример #30
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])