# Intro to Python Scripting: 21 Polygon Class Pt2

Software:
Video Duration:
10 minutes
Author:
Zach Downey

In this tutorial we clean up our polygon python class a bit and make it a little more user friendly by changing the initialization/constructor method to include a user provided centerpoint. This means we need to rewrite the code a bit and we also need to pass a new origin parameter when we instantiate our class.

```import rhinoscriptsyntax as rs
import math

#class definition
class MyPolygon:
#polygon initialization or constructor method
self.sides = sides
self.origin = origin
origin = self.origin
theta = (2*math.pi)/self.sides
x = origin + self.radius
y = origin
z = origin
pts = []
pts.append(pt01)
degrees = theta*(180/math.pi)
for i in range(1,self.sides):
tempPt = pts[-1]
newPt = rs.RotateObject(tempPt,origin,degrees,None,True)
pts.append(newPt)
pts.append(pt01)

def fillPolygon(self):

def extrudePolygon(self,height):
startPt = self.origin;
newZ = self.origin+height
endPt = [self.origin,self.origin,newZ]
return rs.ExtrudeCurveStraight(self.polygon, startPt, endPt)

userpt = rs.GetPoint("Pick a centerpoint")
polygon0 = MyPolygon(6,6,userpt)
polygon0.fillPolygon()
polygon0.extrudePolygon(5)

userpt = rs.GetPoint("Pick a centerpoint")
polygon1 = MyPolygon(8,12,userpt)
polygon1.fillPolygon()
polygon1.extrudePolygon(10)```

### Rating

Please rate this tutorial below. Thanks.