How can I make a script where the user selects a layout from layout names and then makes that layout active?
Or in other words - I get an error "expected RhinoView, got str" - So how to find a RhinoView by having a name?
(this script is just a part of bigger one, but I can’t get this part to work…)
import Rhino
import scriptcontext as sc
import System.Drawing
import rhinoscriptsyntax as rs
def make_details():
layoutNames = []
page_views = sc.doc.Views.GetPageViews()
for page_view in page_views:
layoutNames.append(page_view.PageName)
layout = rs.ComboListBox(layoutNames, "Select layout")
if layout:
sc.doc.Views.ActiveView = layout
sc.doc.Views.Redraw()
print layout
if __name__ == "__main__":
pageview = sc.doc.Views.ActiveView
if type(pageview) == Rhino.Display.RhinoPageView:
print "This tool only works in the model space."
else:
make_details()
There’s too many men, too many people
Making too many problems
And there’s not enough love to go around
Anyways, I found a solution, maybe not the proper way, but it might help in a case when you want to use rhinoscriptsyntax ComboBox for user interface and retrieve an item based on that selection from another list:
import Rhino
import scriptcontext as sc
import System.Drawing
import rhinoscriptsyntax as rs
def make_details():
layoutNames = []
page_views = sc.doc.Views.GetPageViews()
for page_view in page_views:
layoutNames.append(page_view.PageName)
layoutName = rs.ComboListBox(layoutNames, "Select layout")
if layoutName == None:
return()
if layoutName:
for page_no in range(len(layoutNames)):
if(layoutNames[page_no] == layoutName):
layout = page_views[page_no]
if layout:
sc.doc.Views.ActiveView = layout
sc.doc.Views.Redraw()
if __name__ == "__main__":
pageview = sc.doc.Views.ActiveView
if type(pageview) == Rhino.Display.RhinoPageView:
print "This tool only works in the model space."
else:
make_details()