Hello,
I’m sharing a workaround for opening several Views with Revit API and Winform.
The Python script (IronPython) must be placed at the end of the chain and accepts a list of views as input.
an example with a duplication of views
more explanations here
#written by Cyril P
import clr
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
uidoc = uiapp.ActiveUIDocument
clr.AddReference('System.Drawing')
clr.AddReference('System.Windows.Forms')
import System.Drawing
import System.Windows.Forms
from System.Drawing import *
from System.Windows.Forms import *
class MainForm(Form):
def __init__(self, listView, uidoc):
self._dictView = {x.Name : x for x in listView}
self._uidoc = uidoc
self.InitializeComponent()
self.CheckPreselect()
def InitializeComponent(self):
self._checkedListBox1 = System.Windows.Forms.CheckedListBox()
self._buttonOpen = System.Windows.Forms.Button()
self.SuspendLayout()
#
# checkedListBox1
self._checkedListBox1.FormattingEnabled = True
self._checkedListBox1.Items.AddRange(System.Array[System.Object](self._dictView.keys()))
self._checkedListBox1.Location = System.Drawing.Point(24, 27)
self._checkedListBox1.Name = "checkedListBox1"
self._checkedListBox1.Size = System.Drawing.Size(340, 440)
self._checkedListBox1.TabIndex = 0
#
# buttonOpen
self._buttonOpen.Location = System.Drawing.Point(24, 480)
self._buttonOpen.Name = "buttonOpen"
self._buttonOpen.Size = System.Drawing.Size(234, 53)
self._buttonOpen.TabIndex = 1
self._buttonOpen.Text = "Opens Select Views"
self._buttonOpen.UseVisualStyleBackColor = True
self._buttonOpen.Click += self.ButtonOpenClick
#
# MainForm
self.ClientSize = System.Drawing.Size(400, 550)
self.Controls.Add(self._buttonOpen)
self.Controls.Add(self._checkedListBox1)
self.Name = "MainForm"
self.Text = "UI_OpenMulti"
self.ResumeLayout(False)
def CheckPreselect(self):
for i in range(self._checkedListBox1.Items.Count):
self._checkedListBox1.SetItemChecked(i, True)
def ButtonOpenClick(self, sender, e):
for viewName in self._checkedListBox1.CheckedItems :
view = self._dictView.get(viewName)
self._uidoc.ActiveView = view
self.Close()
lstView = UnwrapElement(IN[0])
objForm = MainForm(lstView, uidoc)
objForm.Show()
OUT = 0