rs.ViewNames(return_names=True, view_type=1) in order

Hi all,

I don’t know if this is found in any other topic.
But if I’m correct the rs.ViewNames() returns the views in a list as they are created.
Is there a way to sort them in the order as they are place in the document?

for example:
I create view A, then B, then C. rs.ViewNames() will now return A,B,C
When I later move the “tabs” to C,A,B rs.ViewNames() still returns A,B,C.

I want to return the names of the “viewTabs” in a list as they are placed in the document (C,A,B)

Hope this makes sence

Thanks in advance

Why do you need to do this? What problem are you looking to solve?

– Dale

Hi Dale,

How to explain this… =)

I have a script where the user gets a rs.CheckListBox() with all views.
In the views that are checked it will change a specificly named text object with an increasing number depending on how they are placed in tab order.

basicly each view is a drawing, and each drawing have a number 001, 002, 003 etc.
The user can check which drawings that should have a drawingnumber and then it is placed out with the correct number depening on it’s position in the tabs order.

Is this understandable? =)

Perhaps you can just sort the list of names before adding them to the check listbox?

Hi Dale,

That’s the problem, I don’t know hos to sort the list since the rs.ViewNames() command seams to populate according to the time each view is created.

so creating view A, B, C, D gives in rs.ViewNames() A,B, C, D
When moving view D to the first place gives in the document D, A, B, C, but rs.ViewNames() still gives A,B, C, D

How about this?

import rhinoscriptsyntax as rs
names = rs.ViewNames()
names.sort()

– Dale

Sorry if I misguided you with the names.

Here is an example:

Untitled.3dm (39.7 KB)

On this document try:

import rhinoscriptsyntax as rs
print rs.ViewNames(return_names=True, view_type=1)

It will give you:
[‘Page 1’, ‘Page 2’, ‘Page 3’, ‘Page 4’]

I want:
[‘Page 4’, ‘Page 1’, ‘Page 2’, ‘Page 3’]
Since this is how they are palced in the document

Hope this cleared out the question.

Thanks for helping

bump this thread.

Does anyone have a solution to this?

Best regards!

Hi Dale,

Found that this only happens if I create a new layout in the document and run the command.

import rhinoscriptsyntax as rs
print rs.ViewNames(return_names=True, view_type=1)

If I save, close and open the document I get it in the right order.( [‘Page 4’, ‘Page 1’, ‘Page 2’, ‘Page 3’] )

Is there a way to update the document before running this command?

/thanks again

You might try sorting the list of page views by their page number, which is basically the display order.

import Rhino
import scriptcontext

def OrderedPageViewNames(return_names=True):
    views = list(scriptcontext.doc.Views.GetPageViews())
    if views is None: return scriptcontext.errorhandler()
    views.sort(key=lambda view: view.PageNumber)
    if return_names: return [view.MainViewport.Name for view in views]
    return [view.MainViewport.Id for view in views]

print OrderedPageViewNames()
1 Like

Thanks Dale, I’ll give it a try.