Getting Point coordinates [python]

That’s cool! :slight_smile:

Hi all @Helvetosaur @ivelin.peychev @Willem @jesterking , I wrote this code to get the X coordinate of the point in GH Python, but instead of I am getting an error. I have used this method earlier, but it seems to be not working here. Why? Any solutions or tips? Please. Thanks in advance.

The code is below,

c = rs.AddPoint(300,50,0)
print c.X

Error is,

Runtime error (MissingMemberException): ‘Guid’ object has no attribute ‘X’

Traceback:
line 44, in script

c will be the GUID of the point object you created using AddPoint(), not the point coordinates. Outside of GH you would need to use something like pt=rs.coerce3dpoint(c) to get the point3d object, which would then work with pt.X to get you the X coordinate.

Many people use AddPoint() incorrectly, it’s only designed for adding a point object to the Rhino document and returning its GUID, and many times you don’t need to do that, you just need the real point3d object which has coordinates as part of its properties.

You are working in GH? What is the input in this case?

2 Likes

Hi, @Helvetosaur thanks for the quick reply. I am working with GH. I am generating the points as a list, and try to get the X coordinates from them, only while I call it with an if function. rs.CreatePoint(x,y,z) worked. Thanks.

Could you expand on the right method to use then? Say, I want to create points using a loop and connect them later with a line? No need to draw the points individually.

Do you have any resources on getting the basics of geometry in Rhino Python (not GH). I am learning, but spending soooo much time on searching online for even the most basic answers to drawing simple geometry. Sorry, but the 101 is not much help to a beginner…

There are two ways to create a 3d point object:

  1. rhinoscriptsyntax
    pt=rs.coerce3dpoint([x,y,z])

  2. RhinoCommon
    pt=Rhino.Geometry.Point3d(x,y,z)

import rhinoscriptsyntax as rs

point_list=[]
for i in range(10):
    #create a 3d point
    pt=rs.coerce3dpoint([5*i,i**2,0])
    #append it to the list
    point_list.append(pt)
#add polyline
rs.AddPolyline(point_list)

or maybe to make a segmented circle with 24 points…

import rhinoscriptsyntax as rs
import math

rad=10.0
count=24
inc=2*math.pi/count  #math functions work in radians, 2*pi is full circle
point_list=[]
#circle parametric formula
for i in range(count):
    x=math.sin(i*inc)*rad
    y=math.cos(i*inc)*rad
    #create your 3d point
    pt=rs.coerce3dpoint([x,y,0])
    #append it to the list
    point_list.append(pt)
#add first point to end of list (to close circular polyline)
point_list.append(point_list[0])
#add polyline
rs.AddPolyline(point_list)

Thank you!!!