private static IList <RvtElement> GetSelectedSets(ListBox listBox, string cbName) { IList <RvtElement> theSelected = new List <RvtElement>(); for (int i = 0; i < listBox.Items.Count; ++i) { ListBoxItem lbItem = (ListBoxItem)listBox. ItemContainerGenerator.ContainerFromIndex(i); if (lbItem == null) { continue; } ContentPresenter contentPresenter = ExportImportExcel.FindVisualChild <ContentPresenter>(lbItem); DataTemplate dataTemplate = contentPresenter.ContentTemplate; CheckBox checkBox = (CheckBox)dataTemplate .FindName(cbName, contentPresenter); if ((bool)checkBox.IsChecked) { theSelected.Add(listBox.Items[i] as RvtElement); } } return(theSelected); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { // Add an EventLogTraceListener object Trace.Listeners.Add(new EventLogTraceListener("Application")); // Lay hands on the active document UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; Timing myTimer = new Timing(); myTimer.StartTime(); try { // Show the export window ExportImportExcel exportWindow = new ExportImportExcel(GetAllSchedules(doc)); exportWindow.ShowDialog(); return(Result.Succeeded); } catch (Autodesk.Revit.Exceptions.OperationCanceledException) { return(Result.Cancelled); } catch (Exception ex) { TaskDialog.Show("Exception", string.Format("{0}\n{1}", ex.Message, ex.StackTrace)); return(Result.Failed); } finally { myTimer.StopTime(); Trace.Write(string.Format("Time elapsed: {0}s", myTimer.Duration.TotalSeconds)); } }