Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

find a way to trigger the process without being wired into the rest of the graph #4

Open
notionparallax opened this issue Sep 4, 2024 · 1 comment

Comments

@notionparallax
Copy link
Member

So that the documentation nodes can be isolated, but then still trigger on every update cycle

@notionparallax
Copy link
Member Author

Copilot says:

Yes, you can connect your Python node to the update cycle in Grasshopper using the Grasshopper API. This way, your script will run whenever the graph updates, without relying on a fixed timer. Here's a general approach:

  1. Use the GH_Document Events: Grasshopper's GH_Document class has events that you can subscribe to, such as SolutionStart and SolutionEnd. These events are triggered whenever the Grasshopper document (graph) updates.

  2. Create a Custom Component: You can create a custom Grasshopper component in Python that subscribes to these events. Here's a basic example:

    import Grasshopper
    import GhPython
    import Rhino
    
    class CustomComponent(GhPython.Component):
        def __init__(self):
            self.OnPingDocument().SolutionStart += self.OnSolutionStart
    
        def OnSolutionStart(self, sender, e):
            # Your custom code here
            print("Graph updated!")
    
        def RunScript(self, input):
            # Your main script logic here
            pass
    
    # Instantiate the component
    component = CustomComponent()
  3. Add the Component to Grasshopper: You can add this custom component to your Grasshopper canvas. It will automatically run your custom code whenever the graph updates.

This approach ensures that your Python script runs only when the graph updates, without needing to be connected to the main graph or relying on a fixed timer.

Would you like more detailed instructions or help with a specific part of this process?

Source: Conversation with Copilot, 05/09/2024
(1) refreshing the python script engine - Grasshopper. https://www.grasshopper3d.com/forum/topics/refreshing-the-python-script-engine.
(2) Rhino News, etc.: Python Scripting for Rhino/Grasshopper online .... https://blog.rhino3d.com/2022/12/python-scripting-for-rhinograsshopper.html.
(3) RAM | STAAD Forum - RAM.Concept API - Grasshopper Plugin. https://bentleysystems.service-now.com/community?id=community_question&sys_id=9530f2911be5ca10f3fc5287624bcbe3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant