Message 1 of 14
Not applicable
09-13-2017
06:27 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I want to create a combo box within a windows form that will show a list of all 3D views in the project (I am just testing combo boxes to use them in one of my add-ins).
When
When I run the external command the form shows up but the combo box is empty. I have searched a lot on this forum and other websites and cannot figure out what I am doing wrong.
This is the code of the external command:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
namespace Drop_Down_List_Test
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class ViewList : IExternalCommand
{
static AddInId appId = new AddInId(new Guid("536B73F0-36BF-4CBC-8CF9-EF0E7E210A90"));
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elementSet)
{
UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
using (ViewListForm thisForm = new ViewListForm())
{
thisForm.ShowDialog();
if (thisForm.DialogResult == System.Windows.Forms.DialogResult.Cancel)
{
return Result.Cancelled;
}
}
return Result.Succeeded;
}
}
}
And this is the code of the windows form:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System.IO;
namespace Drop_Down_List_Test
{
public partial class ViewListForm : System.Windows.Forms.Form
{
public Document doc;
public ViewListForm()
{
InitializeComponent();
}
private void ViewListForm_Load(object sender, EventArgs e)
{
FilteredElementCollector fec = new FilteredElementCollector(doc).OfClass(typeof(View3D));
foreach (Element elem in fec)
{
View3D v = elem as View3D;
if (!v.IsTemplate)
cbViewList.Items.Add(v.Name);
}
cbViewList.DisplayMember = "ViewName";
}
private void cbViewList_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}Below screen grab of the 'empty' form after executing the command in Revit.
If you could help me that would be great.
Thanks.
Solved! Go to Solution.