Limit Bake and then break

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)

1 Like

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
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…