# Opening Grasshopper definition with toolbar button

**URL:** <https://discourse.mcneel.com/t/opening-grasshopper-definition-with-toolbar-button/196161>\
**Category:** Rhino Developer\
**Tags:** windows\
**Created:** [December 7, 2024, 9:49am UTC](https://discourse.mcneel.com/t/opening-grasshopper-definition-with-toolbar-button/196161 "2024-12-07T09:49:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![user1956](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/user1956/32/498377_2.png) [@user1956](https://discourse.mcneel.com/u/user1956)\
**Post date:** [December 7, 2024, 9:49am UTC](https://discourse.mcneel.com/t/opening-grasshopper-definition-with-toolbar-button/196161/1 "2024-12-07T09:49:15Z")

</div>

Hello, I have a toolbar with a button to access my gh definitions, the folder and subfolders open fine but when you select a definition, instead of executing there are options displayed in the Rhino command bar. Is there any way of getting it to open directly?

```py
! _-RunPythonScript (
import rhinoscriptsyntax as rs
import os
import System

def find_gh_items(directory):
    items = []
    for root, dirs, files in os.walk(directory):
        rel_path = os.path.relpath(root, directory)
        level = rel_path.count(os.sep)
        indent = " " * level
        
        if rel_path != ".":
            items.append(indent + os.path.basename(root) + " (dossier)")
        
        for file in files:
            if file.endswith(('.gh', '.ghx')):
                items.append(indent + " " + file)
    
    return items

user_app_data = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData)
path = os.path.join(user_app_data, "RhinoCVC", "PIECES 3DM")

if os.path.exists(path):
    gh_items = find_gh_items(path)
    if gh_items:
        selected_item = rs.ListBox(gh_items, "Sélectionnez une définition ou un dossier", "Bibliothèque Grasshopper")
        if selected_item:
            item_path = selected_item.strip()
            if item_path.endswith("(dossier)"):
                folder_name = item_path[:-9].strip()
                full_path = os.path.join(path, *folder_name.split(" "))
                rs.BrowseForFolder(full_path)
            else:
                file_name = item_path.strip()
                full_path = os.path.join(path, *file_name.split(" "))
                rs.Command("_Grasshopper")
                rs.Command("-_grasshopper _Document _Open" + '"' + full_path + '"')
    else:
        rs.MessageBox("Aucune définition Grasshopper trouvée dans le dossier.")
else:
    rs.MessageBox("Le dossier de la bibliothèque 3D n'existe pas à l'emplacement attendu.")
)

```

---

<div class="post-metadata">

**Author:** ![fmyl](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/fmyl/32/617283_2.png) [@fmyl](https://discourse.mcneel.com/u/fmyl)\
**Post date:** [December 9, 2024, 8:42am UTC](https://discourse.mcneel.com/t/opening-grasshopper-definition-with-toolbar-button/196161/2 "2024-12-09T08:42:29Z")

</div>

Try rs.command(\_-grasshopper \_window \_hide \_Enter)

---

<div class="post-metadata">

**Author:** ![user1956](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/user1956/32/498377_2.png) [@user1956](https://discourse.mcneel.com/u/user1956)\
**Post date:** [December 9, 2024, 9:44am UTC](https://discourse.mcneel.com/t/opening-grasshopper-definition-with-toolbar-button/196161/3 "2024-12-09T09:44:08Z")

</div>

Hello, where do I put this command line?

---

<div class="post-metadata">

**Author:** ![fmyl](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/fmyl/32/617283_2.png) [@fmyl](https://discourse.mcneel.com/u/fmyl)\
**Post date:** [December 17, 2024, 6:45am UTC](https://discourse.mcneel.com/t/opening-grasshopper-definition-with-toolbar-button/196161/4 "2024-12-17T06:45:09Z")

</div>

Hi, this is for runing grasshopper silencely, you may try to replace rs.Command(“_Grasshopper") with rs.command("_-grasshopper \_window \_hide \_Enter”) to see if it is able to meet your need.

And if you would like to open your gh file after runing grasshopper, you may try this:  
Grasshopper = Rhino.RhinoApp.GetPlugInObject(“Grasshopper”)  
Grasshopper.OpenDocument(“Path/To/Your/File.gh”)
