+ Reply to Thread
Page 1 of 2
1 2 LastLast
Results 1 to 10 of 11

Thread: python grasshopper get coordinates

  1. #1

    python grasshopper get coordinates

    hi all,

    how can i check out the coordinates of an input point. ?

    thy !

  2. #2
    Hi pyrit
    coord=Rs.PointCoordinates(idpoint)
    Ciao Vittorio

  3. #3
    ciao vittorio,

    thx for the answer.
    i do not really understand why in python its that kind of complicated for my understanding.

    what would be the equivalent to the c#
    A = pt.X;

    because with the python
    coord=Rs.PointCoordinates(idpoint)
    which gives an array of the xyz values.

    im thinking about learning c#or/and python, python is somehow nice and easy with all the datatypoe stuff, but the above described makes me wonder ...

    could anyone tell me why these concepts seem to differ so ?
    thx !

  4. #4
    Super Moderator Mitch's Avatar
    Join Date
    May 2010
    Location
    Switzerland
    Posts
    288
    Vittorio has given you the rhinoscriptsyntax method, which is an adapatation of a simplified scripting language for Rhino into Python. You may also use RhinoCommon in Python which is lower level. If your input point "pt" is a Rhino point3D object, it will have properties .X, .Y, and .Z as in pt.X (like your C# example) and you can use those.

    In general RhinoCommon, being lower level, is more complicated than the Rhinoscriptsyntax, but also more powerful. You can decide which is best for you, you can also mix the two.

    http://www.rhino3d.com/5/rhinocommon/
    http://www.rhino3d.com/5/ironpython/index.html

    --Mitch

  5. #5
    thanks for pointing that out !

  6. #6
    What would you recommend to start with ?
    i assume that methods in rhinocommon also apply to c# ?
    why is the rc more complicated to use ?

    thanks for helpin

  7. #7
    Hi pyrit
    The following example shows the difference between id_point and Point3D:

    Python Code:
      import rhinoscriptsyntax as rs
      idp=rs.GetObject("select point",1)#the point is an object point
      print "idp=",idp
      if idp!=None:
          coord_idp=rs.PointCoordinates(idp)
          print "coord0 ",coord_idp
          print coord_idp[0]
       
      p=rs.GetPoint("get point")
      print "point coordinates=",p
      print p.X

    Ciao Vittorio
    Last edited by vittorio; 07-17-2012 at 02:12 PM.

  8. #8
    Senior Member Steve Baer's Avatar
    Join Date
    Apr 2010
    Location
    Seattle
    Posts
    1,464
    Blog Entries
    19
    Quote Originally Posted by pyrit View Post
    What would you recommend to start with ?
    If you are asking which programming language to start with, everyone is going to recommend something different. If you have done some scripting in the past with RhinoScript, the python should be a nice next step. All of the languages are just as powerful as each other, it just takes getting used to the syntax.

    Quote Originally Posted by pyrit View Post
    i assume that methods in rhinocommon also apply to c# ?
    That is true. Python, C#, and VB.NET all have full access to the RhinoCommon SDK when running inside of Rhino

    Quote Originally Posted by pyrit View Post
    why is the rc more complicated to use ?
    RhinoCommon is a bit more complicated to use than the rhinoscriptsyntax library since you need to learn more low-level details to get anything done. The nice thing about rhinoscriptsyntax is that it is built on top of RhinoCommon so you can look at functions in the library to figure out how to make things work in RhinoCommon. The library is simply a higher level set of functions that make a bunch of calls into RhinoCommon to get something done.

    Hope that helps,
    -Steve

  9. #9
    hi guys,

    i think python is a good choice, especially because also some nice opensource programms are written with it...

    Code:
    p=rs.GetPoint("get point")
    print "point coordinates=",p
    print p.X
    that goes well with python script editor

    how can i do this with an input point from gh.
    with my example c# i can do it.

    if i try with python
    Code:
    import math
    import rhinoscriptsyntax as rs
    
    a = pt.X
    it gives
    0. Runtime error (MissingMemberException): 'Guid' object has no attribute 'X'
    1. Traceback: ine 5, in script

  10. #10
    Super Moderator Mitch's Avatar
    Join Date
    May 2010
    Location
    Switzerland
    Posts
    288
    Hi,
    I think this is because GH treats points as if they are all point objects with a GUID - all the components which output a point, are actually outputting a GUID (despite the fact that you see the point coordinates in a panel if you connect one)... at least that's my theory.

    So, the following works (assume you have a point being input to an input called "pt"):
    python Code:
      import rhinoscriptsyntax as rs
      #pt.X <-- will error out, but:
      ptc=rs.coerce3dpoint(pt)
      print ptc.X
      #works
       

    So I actually had to coerce the point object ID input to a point3D object by using rs.coerce3dpoint
    --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