Deleting Page Layouts

I can’t figure out how to delete Page Layouts.
I’ve tried this: https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Display_RhinoView_Close.htm:

myLayoutReference.Close()
scriptcontext.doc.Views.Redraw()

but that doesn’t work.
I’ve looked in the RhinoCommon docs, but even there I can’t find any other way of doing it. The ViewTable class doesn’t have a remove counterpart to it’s AddPage method.

Any tips?

Hmm, just looking at the api doc, the Rhino.PageView class has a “Close” method…
(inherited from RhinoView)

https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Display_RhinoView_Close.htm

Don’t know if that will do it…

Isn’t that the same method I attempted to call (and linked to?) Or am I missing something?

Yeah, sorry, too late last night…

The following seems to work for me to close all layouts - which I think is the same as deleting them:

import scriptcontext as sc
import Rhino

p_views=sc.doc.Views.GetPageViews()
for p_view in p_views:
    p_view.Close()

You would of course need to refine that to close only the layouts you want…

Is this more or less what you’re looking for?

My bad. It works’ish, but the Layout UI doesn’t update on Mac WIP: the pages are still visible. Only after closing the Layout window, and reopening it, is it updated. Further the “Closed” pages, keep hangin around in the view table:

import scriptcontext as sc

p_views0 = sc.doc.Views.GetPageViews()
num_pviews_before = len(p_views0)
print(num_pviews_before)
for p_view in p_views0:
    p_view.Close()

p_views1 = sc.doc.Views.GetPageViews()
if (len(p_views1) == num_pviews_before):
    raise Exception("zombie pages detected. Run!")

Results in the Exception being raised.

I suppose I’m missing calling one of the commit/redraw methods, but I can’t figure out which one?

OK, I didn’t check on Mac… The views are not left hanging around in the view table in V6 for Windows after closing.

Before:
image

After:
image

Probably a bug on the Mac side… maybe nothing you can do until it’s fixed.

Does calling a redraw help in any way?

sc.doc.Views.Redraw()

I attempted the sc.doc.Views.Redraw() in between, but it doesn’t work.

Thanks a lot for your taking a look @Helvetosaur!

If anyone from McNeel is listening in on this, you can use the minimal test case above to reproduce the buggy behavior. You just need to have some existing layouts before running it.

@Alain - do you have any idea what might be happening here?

1 Like

Hi Mitch, No but I logged the issue.
Thanks for looking into it.

1 Like

This bug should be fixed in the latest RhinoBETA.

1 Like