Rhinopython report error

Hi guys, I am a beginner of rhino python.
I tried to use python to generate a polygon, but the script didn’t work well and report the following error.I have no idea which part of my script wrong. Could someone tell me how to solve the problem?

Runtime error (ValueErrorException): Could not convert a9ae2f78-a453-43f8-866f-8fb7621657c2 to a list of points

Here is my file:fenxing.py (542 Bytes)

Hi @jujudebuguilu,

On line 21, you call rs.AddPoints(vertices[i]), which - if you take a look at the documentation -, expects a list of points, but you pass in a single GUID from your vertices list.
Instead of storing the vertices as GUIDs, you could store each one as simple list(x, y, z) or tuple(x, y, z). You should also call rs.AddPoint() instead, since you only pass in a single point.

If you want to read more about my opinion on GUIDs vs. geometry objects, check out this post of mine from a few hours ago:


1 Like

Hi @diff-arch,

Thank you for your reply!I know the problem I have now.
I checked the link you shared, and have some new questions about rhinoscriptsyntax and rhinocommon:

  1. Based on my understanding, the data type generated by rhinoscriptsyntax is GUID, and the type generated by rhinocommon is geometry itself. Is that correct? What’s the different of in rhinocommon and rhinoscriptsyntax?
    2.Are there some methods can convert GUID type into geometry itself?
    3.I check the documentation, there are not python code in rhinocommon API. Whether there are some place I can find the rhinocommon documentation for python?


This post contains lots of useful info, tips and links…


Yes, in rhinocommon, geometry objects are created. This has to do with the intricacies of object-oriented programming, where you have classes as blueprints and objects as class instances. Imagine the class being the blueprint of a chocolate factory and the object or class instance as the built factory itself. The class documents how to construct the object so to speak.
rhinoscriptsyntax is a wrapper for rhinocommon, meaning that each of its functions executes rhinocommon code in the background. You can inspect the source code like this:

import rhinoscriptsyntax as rs
import inspect

print inspect.getsource("rs.AddPoint")  # outputs the source code of this function

rhinoscriptsyntax was meant to make Python scripting in Rhino easier, but it’s debatable if that strategy really came to fruit, especially because every beginner, me included, is always confused about GUIDs. :slight_smile:
Now, I don’t know if this is 100% how this really works, but I imagine that GUIDs are like adresses that point to where the geometry in question is stored in your computers memory. This probably has to do with memory management and stuff like that.

Yes, you can for instance use rs.coercebrep(guid) to get the brep in question. There are also others, but I believe these functions are not documented, because they are probably not meant to be used.
Simply don’t mix rhinocommon and rhinoscriptsyntax and you probably won’t have to deal with coercing.

It’s C# code, but you can mostly treat it like Python. You’re probably not accustomed to what you see because you don’t understand classes yet.
Your code above in rhinocommon could look something like this:

import Rhino.Geometry as rg
import math

def generate_polygon(point, radius, segments):
    polyline = rg.Polyline()  # construct a Polyline object
    angle = (2 * math.pi) / segments  # angle in radians
    vector = rg.Vector3d.XAxis * radius  # construct a Vector3d object
    for _ in range(segments):
        vector.Rotate(angle, rg.Vector3d.ZAxis)  # rotate the existing Vector3d object
        polyline.Add(point + vector)  # add a point to the existing Polyline object
    return rg.PolylineCurve(polyline)  # construct a PolylineCurve object from the Polyline object and return it

# Output
a = generate_polygon(rg.Point3d.Origin, 12.0, 5)  

Try it! :wink:


Also note that the Polyline class already has several methods for generating polygons, all taking a Circle as their geometry input: