i have a somewhat odd question, but is there a way to write/compile a bake component (ghpy) that self-destructs/corrupts after one execution?
You can access the component and set its code property to an empty string at the end of your script. I forget how in compiled components, but for a regular GHPython component you would do this:
ghenv.Component.Code = ""
You can probably also have it self-delete/remove from canvas. But deleting the code might be simpler.
Edit: Hereās a quick proof of concept:
230306_BakeAndDeleteScript_00.gh (3.2 KB)
Yes, odd question. What is the problem you want to solve? Could it be done by setting a flag when baking that must be explicitly reset before bake is allowed to work again? Python āglobals()ā could be useful for that.
I added a āResetā input to the Python bake component I wrote three years ago:
Seems to work, though Iām far from an expert at Python.
bake_once_2023Mar6a.gh (5.4 KB)
# Instantiate/reset persisent "okBake" variable
if "okBake" not in globals() or reset:
okBake = True
if active and okBake: #change the scriptcontext
scriptcontext.doc = Rhino.RhinoDoc.ActiveDoc
try:
if type(geo) is System.Guid:
g = ghdoc.Objects.Find(geo)
if g and hasattr(g, 'Geometry'):
bakeGeo(g.Geometry, g.Attributes, layer, rM, mSrc)
okBake = False
P.S. This will cause problems in the way I typically use the Bake component when I use multiple ābakesā for a variety of geometry and layers. Only the first one will work.
thanks for the quick answers. yes seems like a strange question. iām trying to generate some kind of watermark with a unique user id that canāt be generated again after running it once. only problem now is that when i reopen the script it works again. so i was thinking of compiling one.
another thing is how to also ābakeā to grasshopper canvas. i know there is the option to āload from rhinoā
Maybe bake the watermark to a reserved layer name?
sry what is a reserved layer? some kind of hidden layer or can i create non public or privat layers?
No private/hidden layers that I know of, just a unique name that you use for your watermark. I donāt know if the idea helps? But if that layer exists, that could be a flag that youāve already baked it.
You can generate a GUID/UUID before running the line that deletes the Python script (i.e. that I posted above):
But yeah, you should probably explain the larger problem as this all seems a bit odd/unnecessary.
Well thank you so much. I think I go for the countdown one. So i use timedelta or countdown and when time is up one can t bake anymore with watermark or soā¦ To shed some light on it: I am developing a grasshopper workshop where for practice reasons the partitioners have limited time to submit small exercises. So they can only bake in given time with watermark,like ^you win^, or on the other hand ^game over^. Just some gimmick to show the potential of coding stuffā¦
this is work in progressā¦ next i want to implement the limited bake functionā¦