import rhinoscriptsyntax as rs
import math
class MyPolygon:
def __init__(self, radius, sides):
self.radius = radius
self.sides = sides
#variable theta
theta = (2 *math.pi)/self.sides
pt01 = rs.AddPoint(self.radius,0,0)
pts = []
pts.append(pt01)
self.origin = [0,0,0]
#radians to degrees
degree = theta*(180/math.pi)
#rotate object method i need a loop
for i in range (1,self.sides):
tempPt = pts[-1]#it will give me the last item form an array
newPt = rs.RotateObject(tempPt, self.origin, degree, None, True)
pts.append(newPt)
pts.append(pt01)
self.polygon = rs.PolylineVertices(tempPt)
polygon1 = MyPolygon(5,5)

I am getting following error message:

Message: unable to convert 8de8acb9-2bf3-4f90-a848-c03254349161 into Curve geometry

Traceback:
line 567, in coercecurve, â€śC:\Users\Kuldeep\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript\utility.pyâ€ť
line 2317, in PolylineVertices, â€śC:\Users\Kuldeep\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript\curve.pyâ€ť
line 23, in init, â€śE:\Digital Media Master\3rd Semester\Rhino Exercises\Polygon.pyâ€ť
line 24, in , â€śE:\Digital Media Master\3rd Semester\Rhino Exercises\Polygon.pyâ€ť

Youâ€™re might be thinking that that will add a polyline, but it only gets vertices from an existing one.

I changed your class around a bit, see if the following makes sense. Instead of adding Rhino point objects to the document, I use 3Dpoints which only exist â€śvirtuallyâ€ť. I have to leave for an hour now, but I can explain more later.

import rhinoscriptsyntax as rs
import Rhino
import math
class MyPolygon:
def __init__(self, radius, sides):
self.radius = radius
self.sides = sides
#variable theta
theta = (2 *math.pi)/self.sides
self.origin = rs.coerce3dpoint([0,0,0])
#radians to degrees
degree = theta*(180/math.pi)
#create a 3dpoint object (not a Rhino point in the document)
pt01 = rs.coerce3dpoint([self.radius,0,0])
#empty list
pts = []
#need a rotation axis (World Z axis)
zvec=rs.coerce3dvector([0,0,1])
#run your rotate loop
for i in range (self.sides):
#create a rotation transform with the correct rotation from original
xform=rs.XformRotation2(degree*i,zvec,self.origin)
#transform the original 3d point, add to list
pts.append(rs.PointTransform(pt01,xform))
#add first point again to close polyline
pts.append(pt01)
#add the polyline
self.polygon = rs.AddPolyline(pts)
polygon1 = MyPolygon(5,5)

rs.coerce3dpoint() tries to create a RhinoCommon â€śPoint3d objectâ€ť from a list of 3 numbers. This Point3d object represents a point in world 3d space (coordinates) but does not actually add a visible point object to the Rhino document - in this case you do not need or want that.

Once you have this initial Point3d object you can manipulate it with various rhinoscript and RhinoCommon methods. You cannot rotate it directly with rs.RotateObject() because that method only acts on objects already in the document - represented by their GUID. The easiest way to rotate it then is to create a rotation transformation with rhinoscriptsyntax and then apply it to the object (I know this is a bit abstract, but itâ€™s pretty common way of working).

This rotation transformation needs a center point, an angle (in degrees), and an axis direction about which to rotate - think 3D here. The axis direction is a vector which points along the direction of the axis, and that will be applied at the rotation center point. In this case, as we are working from the Top view, I fixed the axis direction as the world Z axis, thus the vector is (0,0,1). I used rs.coerce3dvector() in exactly the same way as rs.coerce3dpoint() and it creates a RhinoCommon Vector3d objectâ€¦

Then the loop takes care of the rest, we rotate the original point by i times the angle increment at every iteration, and put a copy into the point list.

Hello @Helvetosaur, what if I donâ€™t want to the center of the polygon to be [0,0,0] but any 3d point in space? I tried changing the origin, but the length of the sides changed.