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?
! _-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.")
)