# Components in ghpythonlib

**URL:** <https://discourse.mcneel.com/t/components-in-ghpythonlib/135365>\
**Category:** Grasshopper\
**Tags:** windows, python\
**Created:** [December 22, 2021, 5:26pm UTC](https://discourse.mcneel.com/t/components-in-ghpythonlib/135365 "2021-12-22T17:26:23Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![0904](https://avatars.discourse-cdn.com/v4/letter/0/b3f665/32.png) [@0904](https://discourse.mcneel.com/u/0904)\
**Post date:** [December 22, 2021, 5:26pm UTC](https://discourse.mcneel.com/t/components-in-ghpythonlib/135365/1 "2021-12-22T17:26:23Z")

</div>

> import rhinoscriptsyntax as rs  
> import ghpythonlib.components as ghc
> 
> e0 = ghc.Line(“0,0,0”, “10,10,0”)  
> e1 = ghc.Move(“0,0,0”, “0,0,10”)  
> e = ghc.Line\_Pt(e0, e1)

![ghc](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/4/f/9/4f9fc3addb8d894d18b4f4890de9cbb0ec063bf3.jpeg)

Hello everybody,  
could anyone tell me why these errors come back to me?  
e0 and e1 are fine. e return error 2 of “Data conversion failed”

---

<div class="post-metadata">

**Author:** ![kev.r](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/kev.r/32/771963_2.png) [@kev.r](https://discourse.mcneel.com/u/kev.r)\
**Post date:** [December 22, 2021, 7:38pm UTC](https://discourse.mcneel.com/t/components-in-ghpythonlib/135365/2 "2021-12-22T19:38:58Z")

</div>

If you change your code to this:

```python
import rhinoscriptsyntax as rs
import ghpythonlib.components as ghc

e0 = ghc.Line("0,0,0", "10,10,0")
e1 = ghc.Move("0,0,0", "0,0,10")

print "e0 = {}, {}".format(e0, type(e0))
print "e1 = {}, {}".format(e1, type(e1))

e = ghc.Line_Pt(e0, e1)

```

You will get this output:

```auto
  e0 = 0,0,0,10,10,0, <type 'Line'>
  e1 = {'geometry': <Rhino.Geometry.Point3d object at 0x0000000000000090 [0,0,10]>, 'transform': <Rhino.Geometry.Transform object at 0x0000000000000091 [R0=(1,0,0,0), R1=(0,1,0,0), R2=(0,0,1,10), R3=(0,0,0,1)]>}, <class 'ghpythonlib.components.__namedtuple'>
  Warning: Line + Pt: input 2 point. error: Data conversion failed from Transform to Point
  Warning: Line + Pt: solver component. error: Data conversion failed from Transform to Point

```

You can see that your e1 variable holds a tuple containing a Point3d and a Transform object.

Now if you change your code to:

```python
import rhinoscriptsyntax as rs
import ghpythonlib.components as ghc

e0 = ghc.Line("0,0,0", "10,10,0")
e1 = ghc.Move("0,0,0", "0,0,10")

print "e0 = {}, {}".format(e0, type(e0))
print "e1 = {}, {}".format(e1, type(e1))

e = ghc.Line_Pt(e0, e1[0])
print "e = {}, {}".format(e, type(e))

```

You will get this output:

```auto
  e0 = 0,0,0,10,10,0, <type 'Line'>
  e1 = {'geometry': <Rhino.Geometry.Point3d object at 0x000000000000008E [0,0,10]>, 'transform': <Rhino.Geometry.Transform object at 0x000000000000008F [R0=(1,0,0,0), R1=(0,1,0,0), R2=(0,0,1,10), R3=(0,0,0,1)]>}, <class 'ghpythonlib.components.__namedtuple'>
  e = Origin=0,0,0 XAxis=0.707106781186547,0.707106781186547,0, YAxis=0,0,1, ZAxis=0.707106781186547,-0.707106781186547,0, <type 'Plane'>

```

Your e variable now contains a plane (I think this is your intended result).

I’m not sure why you’re trying to use **ghpythonlib.components** to do this. These things can be easily done with the RhinoCommon API methods which are pretty well documented here:  
[https://developer.rhino3d.com/api/RhinoCommon/html/R\_Project\_RhinoCommon.htm](https://developer.rhino3d.com/api/RhinoCommon/html/R_Project_RhinoCommon.htm)

-Kevin

---

<div class="post-metadata">

**Author:** ![0904](https://avatars.discourse-cdn.com/v4/letter/0/b3f665/32.png) [@0904](https://discourse.mcneel.com/u/0904)\
**Post date:** [December 22, 2021, 10:27pm UTC](https://discourse.mcneel.com/t/components-in-ghpythonlib/135365/3 "2021-12-22T22:27:28Z")

</div>

thanks Kevin for the reply,

 ![ghc2](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/a/d/a/ada6f015a1709cb86624c5076bc875758217c7f7.jpeg)

sorry if I ask a second question:  
the first three lines were used to be added to the fourth and I inserted the variables in place of the coordinates. as you can see from the message, the new problem concerns the fourth row of the BoundingBox, I did various tests and tried to solve it but without results. some idea?

> [@kev.r](#):
>
> I’m not sure why you’re trying to use **ghpythonlib.components** to do this. These things can be easily done with the RhinoCommon API methods which are pretty well documented here:

yes indeed RhinoCommon would be more appropriate, but for me it is too broad a scope.  
(I understand little or nothing)

I can use the rhinoscriptsyntax library just the basics  
and I create some definitions in Grasshopper, then having discovered the ghpythonlib library, which via script simulates the functioning of Gh components, everything is more familiar to me. . . .

---

<div class="post-metadata">

**Author:** ![kev.r](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/kev.r/32/771963_2.png) [@kev.r](https://discourse.mcneel.com/u/kev.r)\
**Post date:** [December 23, 2021, 12:25am UTC](https://discourse.mcneel.com/t/components-in-ghpythonlib/135365/4 "2021-12-23T00:25:50Z")

</div>

Difficult to help from a screen capture can you post a GH file?

What is the type and value of variable u?

From the error message it appears you are supplying a Guid where a Geometry input is required.

There are some functions in rhinoscriptsyntax for coercing Guid’s but without a GH file I can’t really help.

-Kevin

---

<div class="post-metadata">

**Author:** ![0904](https://avatars.discourse-cdn.com/v4/letter/0/b3f665/32.png) [@0904](https://discourse.mcneel.com/u/0904)\
**Post date:** [December 23, 2021, 1:13am UTC](https://discourse.mcneel.com/t/components-in-ghpythonlib/135365/5 "2021-12-23T01:13:08Z")

</div>

you are right Kevin, as these lines of code are part of a whole, I will try to extrapolate only the part of the code with a “closed curve” that replicates the same problem.

ps, however, the curve in question should not be a strange curve (which gives problems) being that before the code I made a small definition in Gh that works without problems, with the same curve etc. So through codes I follow the same reasoning and passages made with the def in gh (I repeat that it does not give problems)  
the only doubt that comes to me now concerns the def in gh and that the BBox component, clicking with the right button in the center, has the option “Union Box” and I wonder if it is not necessary to set some options in indicating the first parameter of the closed curve in question? ? ? ?  
thank you!

---

<div class="post-metadata">

**Author:** ![0904](https://avatars.discourse-cdn.com/v4/letter/0/b3f665/32.png) [@0904](https://discourse.mcneel.com/u/0904)\
**Post date:** [December 23, 2021, 11:54am UTC](https://discourse.mcneel.com/t/components-in-ghpythonlib/135365/6 "2021-12-23T11:54:59Z")

</div>

u = closed curve (Item Access / Type hint = ghdoc)  
d = two point (List Access / Type hint = Point3d)

 ![Kevin3](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/2/c/c/2cca2ea1a3c77c42d4778c04dfdf798ee0879acf.jpeg)

finally while I was looking for some solution, reading discussions I saw examples  
of BBox with rhinoscriptsyntax, trying with this library no problem. mmmm 🤔 🤔

ps it seems that the ghpythonlib library works differently than rhinoscriptsyntax  
(better to use it as little as possible)

thank you so much Kevin

---

<div class="post-metadata">

**Author:** ![kev.r](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/kev.r/32/771963_2.png) [@kev.r](https://discourse.mcneel.com/u/kev.r)\
**Post date:** [December 23, 2021, 4:15pm UTC](https://discourse.mcneel.com/t/components-in-ghpythonlib/135365/7 "2021-12-23T16:15:22Z")

</div>

> [@0904](#):
>
> the only doubt that comes to me now concerns the def in gh and that the BBox component, clicking with the right button in the center, has the option “Union Box” and I wonder if it is not necessary to set some options in indicating the first parameter of the closed curve in question? ? ? ?

From this post, I don’t think you can access these right-click options from ghpythonlib.components

> [@Am I the only one who got confused using ghpythonlib.components?](https://discourse.mcneel.com/t/am-i-the-only-one-who-got-confused-using-ghpythonlib-components/89214/2):
>
> Hi @grasshoppertrainer, You are asking advanced questions. Let’s have a look together. This is not possible. There is no SDK method to do this, so no library can replicate this. The right-click behavior is defined per-component, so there is no way to repeat it automatically at present. @DavidRutten said he would study some options for GH2. These components are very special, and they are usually a way to represent a looping or conditional construct. The library does not allow to add argument…

Regarding the user of ghpythonlib, his recommendation is the same as what you wrote

> [@0904](#):
>
> ps it seems that the ghpythonlib library works differently than rhinoscriptsyntax  
> (better to use it as little as possible)

-Kevin

---

<div class="post-metadata">

**Author:** ![0904](https://avatars.discourse-cdn.com/v4/letter/0/b3f665/32.png) [@0904](https://discourse.mcneel.com/u/0904)\
**Post date:** [December 23, 2021, 5:00pm UTC](https://discourse.mcneel.com/t/components-in-ghpythonlib/135365/8 "2021-12-23T17:00:25Z")

</div>

Hi @kev.r

I did it!

 ![Kevin4](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/2/d/e/2de850fc997925d7df38d32a574a284331d19240.jpeg)

after your last answer, I reread the whole discussion, and thinking back to your last considerations, it occurred to me to give it a try: change the parameters in the input of u = closed curve (List Access / Type hint = Curve) as soon as I did it everything was fine it works perfectly 💪 ps luckily I have a hard head 😆  
Thanks again 👍

days ago I was trying to figure out how to set “List Access” via script but I couldn’t find the right examples  
😓
