Invalid NamedView ViewportId

Hello,
I’m trying to get the Guid of NamedView Viewport but I’m getting strange results.

to get the NamedView viewport ids I use this piece of code:

      List<Guid> namedViewIds = RhinoDoc.ActiveDoc.NamedViews
        .Select(v => v.Viewport.Id)
        .ToList();

But it return strange values, either only 0 as seen on this pic:

or sometimes the Viewport does return a valid Guid value, but all the named view viewport have the same Guid. for info those NamedView can be active in a visible viewport or not but their viewport guid will still seems wrong.

Now there is another method that get Rhino standard view :

      List<Guid> standardViewIds = RhinoDoc.ActiveDoc.Views.GetStandardRhinoViews()
        .Select(v => v.ActiveViewportID)
        .ToList();

This method does include some of the NamedView (not all but that’s another subject), the important thing here is that this method when it return NamedViews they will have a correct Viewport Id (valid guid)

So I tried to look on the forum and read the doc but still don’t understand if I’m just getting this wrong or it’s a bug. how can I get consistent result for NamedView viewport Id from the NamedView table ?

Thanks for anyone who can help.

Are you doing this with Rhino 7? Perhaps you can share a Rhino file that has this problem.

@nathanletwory thanks for the reply. Sure thing, I can provide more details. I’m on Rhino 7 SR26.
So while trying to recreate the problem and the test file I think I gained more understanding of how this work.

this is the code I used for debug:

        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            
            Dictionary<string, Guid> namedViewIds = RhinoDoc.ActiveDoc.NamedViews
              .ToDictionary(k => k.Name, v => v.Viewport.Id);

            Dictionary<string, Guid> standardViewIds = RhinoDoc.ActiveDoc.Views.GetStandardRhinoViews()
              .ToDictionary(k => k.ActiveViewport.Name, v => v.ActiveViewport.Id);

            return Result.Success;
        }

When I run this code on the first file I attached (NamedViewDebug.3dm) we can see that the Named View viewport Id are all zeros

Now here is the interesting part, I create a new NamedView5 from the perspective viewport and rerun the code, we can see that the guid id it got assigned to is the Perspective viewport guid.

Ok now I save this to a new file I attached (NamedViewDebug2.3dm), close the file, reopen it again, rerun the code, the NamedView5 lost it’s guid, it’s all zeros now

We can also see that the NamedView5 in the second dictionary of standard view kept the guid, that’s because, if i’m getting this right, creating a NamedView will create 2 views: the NamedView itself AND a standard view with the same name.

Anyway, maybe this is working as intended. But in any case I’m just trying to get a unique way to identify each named view and apparently their viewport guid is not the best idea (I also discovered that creating two named views from the same viewport will get them the same guid before getting zeroed on the next file open/close).

NamedViewDebug.3dm (140.6 KB)
NamedViewDebug2.3dm (140.3 KB)

Thanks for the additional info. One thing before I look into this more: you already get a RhinoDoc instance passed to your RunCommand implementation. Use that instead of RhinoDoc.ActiveDoc, meaning doc.NamedViews.

Addendum:

Indeed in your 3dm file these named views have IDs of zeroes. How were these named views created?

you are right about the doc, I just copy/pasted the code without paying much attention to that. :sweat_smile:

those view were created like NamedView5, like I described in my previous reply:

Now here is the interesting part, I create a new NamedView5 from the perspective viewport and rerun the code, we can see that the guid id it got assigned to is the Perspective viewport guid.

In summary, I go to the perspective viewport, on the “Named views” panel I click “save as…” and type the new NamedView name. it get saved and the viewport id will be the same as the perspective viewport id. HOWEVER closing and reopening the file will make the Id go back to Zeros

There is probably going something on I don’t understand. I’m asking around if this is how it is supposed to go or not.

thanks a bunch @nathanletwory :slight_smile: