Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi everybody,
i'm searching for a solution to my problem. I'm trying to add all the Revit Categories to a Checked List Box in a Windows Form in order to select them and obtain the selected categories from the form.
Unfortunately, i'm stuck at the creation of the list in the box.
Here is the FORM code:
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
namespace LP_Parameters.Commands
{
public partial class Form1 : System.Windows.Forms.Form
{
//Revit references
public UIApplication rvtUiApp;
public UIDocument rvtUiDoc;
public Autodesk.Revit.ApplicationServices.Application rvtApp;
public Form1()
{
InitializeComponent();
}
public Form1(ExternalCommandData commandData)
{
//Revit references
rvtUiApp = commandData.Application;
rvtUiDoc = rvtUiApp.ActiveUIDocument;
rvtApp = rvtUiApp.Application;
InitializeComponent();
}
private void checkedListBox1_Load(object sender, EventArgs e)
{
Document rvtDoc = rvtUiDoc.Document;
Categories cat = rvtDoc.Settings.Categories;
SortedList<string, Category> myCategories = new SortedList<string, Category>();
myCategories.Clear();
foreach (Category c in cat)
{
if (c.AllowsBoundParameters)
myCategories.Add(c.Name, c);
}
checkedListBox1.DataSource = myCategories;
checkedListBox1.DisplayMember = "Name";
}
private void OKbtn_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.OK;
Close();
}
private void Cancelbtn_Click(object sender, EventArgs e)
{
Close();
}
}
}
The error when i run it in Revit is the following:
It seems that the error is at line 39, where i define the rvtDoc variable:
Any idea about what am i doing wrong?
Thank you very much to everybody, you are always really helpful!
Solved! Go to Solution.