示例#1
0
        public Result Execute(
            ExternalCommandData commandData, 
            ref string message, 
            ElementSet elements)
        {
            // Get application and document objects
            UIApplication uiApp = commandData.Application;
            Document doc = uiApp.ActiveUIDocument.Document;
            UIDocument uidoc = uiApp.ActiveUIDocument;

            try
            {
                IList<Reference> refs = null;
                LegendScheduleFilter selFilter = new LegendScheduleFilter(doc);

                Selection sel = uidoc.Selection;
                refs = sel.PickObjects(ObjectType.Element, selFilter, "Select Legends and/or Schedules only.");

                InputData inData = new InputData(doc, refs);
                LegendDuplicatorForm form = new LegendDuplicatorForm(inData);
                form.ShowDialog();

                return Result.Succeeded;
            }
            // Catch any exceptions and display them
            catch (Autodesk.Revit.Exceptions.OperationCanceledException)
            {
                return Result.Cancelled;
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return Result.Failed;
            }
        }
        public LegendDuplicatorForm(InputData inputData)
        {
            this.inputData = inputData;

            InitializeComponent();

            // populate data grid view with sheets
            SortableBindingList<SheetWrapper> sheetBindingList = new SortableBindingList<SheetWrapper>();
            foreach (SheetWrapper sw in inputData.Sheets)
            {
                sheetBindingList.Add(sw);
            }
            dgvSheets.AutoGenerateColumns = false;
            dgvSheets.DataSource = sheetBindingList;

        }