+ Reply to Thread
Results 1 to 8 of 8

Thread: 7 questions other new Rhino.Python users might have like me

  1. #1

    7 questions with answer for new Rhino.Python users

    Hi all,

    like most of the people on this forum, I'm new to Rhino.Python and I'm posting some of the questions (with some answers I found so far) that were puzzling me when transitioning from RhinoScript to Rhino.Python.

    0. What’s the RhinoScript package and where is it?
    It’s a series of Python functions that mimic the procedural programming style found in RhinoScript, the scripting language that is available in Rhino v4 and previous&future Windows versions of Rhino and is based on vbScript. I could find the Python source code of the RhinoScript package in
    • C:\Documents and Settings\#my-name#\Application Data\McNeel\Rhinoceros\5.0\IronPython\lib\rhinoscr ipt (on winXP)
    • /Library/Application Support/McNeel/Rhinoceros/MacPlugIns/IronPython/settings/rhinoscript/lib/ (on Mac)
    • C:\Users\#my-name#\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript (on Vista/7)

    1. How do I reference a Rhino point with the RhinoScript package?
    The point entity in the Rhino document is linked with a Guid (a globally unique identifier of the point inside the document) in the RhinoScript package. Similarly as its precursor, generally RhinoScript uses Guids (in this case, System.Guid and not text any longer as in vbScript) all the time to reference all geometric entities in the document.
    Python Code:
      import rhinoscriptsyntax as rs
       
      ptId = rs.GetObject("Please select point", rs.filter.point)
      if ptId:
          coords = rs.PointCoordinates(ptId)
          print(coords)

    2. Ok, then what does coords in the example above contain now?
    coords above is a RhinoCommon object, a Point3d. It’s a Rhino.Geometry.Point3d type to be precise. The same happens to almost every type: for a line RhinoCommon uses the Rhino.Geometry.Line type, and RhinoScript simply normally uses Guids to a line in the document.
    To gain access to the RhinoCommon object linked by Guid, you can use the rs.coerceXXX(ID) functions.

    3. How can I print the x coordinate of a point that is not in the document using RhinoCommon?
    Python Code:
      from Rhino.Input import GetResult
      from Rhino.Input.Custom import GetPoint
       
      getter = GetPoint() #calls the constructor of GetPoint
      try:
          getter.SetCommandPrompt("Please select a point")
          if getter.Get() == GetResult.Point: #we wait for the result here
              pt = getter.Point()
              print("x coordinate: %.5f" % (pt[0], ) ) #float formatting 5 digits
       
      finally:
          getter.Dispose() #this will be called in all cases
       

    4. The “command wizard” doesn’t work?
    The command wizard is a great feature. The idea behind it is to write scripts that are automatically converted in runnable command aliases. Too bad, at first it seems not to be working! It is actually working, but it needs a couple of actions to make it functional after the script is completed:
    • Save the file (name is *_cmd.py)
    • Restart Rhino
    • Run the _EditPythonScript command
    • The alias is now in the Rhino command bar
    • Rhino.Python keeps track of the name of the file, not the name written after “__commandname__” in the file itself
    • You can find all IronPython command writing “IronPython.” in the toolbar

    5. In which folder do I need to put commands?
    The folder where Rhino looks for *_cmd.py files is:
    Code:
    C:\Documents and Settings\#my-name-here#\Application Data\McNeel\Rhinoceros\5.0\Plug-ins\PythonPlugins\ (on winXP)
    \Library\Application Support\McNeel\Rhinoceros\MacPlugIns\PythonPlugIns\#my-name-here#\dev (on Mac)
    See this great discussion: http://python.rhino3d.com/threads/27-Add-a-command about the Mac setup.

    6. What book can I read to learn the Python syntax and style?
    I personally think the books on Python that are going to be most relevant for Rhino.Python are the ones that are also taking into account the *Iron* prefix. I’ve only read IronPython in Action so far and I liked it, even if sometimes I found it a bit too ardent at the expense of objectiveness. Do you have other suggestions?

    If you have any additional trick, book suggestions, advice for new users, comments etc., I'd be glad if you reply down here or start a new conversation!
    Have a good start,

    - Giulio
    ___________________
    giulio@mcneel.com
    McNeel Europe, Barcelona
    Last edited by Giulio Piacentino; 05-18-2012 at 10:22 PM.

  2. #2
    Ciao Giulio
    Finalmente anche tu inizi a utilizzare IronPython. Sono certo che riuscirai a dare utili consgli.
    Ciao Vittorio

  3. #3
    Senior Member Steve Baer's Avatar
    Join Date
    Apr 2010
    Location
    Seattle
    Posts
    1,472
    Blog Entries
    19
    Thanks Giulio. Nice that you start with a 0 based numbering system; you must be a programmer

  4. #4
    Hi Giulio,

    About Python resources, I use the following:

    - The python documentation: very precise and to the point (http://docs.python.org/) - There is a link to it from the Rhino Python Editor
    - Python Programming: An introduction to computer science - easy to read through
    - Python, pocket reference - nice quick syntax reference
    - Learning Python.

  5. #5
    Hi Rajaa,

    Can you please edit your last post to include links to the books you mentioned?
    - Brian Gillespie
    Rhinoceros Development | Robert McNeel & Associates | Seattle, WA, USA

  6. #6
    Hi all,
    I've just added the RhinoScript library folder for mac following this thread: http://python.rhino3d.com/threads/44-CopyObject-error .

    @Vittorio: grazie sto imparando anche io. Per adesso mi piace molto!
    @Steve: when I saw the forum at first I thought: why isn't page numbering following Python convention?
    @Rajaa: thank you for your suggestions. I also have the Python pocket reference, it's handy. Is "Python Programming: An introduction to computer science" having some geometric example? From the title it looks promising.

    - Giulio
    ___________________
    giulio@mcneel.com
    McNeel Europe, Barcelona

  7. #7
    I have two of Rajaa's recommendations, and one to add.

    Python Programming: An Introduction to Computer Science is a great intro book for people who do not have programming experience. It introduces the concepts of object-oriented programming using python. It's not much of a reference, but it's excellent for beginners. It has some REALLY BASIC geometry examples, when it is introducing the concept of classes.

    Python Pocket Reference is really helpful especially if you already know some python, but want to get some quick tips about syntax and stuff in depth. I read this on my iphone on the bus, you can download it as an app.

    Programming Python is huge and amazing and covers so much good stuff it is just absurd. It goes through the built in libraries in depth, and shows you how take advantage of the os and sys modules (cross platform command-line scripting and file management!!) how to do web programming, create and use databases, and all sorts of good stuff.
    Last edited by BenjaminGolder; 02-24-2011 at 05:30 AM.

  8. #8
    This is probably the best book from which to learn python. This stack overflow question also has some fantastic advice on getting started.

+ Reply to Thread

Tags for this 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