View RSS Feed

Dale Fugier

My First RhinoPython Script

Rate this Entry
I know this is kinda cheezy, since I use the RhinoScript syntax. But hey! gotta start somewhere...


Python Code:
    ###############################################################################
    # ArchimedeanSpiral.py -- July 2011
    # If this code works, it was written by Dale Fugier.
    # If not, I don't know who wrote it.
    #
    # Change 'a_const' to turn the spiral.
    # Change 'b_const' to control the distance between turnings.
     
    import rhinoscriptsyntax as rs
     
    def ArchimedeanSpiral():
       
        print "Archimedean Spiral: Radius = A + B * Theta"
       
        a_const = rs.GetReal("Value of A constant", 1.0, 0.01)
        if a_const is None: return
       
        b_const = rs.GetReal("Value of B constant", 1.0, 0.01)
        if b_const is None: return
       
        num_points = rs.GetInteger("Number of points to calculate", 10, 1)
        if num_points is None: return
       
        step_angle = rs.GetReal("Angle between points"30.0, 1.0, 45.0)
        if step_angle is None: return
       
        curr_angle = 0.0
        base_point = [0.0, 0.0, 0.0]
        points = []
       
        for i in xrange(0, num_points):
               radius = a_const + (b_const * curr_angle)
               pt = rs.Polar(base_point, radius, curr_angle)
               points.append(pt)
               curr_angle = curr_angle + step_angle
       
        rs.AddInterpCurve(points)
     
    ##########################################################################
    # Check to see if this file is being executed as the "main" python
    # script instead of being used as a module by some other python script
    # This allows us to use the module which ever way we want.
    if( __name__ == "__main__" ):
        ArchimedeanSpiral()

Enjoy!

Updated 07-26-2011 at 05:43 AM by Steve Baer

Tags: None Add / Edit Tags
Categories
RhinoScript , RhinoPython

Comments