GHPython Type Casting

General Question Here:

What is the best ways to type cast (between GUID and Curve for example) to use built in rhinoscriptsyntax and RhinoCommon components that require these different type inputs in the same script?

an example of this is aligning a set of curves, flipping them based on direction and performing more operations.

based on my scraping of the API references on RhinoDeveloperDocs, it seems like things like “rs.ReverseCurve” “rs.CurveClosestPoint” “rs.CurveSeam” and “rs.CurvePerpFrame” take either a curve or a GUID input, but are not consistent.

does this mean you have to create different scripts to handle each operation and type cast with your inputs into the ghpython component itself. There must be a better way!

any help is appreciated!

-H

Yes, only use RhinoCommon in the context of GHPython. rhinoscriptsyntax is primarily meant for Rhino.

1 Like

Hm, I would like to figure out another way so would be possible to leverage all the useful functions and tools in both libraries.

The guid you refer to is part of a RhinoObject instance. This wraps a geometrical instance in the RhinoDocument to uniquely identify it there. In Grasshopper they don’t exist in this document until you „bake“ it. So there are no GUIDs to work with. RS wraps RC so there nothing you could also achieve by using RC. In Rhino you can „cast“ inbetween by using the RS coerce methods. Its called coercing and not casting because you are not just redeclaring the type but finding a geometrical instance by id. Note that casting is not a type conversion, its a reinterpretation of bytes.

2 Likes

Thanks TomTom thats a really informative way of thinking about this problem. i will look into coercing methods for my problem going forward.

Again, this only works for Grasshopper if your geometry is already (“baked”) in the RhinoDocument. If it’s raw geometry created in Grasshopper, then there will be no way of modifying geometry using rhinoscriptsyntax with a GUID.

You’re not missing out by “only” using RhinoCommon. rhinoscriptsyntax is simply a wrapper around RhinoCommon functionality. You can inspect its source code to learn which RhinoCommon classes/methods it implements:

1 Like

Thanks Tom Tom, I’m new to scripting components using RhinoCommon, etc, so this insight is super helpful to understand how these work.

Thank you Anders, great links i will peruse. I will probably continue to have questions going forward regarding scripting RhinoCommon components so its always great to have a robust community that supports new people.

1 Like