public BeamTypeCorrectForm(UIDocument uidoc, ExternalEvent exEvent, ChangeBeamFamilyTypeEvent handler) { InitializeComponent(); _uidoc = uidoc; _doc = _uidoc.Document; _exEvent = exEvent; _handler = handler; }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { if (null == _hWndRevit) { Process[] processes = Process.GetProcessesByName("Revit"); if (0 < processes.Length && processes.Any(p => p == Process.GetCurrentProcess())) { IntPtr h = Process.GetCurrentProcess().MainWindowHandle; _hWndRevit = new WindowHandle(h); } } _uiapp = commandData.Application; _uidoc = _uiapp.ActiveUIDocument; _doc = _uidoc.Document; // Retrieve data from revit document and add to the data grid view try { ChangeBeamFamilyTypeEvent handler = new ChangeBeamFamilyTypeEvent(); _exEvent = ExternalEvent.Create(handler); _form = new BeamTypeCorrectForm(_uidoc, _exEvent, handler); // Capture the error of no-host beam bool allBeamsHaveHost = !new FilteredElementCollector(_doc) .OfCategory(BuiltInCategory.OST_StructuralFraming) .OfClass(typeof(FamilyInstance)) .Cast <FamilyInstance>() .Any(beam => beam.Host == null); if (!allBeamsHaveHost) { TaskDialog.Show("Revit", "Il y a des poutres qui n'ont pas de Host"); return(Result.Cancelled); } // TODO : Extract GetAllStructuralLevels the methode // Get list of all structural levels IList <Level> strLevels = (from lev in new FilteredElementCollector(_doc) .OfClass(typeof(Level)) where lev.GetEntitySchemaGuids().Count != 0 select lev) .Cast <Level>() .OrderBy(l => l.Elevation) .ToList(); if (strLevels.Count == 0) { TaskDialog.Show("Revit", "Configurer les niveaux structuraux avant de lancer cette commande."); return(Result.Cancelled); } TreatBeamsToBeAsNormal(); TreatBeamsToBeAsGroundBeam(); TreatUnsupportedWalls(strLevels); } catch (Exception e) { message = e.Message; return(Result.Failed); } _form.Show(_hWndRevit); return(Result.Succeeded); }