I am trying to get Sheet Names, Number & Revision in DataGrid tried various sample code tried even ChatGPT but no solution. I am able to retrieve data but unable to show it in DataGrid.
Tried creating basic one column and adding Sheet Names in DataGrid still not working
import clr
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import FilteredElementCollector, ViewSheet
clr.AddReference("System.Windows.Forms")
clr.AddReference("System.Drawing")
from System.Windows.Forms import Application, Form, DataGridView, DataGridViewAutoSizeColumnsMode
from System.Drawing import Size, Point
doc = _revit_.ActiveUIDocument.Document
# Get all sheets in the project
sheets = FilteredElementCollector(doc).OfClass(ViewSheet).ToElements()
sheet_names = [sheet.Name for sheet in sheets]
class SheetNameForm(Form):
def _init_(self):
self.Text = 'Revit Sheet Names'
self.Size = Size(400, 500)
self.dataGridView = DataGridView()
self.dataGridView.Location = Point(10, 10)
self.dataGridView.Size = Size(380, 450)
self.dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
self.dataGridView.DataSource = sheet_names
self.dataGridView.Columns[0].Name = "Sheet Names"
self.Controls.Add(self.dataGridView)
# Create and show the form
form = SheetNameForm()
Application.Run(form)