public static Result CreateSpaceSyntaxAnalysisResult(Document doc, SpaceSyntax spaceSyntax, Face face) { // A (default) AnalysisDisplayStyle must exist, otherwise Revit does not know how to display/interpret anything ActivateAnalysisDisplayStyle(doc); using (var transaction = new Transaction(doc, "SpaceSyntax Visualization")) { transaction.Start(); try { CreateSpaceSyntaxAnalysisResult(doc, spaceSyntax, face, face.Reference); transaction.Commit(); return(Result.Succeeded); } catch (Exception e) { PromtService.ShowErrorToUser(e.ToString()); transaction.RollBack(); return(Result.Failed); } } }
public static KeyValuePair <Result, SpaceSyntax> PromtUserForSpaceSyntaxXml() { var openFileDialog = new OpenFileDialog(); openFileDialog.InitialDirectory = "%USER%"; openFileDialog.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*"; openFileDialog.FilterIndex = 1; openFileDialog.RestoreDirectory = true; if (!(openFileDialog.ShowDialog() == DialogResult.OK)) { PromtService.ShowInformationToUser("SpaceSyntax Addin cancelled by user."); return(new KeyValuePair <Result, SpaceSyntax>(Result.Cancelled, null)); } if (!openFileDialog.CheckFileExists) { PromtService.ShowInformationToUser("File does not exist."); return(new KeyValuePair <Result, SpaceSyntax>(Result.Failed, null)); } XmlSerializer xmlDeserializer = null; try { xmlDeserializer = new XmlSerializer(typeof(SpaceSyntax)); } catch (Exception) { PromtService.ShowErrorToUser("The provided xml file could not be parsed correctly."); return(new KeyValuePair <Result, SpaceSyntax>(Result.Failed, null)); } var spaceSyntax = (SpaceSyntax)xmlDeserializer.Deserialize(openFileDialog.OpenFile()); return(new KeyValuePair <Result, SpaceSyntax>(Result.Succeeded, spaceSyntax)); }
public static KeyValuePair <Result, Level> LetUserPickLevelFromDialog(Document doc) { FilteredElementCollector levelCollector = new FilteredElementCollector(doc); ICollection <Element> levelCollection = levelCollector.OfClass(typeof(Level)).ToElements(); var levels = new List <Level>(); foreach (Element element in levelCollection) { Level level = element as Level; if (level != null) { levels.Add(level); } } if (levels.Count == 0) { PromtService.ShowErrorToUser("The project does not contain any levels."); return(new KeyValuePair <Result, Level>(Result.Failed, null)); } return(OpenLevelSelector(levels)); }
public static KeyValuePair <Result, PlanarFace> GetTopFaceFromLevel(Application app, Level level) { var allFloorsForLevel = GetAllFloorsFromSelectedLevel(level); var allFaces = CollectAllFacesFromAllFloors(app, allFloorsForLevel); if (allFaces.Count == 0) { PromtService.ShowErrorToUser("No Surfaces for visualization found!"); return(new KeyValuePair <Result, PlanarFace>(Result.Failed, null)); } // For now we assume: We select the both Faces with the biggest Area // from the floors (which is assumed to be top and bottom face of the same floor element) var topAndBottomFaces = FilterTwoFacesWithBiggestArea(allFaces); var topFace = FilterTopFace(topAndBottomFaces); if (topFace == null) { PromtService.ShowInformationToUser("The top of the surface could not be determined. Visualization failed."); return(new KeyValuePair <Result, PlanarFace>(Result.Failed, null)); } return(new KeyValuePair <Result, PlanarFace>(Result.Succeeded, topFace));; }