Grasshopper

algorithmic modeling for Rhino

Creating a custom GH component that removes the geometry when Preview is not enabled, but retains the geometry when baked

I'm creating a custom component that should theoretically add/remove geometry depending on the state of Preview (True/False). So far I've found this discussion: Python Previewing without an Output

From that particular thread, I've derived that ghenv.Component.Hidden will tell me if the Preview is True/False, plus the sample files in the thread illustrate how to remove and add the geometry to the display.

However, I'd like to add an additional feature, which is being able to bake the geometry using this custom GH component and getting back the GUIDs generated. Would anyone have any suggestions as to what resources I can look at or similar threads? I've looked through the forums but I may have missed some of the more relevant responses. 

With the examples in the thread, it doesn't seem to allow for baking the geometry when the Preview is set to False. The code from that thread I'm looking at specifically is below (the file called CustomDisplayDisc etc):

import Rhino as rc

def preview(x, y):
   global display
   if "display" not in globals():
      display = rc.Display.CustomDisplay(True)
      # Clear everytime
      display.Clear()

   if ghenv.Component.Hidden == False:
       r = g = b = 1
       for i, crv in enumerate(Curves):
          rgb = rc.Display.ColorHSL(r, g, b)
          display.AddCurve(crv, rgb, i+1)

       # Dispose of custom display
    else:
       display.Dispose
       del display

ghenv.Component.PreviewExpired += preview

Furthermore, does 'display' function as a way of only temporarily holding the geometry or does it generate actual GUIDs? It would be great to understand more about this aspect of Grasshopper, since I'm still pretty new to using scripting in GH.

Views: 268

Reply to This

Replies to This Discussion

Under Rhino.RhinoDoc.ActiveDoc.Objects you have all the methods do add new objects to the current document. 

http://developer.rhino3d.com/api/RhinoCommonWin/html/T_Rhino_DocObj...

I believe you'll call it 

circle_GUID = rc.RhinoDoc.ActiveDoc.Objects.AddCircle(Circle, Attributes)

which is also a function returning a GUID of this new Circle.

Regarding the display... I don't think any of the objects passed to the display pipeline are actually added to the ObjectTable. 

On the same note, what method would I use to determine if the user opted to bake the geometry? (similar to how I can find out if Preview is set to True/False)

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2019   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service