mcneel / ghpython

A Grasshopper component for Rhino.Python
http://www.food4rhino.com/project/ghpython
118 stars 34 forks source link

modules input #16

Open piac opened 12 years ago

piac commented 12 years ago

http://www.grasshopper3d.com/forum/topics/gh-python-component-why-the

piac commented 12 years ago

It is and will always be possible to add paths manually with this syntax:

import sys if not my_path in sys.path: sys.path.append(my_path)

import my_library

bengolder commented 12 years ago

I think this is most relevant to new users and to people who want to create and share plugins.

new users, who are trying to use some neat python library they found, would benefit from a simple non-code interface for adding python modules to import from. If there was an option to right click, then select a folder to add to the sys.path, I think using external modules would be less intimidating to a brand new user.

The second use case is script authors who want to share a script that relies on additional modules. this might be well addressed in several ways:

  1. if the menu described above recorded file paths relative to the grasshopper file in which the script is saved.
  2. if there is a very clear default file path for scripting components to utilize that will always be included in sys.path (perhaps the 'Components Folder', or a 'Scripts' folder, or the 'User Object' folder.) This way, there is little confusion about where additional packages should be placed. Imagine downloading someone's script and they can say "To get started, just drag and drop this .gh file into your 'Scripts Folder' which can be found under 'File' > 'Special Folder' in Grasshopper."
piac commented 10 years ago

I think I would need some interventions in the main Rhino.Python plugin for this, as the ghPython component is, among other things, a trimmed-down version of the same editor that is there in _EditPythonScript. This actually means that

  1. There is already a non-coding way to do that. It is in the _EditPythonScript. In fact, the ghPython component listens to all the locations that are available in _EditPythonScript > Options > Module Search Paths. What is missing is probably a way to show that information in ghPython for convenience. I am only afraid about adding several location, as it will slow down the search for modules.
  2. The local Grasshopper file path is, from now (0.5.99) on, available in sys.path, while running the ghPython component definition