view.ActiveViewport.PopViewProjection() no effect

@dale I am trying to store and restore the current view. I based my attempt on Select object by WindowBox - #14 by dale but do not get it to work. Any hints would be greatly appreciated. Thank you - Silvan

import Rhino.Geometry as rhg
import scriptcontext as sc


def main():
    # Store view
    view = sc.doc.Views.ActiveView
    if not view:
        print("Could not store current view to restore")
    view.ActiveViewport.PushViewProjection()
    
    # Modify viewport
    viewport = view.ActiveViewport
    viewport.SetToPlanView(rhg.Plane.WorldXY.Origin, 
                           rhg.Plane.WorldXY.XAxis, 
                           rhg.Plane.WorldXY.YAxis * -1., False)
    viewport.ZoomExtents()
    
    # Restore view and redraw the document
    view.ActiveViewport.PopViewProjection()
    view.Redraw()


main()

If nobody answers you can try getting help from chatgtp.

I am a very poor scripter and dont use it often so I normally ask chatgtp for help with my scripts. It has been a gamechanger for me to be able to ask chatgtp about python coding in rhino

We are using Github copilot. Unfortunately such SDK specific questions are mostly not solved by them. Out of curiosity I gave ChatGPT a try as well, to no avail. Thanks for the tip anyways :slight_smile:

For anybody ever having the same question: I overlooked that viewport.SetToPlanView() and viewport.ZoomExtents() also push to the viewport fifo stack. To get back to the state at view.ActiveViewport.PushViewProjection() one needs to 3x view.ActiveViewport.PopViewProjection().