+ Reply to Thread
Results 1 to 4 of 4

Thread: points of a curve Vs GetObject (points) - data structure ?

  1. #1

    points of a curve Vs GetObject (points) - data structure ?

    Hi
    hope you can help me understand
    when i try to retrieve points of a curve using:

    Python Code:
      polyline_id = rs.GetObject("Select Polyline", 4, True, True)
      vertices = rs.PolylineVertices(polyline_id)
    i get this kind of output :
    <Rhino.Geometry.Point3d object at 0x0000000000000030 [0,0,0]>,...... (for each point)

    while using
    Python Code:
      pickPts = rs.GetObjects("Select Points:",1)
    the output is :
    <System.Guid object at 0x0000000000000035 [d4c2609e-74e0-40d0-8fb6-f332fa21f90a]>,...... (for each point)

    the end result should be a curve (following the Nurbs-curves exaple of the primer) but the first example data (rs.PolylineVertices) creates an error : Specified cast is not valid

    can i convert the data ? or, is there is a way to read bits of it somehow - i can see the coordinates are there... but i just can't reach...

    Thanks
    Tamir

  2. #2
    Super Moderator Mitch's Avatar
    Join Date
    May 2010
    Location
    Switzerland
    Posts
    285
    Hi,

    The important thing to distinguish here is between points in space (represented by x,y,z coordinates) and point *objects*, which are actually objects in the Rhino document - you can see them on the screen. Objects in the Rhino document are represented by a "name" - that is the object's GUID. A GUID looks like this: d31f4589-5b79-466a-96c2-2b5ff51eee27. It's what uniquely identifies the object in the file.

    So, in the first instance, you are getting an object that is in the document (a polyline) and then getting its vertices. The polyline will have a GUID because it exists in the document, but the vertices are not actually objects in the file, they are just points in space, in Python/RhinoCommon those are Point3D's. So rs.PolylineVertices() will return a list of Point3D's.

    In the second example you are getting a series of point *objects* with rs.GetObjects. They are also objects in the Rhino document, you see them on the screen, therefore you get their GUID's. GetObject or GetObjects will always return GUID's. In order to get the actual point coordinates of a point object or list of point objects, you will need to use rs.PointCoordinates() on the point objects, which will return their coordinates as a Point3D.

    However, as rs.PointCoordinates only works on one point at a time, so you will need to run a little loop to get all the point coordinates of pickPts.
    Python Code:
      ptCoords=[]
      for pt in pickPts: ptCoords.append(rs.PointCoordinates(pt))
       
      #Or, if you want to use a little trick, you can run a list comprehension to compact it to all one line:
      ptCoords=[rs.PointCoordinates(pt)for pt in pickPts]
    Does the above make sense?

    --Mitch
    Last edited by Mitch; 05-21-2012 at 02:37 PM. Reason: spelling, clarity

  3. #3
    Hi Mitch
    Thanks for the quick response, it made a lot of sense
    I wonder if there is a way to just extract pieces of the Point3D or GUID string
    Thanks
    Tamir

  4. #4
    Super Moderator Mitch's Avatar
    Join Date
    May 2010
    Location
    Switzerland
    Posts
    285
    I wonder if there is a way to just extract pieces of the Point3D or GUID string
    Sure...
    If you have Point3D objects (that is Python objects, not document objects), they have attributes and some of those are the coordinates X, Y, and Z that the Point3D has. You get at them simply as you do with most object attributes - you need a little RhinoCommon:
    Python Code:
      ptObj=rs.GetObject("Select point object",1)
      pt=rs.PointCoordinates(ptObj)
      xCoord=pt.X
      yCoord=pt.Y
      zCoord=pt.Z
      print xCoord, yCoord, zCoord

    For getting at a piece of a GUID (I don't know why you want to do that) or the whole thing, you can just do the following:
    Python Code:
      ptObj=rs.GetObject("Select point object",1)
      gString=str(ptObj)
    That turns it into a string, then you can use all the usual Python string manipulation techniques to extract what you want.

    --Mitch

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts