Grasshopper

algorithmic modeling for Rhino

Question on adding object dynamically to active Grasshopper document

Hi,

I have a python script from which I would like to add components dynamically to an active Grasshopper definition.

I have managed to do it successfully with a panel. The following is a snippet of my code:

def create_panel_ptinfo(_xyz):
    my_panel = g.Kernel.Special.GH_Panel()
    my_panel.UserText = str(tuple(_xyz))[1:-1]  #format point info as a string
    my_panel.NickName = "My Listened point"
    my_panel.CreateAttributes()
    my_panel.Attributes.CustomColour = color.FromArgb(200,255,55,55)
    return my_panel

my_panel= create_panel_ptinfo(xyz)  # where xyz is some arbitrary point coordinates
ghdoc.AddObject(my_panel,False,1)

This allows me to add the following:

I have two questions regarding this:

1) I am not entirely sure what the last argument for AddObject() is. In the Grasshopper SDK it says index. Is this the index of all objects in the Grasshopper document? If so, if i keep using the index 1, why does it not 'overwrite' the existing components?

2) I would like to know how to directly create a Point param in the document. My solution right now works (using panels). Originally I wanted to create a Point param holding the correct xyz info, but I did not succeed.

Thanks!

Views: 230

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service