# The same script works in Rhino Python Editor yet not in GhPython Component

**URL:** <https://discourse.mcneel.com/t/the-same-script-works-in-rhino-python-editor-yet-not-in-ghpython-component/101645>\
**Category:** Scripting\
**Created:** [May 7, 2020, 2:59pm UTC](https://discourse.mcneel.com/t/the-same-script-works-in-rhino-python-editor-yet-not-in-ghpython-component/101645 "2020-05-07T14:59:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![xudong](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/xudong/32/265456_2.png) [@xudong](https://discourse.mcneel.com/u/xudong)\
**Post date:** [May 7, 2020, 2:59pm UTC](https://discourse.mcneel.com/t/the-same-script-works-in-rhino-python-editor-yet-not-in-ghpython-component/101645/1 "2020-05-07T14:59:43Z")

</div>

Hello!  
A Rhino/GH frequent user but python newbie here 🙂

was working on a Python script that could fix broken text objects(for example one text object “33.6” breaks into two objects “33” & “6”; the script is trying to fix it) in Rhino, it worked perfectly in Rhino Python Editor, but when I was trying to transfer the same code to GhPython Component (the reason why I do this is that I would like to use Human UI in GH to make the workflow more smooth ), some error occurred and I can’t find out why.

Here is a screen shot, it seems that the TextObjectPoint() & TextObjectText() methods are returning correct value in Rhino Python Editor but returning “none” value in GhPython:

 ![121](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/e/d/edc5382954785e143789d70eadf3eef82e79f7b3.jpeg)

and here is my complete script which works perfectly (a bit slow though) in Rhino Python Editor but not in GhPython Component:

```auto
python
import rhinoscriptsyntax as rs

def fixbrokentext():
    
    T01 = rs.GetObjects("Pick broken text",512,True,True,True)

    VL_f = []
    PL_f = []

    VL_i = []
    PL_i = []

    VL_t = []
    PL_t = []

    count = 0
    for i in T01:
        ID = T01[count]
        P00 = rs.TextObjectPoint(ID)
        V00 = rs.TextObjectText(ID)
        
        st = str(V00)
        
        if "," in st :
            V00 = V00.replace(",",".")
            VL_t.append(V00)
            PL_t.append(P00)
        elif float(st)<10:
            VL_f.append(V00)
            PL_f.append(P00)
        else:
            VL_i.append(V00)
            PL_i.append(P00)
        
        count += 1
        
    t = len(PL_i)
    for i in range(0,t):
        P = PL_i[i]
        Inx = rs.PointArrayClosestPoint(PL_f,P)
        F = float(VL_f[Inx])
        T = int(VL_i[i]) + F/10
        rs.AddText(T,PL_i[i],1.0)
    
    s = len(VL_t)
    for i in range(0,s):
        rs.AddText(VL_t[i],PL_t[i],1.0)
        

fixbrokentext()

```

Any ideas on how to make the script work also in GhPython Component?

---

<div class="post-metadata">

**Author:** ![piac](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/piac/32/673006_2.png) [@piac](https://discourse.mcneel.com/u/piac)\
**Post date:** [May 7, 2020, 3:05pm UTC](https://discourse.mcneel.com/t/the-same-script-works-in-rhino-python-editor-yet-not-in-ghpython-component/101645/2 "2020-05-07T15:05:14Z")

</div>

Hi @xudong

Grasshopper has its own document, and does not use the Rhino document for computation.  
You can use the `rs.` functions for text in Grasshopper, but you need to target the Rhino document. Grasshopper has no text as geometry data. This can be done like so:

```auto
import scriptcontext as sc
import Rhino as rh
sc.doc = rh.RhinoDoc.ActiveDoc

```

but you _must_ remember to put things back to normal afterwards:

```auto
sc.doc = ghdoc

```

Please note that the Rhino document is visible, has undoes, and is slower to visualize and add into than the Grasshopper invisible document.

Does it help?

Thanks,

Giulio

–  
Giulio Piacentino  
for Robert McNeel & Associates  
[giulio@mcneel.com](mailto:giulio@mcneel.com)

---

<div class="post-metadata">

**Author:** ![xudong](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/xudong/32/265456_2.png) [@xudong](https://discourse.mcneel.com/u/xudong)\
**Post date:** [May 7, 2020, 3:07pm UTC](https://discourse.mcneel.com/t/the-same-script-works-in-rhino-python-editor-yet-not-in-ghpython-component/101645/3 "2020-05-07T15:07:26Z")

</div>

Thanks for the fast reply!  
😃 It works!
