Hello,
I’m finally starting to play around with the awesome Kangaroo plugin by @DanielPiker and my favorite part is being able to “drag grasshopper objects around” with the mouse input. I LOVE the dynamic input opportunities this opens up!
My question is, how can I persistently store the “dragged to” location of an object and then when the Rhino doc is closed and reopened, the grasshopper object starts at the dragged to location that is stored in the document user text, but the user can still now drag this from its location and then again the updated new location gets stored in the DUT and then repeat the same process if the Rhino file is reopened.
Essentially, persistently track where an object has been moved to so that the GH object is always at that location even on document close.
I feel like I am close in my Python script but not quite there…
Graph Space:
Model Space:
Python Code Thus Far:
import rhinoscriptsyntax as rs
import Rhino
import scriptcontext as sc
sc.doc = Rhino.RhinoDoc.ActiveDoc
class PersistentLocation:
def __init__(self):
# Initialize loc with the value stored in the Rhino Document User Text, if available
self.loc = rs.GetDocumentUserText("Location")
def set_location(self, location):
self.loc = location
rs.SetDocumentUserText("Location", str(self.loc))
def get_location(self):
return self.loc
def reset_location(self):
rs.DeleteDocumentUserText("Location")
self.loc = None
# Initialize PersistentLocation object
persistent_location = PersistentLocation()
# Input parameters
loc = loc # Use a Grasshopper parameter named "loc" as input
reset = reset # Use a Grasshopper parameter named "reset" as input
# Check if reset is true
if reset:
persistent_location.reset_location()
else:
# Get the current location value
current_loc = loc
# Set the location in the Rhino Document User Text
persistent_location.set_location(current_loc)
# Output
loc_out = persistent_location.get_location()
sc.doc = ghdoc
GH File:
FUNCTION_Kangaroo_Box_Grips_01a.gh (14.7 KB)
Thank you all for your help!

