# # Name: create_a_grid.py # Description: Script that creates instructions to # generate a grid of closed polylines # based on a larger rectangle. # Author: Mike Warren # Date Created: 10/10/2013 # Last Modified: 10/11/2013 # # gather rectangle parameters width = float(raw_input("Enter rectangle width: ")) height = float(raw_input("Enter rectangle height: ")) columns = int(raw_input("Enter number of columns: ")) rows = int(raw_input("Enter number of rows: ")) # calculate grid dimensions grid_width = width / columns grid_height = height / rows # user feedback print "\nOverall width = " + str(width) print "Overall height = " + str(height) print "Generate " + str(columns) + " columns" print "Generate " + str(rows) + " rows" print "\nColumn width = " + str(float(width / columns)) print "Row height = " + str(float(height / rows)) print "Number of grids = " + str(columns * rows) # create two new lists based on provided input xlist = [] # empty list xcount = 0 while xcount <= columns: xlist.append(xcount * grid_width) xcount += 1 ylist = [] ycount = 0 while ycount <= rows: ylist.append(ycount * grid_height) ycount += 1 # user feedback print "\nX list: " + str(xlist) print "Y list: " + str(ylist) print "\n" # create a set of coordinates using the x and y lists # for the lower-left corners y_origin = 0 while y_origin < (len(ylist)-1): # length-1 since 1st index is 0 x_origin = 0 while x_origin < (len(xlist)-1): print "PLINE" # to invoke an AutoCAD function print str(xlist[x_origin]) + "," + \ str(ylist[y_origin]) # LL Corner print str(xlist[x_origin] + grid_width) + \ "," + str(ylist[y_origin]) # LR Corner print str(xlist[x_origin] + grid_width) + \ "," + str(ylist[y_origin] + grid_height) # UR Corner print str(xlist[x_origin]) + "," + \ str(ylist[y_origin] + grid_height) # UL Corner print "C" # force closure of the polyline x_origin += 1 y_origin += 1 print "\nDone!!" # display final instructions print "\n1. Highlight from the first 'PLINE' to the last 'C'" print "2. Paste the contents into Notepad" print "3. Save the file with a .scr extension" print "4. Run it in AutoCAD using the SCRIPT command" print "5. Move the resulting grid of closed polylines if necessary\n"