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)
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.
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
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()