Run portion of script only when one input value changes and not another input value in a python component

Hi @stevebaer , @piac , et al

Orginally written Here , but not been able to solve it, and would be great to keep the code in python if possible. So i don’t have to rewrite the main code in C# as still beginner there.

Is it possible to only run a portion of a code when one value changes, and not recompute the whole code again when another input changes in a python component ?

I am working with Cameras and i am trying to store the initial camera view, edit /add named views then return the initial camera view when the switch is returned to false.

It works to the level that it creates a named view based on the active viewport and the new view as required but when i move the slider to change the zoom on the new viewport/s it updated both so when it i am finished with the change and i switch it back it returns an updated view before deleting the temporary viewport and not the original named view i had saved.

I have a feeling this problem would also happen if i wrote the viewport info to an dictionary as it would still run the whole code again and update the dictionary as it currently written


    from Rhino.RhinoDoc import ActiveDoc as doc
    import rhinoscriptsyntax as rs
    def SetISO(vp):
    if Create == 1:
    #Get Active Viewport
    vp = doc.Views.ActiveView.ActiveViewport
    current_vp = vp.Name

    index = doc.NamedViews.FindByName(current_vp)

Just bake the Example Brep into Rhino File for reference Geometry to see if the Camera is working as expected. Note: (Modelled in Meters)

Since Posting this first question on the Grasshopper Forum i have found this list but not yet worked out how to implement any of them in the code


The more i have worked on solving this the more i have found if i can understand how the logic work that if one input changed it done one thing once, even when another input changes it does not recompute the first action. Making some GH codes so much faster.

Run Part Script (9.4 KB)

Thanks Matt

Hi Matt

I’ve answered there. I’m sorry I don’t have a good answer to this general question.
I’d probably need some tangible purpose to have something actionable as an answer.


Giulio Piacentino
for Robert McNeel & Associates