Grasshopper

algorithmic modeling for Rhino

Dear gh joda,

I'm new to ghpython and have a hard time to wrap my head around a type hint issue I was experiencing. Attached a script in two versions of type hint, first works fine until you decide to delete one of its input points, it'll spit out a None Type.

I found some threads which actually confused me even more

http://www.grasshopper3d.com/forum/topics/incremental-addition-of-v...

http://www.grasshopper3d.com/forum/topics/python-and-ghpython-problems

I guess my questions would be:

- how to write a conditional for non-types

- what actually does ghdoc type hint

- how to convert guids to geometry (in order to access their variables)

- rhinoscriptsyntax vs. rhino common sdk

- where can I find resources to understand that mess

Feel free to enlighten me :)

Views: 1368

Attachments:

Replies to This Discussion

Hi Tom,

thanks for your magical powers and taking time to help me out on this.

I guess these are all typical beginners questions, however couldn't find a nice overview which clarifies this.

Is it common practice to stick to rhinocommon classes?

Can you clarify the difference between rhinocommon and rhinoscript, for which purpose they were designed?

Cheers,

Patrick

Hi guys,

I am sorry, while the content of what Tom says is absolutely correct for the RhinoCommon part, I find the suggestion not to use rhinoscript not helpful for a beginner.

Rhinoscript is a comprehensive library that contains easy and thought-out functions (for the vast part, not written by me) that work with geometry IDs. It is rare that something as easy as averaging points cannot be written in rhinoscript. Rhinoscript is based on RhinoCommon (with others, I wrote larger chunks of this library), a C# library. C# has no access to rhinoscript.

For this or other reasons, sometimes C# developers like RhinoCommon methods more than rhinoscript functions. This is a personal preference and should not justify using one or the other library. You can see the GhPython Help from the context menu of any GhPython component about type Hints. It covers most of these basic concepts.

When dealing with geometry IDs (Guid types), you can use rhinoscript methods that tell apart different entities. For example, rs.IsPoint(ID) will determine if the ID corresponds to a point in the document.

rs.PointCoordinates(ID) takes the ID of a point and returns a Point3d element that allows access to the X, Y, Z coordinates. For example:

coords = rs.PointCoordinates(ID)
X = coords[0] # also .X works

In addition, in Python, heavily relying on type checking is frowned upon, because it prohibits duck typing. Duck typing allows to use types interchangeably in dynamic languages.

I modified the script that you posted so that it also works also with rhinoscriptsyntax. It's just one line difference, but conceptually shows where to use rs functions. Have a look and please let us know if you have more questions.

Attachments:

I still want to thank Tom for the help here.

Thanks, your words are appreciated; just like the great answers you always give.

Thanks so much for your input!

Could you also write the same script with utilizing only rhinocommon?

At the end of this day, I might get the difference :)

Yeah Tom, thanks! You earned yourself a beer on my behalf at the upcoming user meeting in Berlin.

Just a tiny addendum to Tom and Giulio's post: You can look up the source code of rhinoscriptsyntax to learn how it is structured and how RhinoCommon is implemented within it using IronPython directly on your hard drive. Somewhere around here:

C:\Users\YourUserName\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript.

I would also recommend browsing through the new neat Rhino Developer Docs which have several relevant pages on these subjects.

And pandora's box just popped open. Cheers!

Just a word of caution about  Rhino Developer Docs. It's really new. It might still be rough around the edges.

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service