# GHPython Type Casting

**URL:** <https://discourse.mcneel.com/t/ghpython-type-casting/141705>\
**Category:** Grasshopper\
**Tags:** windows, mac, python, rhino7\
**Created:** [April 26, 2022, 4:16pm UTC](https://discourse.mcneel.com/t/ghpython-type-casting/141705 "2022-04-26T16:16:16Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hamilton\_Forsythe](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/hamilton_forsythe/32/671579_2.png) [@Hamilton\_Forsythe](https://discourse.mcneel.com/u/Hamilton_Forsythe)\
**Post date:** [April 26, 2022, 4:16pm UTC](https://discourse.mcneel.com/t/ghpython-type-casting/141705/1 "2022-04-26T16:16:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![diff-arch](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/diff-arch/32/528268_2.png) [@diff-arch](https://discourse.mcneel.com/u/diff-arch)\
**Post date:** [April 26, 2022, 5:00pm UTC](https://discourse.mcneel.com/t/ghpython-type-casting/141705/2 "2022-04-26T17:00:53Z")

</div>

> [@Hamilton\_Forsythe](#):
>
> There must be a better way!

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

---

<div class="post-metadata">

**Author:** ![Hamilton\_Forsythe](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/hamilton_forsythe/32/671579_2.png) [@Hamilton\_Forsythe](https://discourse.mcneel.com/u/Hamilton_Forsythe)\
**Post date:** [April 26, 2022, 5:41pm UTC](https://discourse.mcneel.com/t/ghpython-type-casting/141705/3 "2022-04-26T17:41:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![TomTom](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/tomtom/32/651939_2.png) [@TomTom](https://discourse.mcneel.com/u/TomTom)\
**Post date:** [April 27, 2022, 5:25am UTC](https://discourse.mcneel.com/t/ghpython-type-casting/141705/4 "2022-04-27T05:25:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Hamilton\_Forsythe](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/hamilton_forsythe/32/671579_2.png) [@Hamilton\_Forsythe](https://discourse.mcneel.com/u/Hamilton_Forsythe)\
**Post date:** [April 27, 2022, 7:27pm UTC](https://discourse.mcneel.com/t/ghpython-type-casting/141705/5 "2022-04-27T19:27:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![TomTom](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/tomtom/32/651939_2.png) [@TomTom](https://discourse.mcneel.com/u/TomTom)\
**Post date:** [April 28, 2022, 6:17am UTC](https://discourse.mcneel.com/t/ghpython-type-casting/141705/6 "2022-04-28T06:17:37Z")

</div>

> [@Hamilton\_Forsythe](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![AndersDeleuran](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/andersdeleuran/32/476683_2.png) [@AndersDeleuran](https://discourse.mcneel.com/u/AndersDeleuran)\
**Post date:** [April 28, 2022, 8:04am UTC](https://discourse.mcneel.com/t/ghpython-type-casting/141705/7 "2022-04-28T08:04:00Z")

</div>

> [@Hamilton\_Forsythe](#):
>
> … so would be possible to leverage all the useful functions and tools in both libraries.

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:

> [@Reparametrize geometry python](https://discourse.mcneel.com/t/reparametrize-geometry-python/100057/8):
>
> It might also be worth mentioning that the rhinoscriptsyntax Python package is located here: C:\Users\USERNAME\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript Where you can browse through the .py files and learn how RhinoCommon has been implemented: I like to use Sublime Text for this. Where I add the rhinoscript folder (under Project \> Add Folder to Project), which allows you to sear…

> [@Reparametrize geometry python](https://discourse.mcneel.com/t/reparametrize-geometry-python/100057/14):
>
> You can also simply call inspect.getsource() while you’re developing: Edit: A downside to this (and the utility posted above) is that you don’t get the import statements included in the .py module file, which you would by directly inspecting the .py file. Thereby breaking the breadcrumb trail of where functions come from.

---

<div class="post-metadata">

**Author:** ![Hamilton\_Forsythe](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/hamilton_forsythe/32/671579_2.png) [@Hamilton\_Forsythe](https://discourse.mcneel.com/u/Hamilton_Forsythe)\
**Post date:** [April 29, 2022, 12:30am UTC](https://discourse.mcneel.com/t/ghpython-type-casting/141705/8 "2022-04-29T00:30:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Hamilton\_Forsythe](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/hamilton_forsythe/32/671579_2.png) [@Hamilton\_Forsythe](https://discourse.mcneel.com/u/Hamilton_Forsythe)\
**Post date:** [April 29, 2022, 12:32am UTC](https://discourse.mcneel.com/t/ghpython-type-casting/141705/9 "2022-04-29T00:32:03Z")

</div>

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.
