private SpatialFieldManager SetSpatialFieldManager(Autodesk.Revit.DB.View view, out int index) { SpatialFieldManager sfm = null; index = -1; try { sfm = SpatialFieldManager.GetSpatialFieldManager(view); using (Transaction trans = new Transaction(m_doc)) { trans.Start("Create Spatial Manager"); try { if (null == sfm) { sfm = SpatialFieldManager.CreateSpatialFieldManager(view, 1); List <string> names = new List <string>(); List <string> descriptions = new List <string>(); names.Add("Visibility Index"); descriptions.Add("0: area with no views, 1: area with views"); sfm.SetMeasurementNames(names); sfm.SetMeasurementDescriptions(descriptions); } IList <int> resultIndices = sfm.GetRegisteredResults(); foreach (int i in resultIndices) { AnalysisResultSchema resultSchema = sfm.GetResultSchema(i); if (resultSchema.Name == "View Analysis") { index = i; } } if (index == -1) { AnalysisResultSchema resultSchema = new AnalysisResultSchema("View Analysis", "Calculating area with views"); index = sfm.RegisterResult(resultSchema); } trans.Commit(); } catch (Exception ex) { string message = ex.Message; trans.RollBack(); } } } catch (Exception ex) { MessageBox.Show("Set Spatial Field Manager.\n" + ex.Message, "Set Spatial Field Manager", MessageBoxButton.OK, MessageBoxImage.Warning); } return(sfm); }
private void HideExistingAnalysis() { SpatialFieldManager sfm = SpatialFieldManager.GetSpatialFieldManager(doc.ActiveView); if (sfm != null) { IList <int> regIndices = sfm.GetRegisteredResults(); foreach (int i in regIndices) { AnalysisResultSchema result = sfm.GetResultSchema(i); result.IsVisible = false; sfm.SetResultSchema(i, result); } } }
private int FindIndexOfResult(SpatialFieldManager sfm) { int index = 0; overwriteResult = false; IList <int> regIndices = sfm.GetRegisteredResults(); foreach (int i in regIndices) { AnalysisResultSchema result = sfm.GetResultSchema(i); if (result.Name == settings.LegendTitle) { index = i; overwriteResult = true; break; } } return(index); }
private void DisplayExisitingResults() { listViewResults.Items.Clear(); SpatialFieldManager sfm = SpatialFieldManager.GetSpatialFieldManager(doc.ActiveView); if (sfm != null) { IList <int> regIndices = sfm.GetRegisteredResults(); foreach (int i in regIndices) { AnalysisResultSchema result = sfm.GetResultSchema(i); ListViewItem item = new ListViewItem(result.Name); item.Name = result.Name; item.Tag = result; item.Checked = result.IsVisible; listViewResults.Items.Add(item); } } }
/// <summary> /// Get the AnalysisResultsSchemaIndex for the SpatialFieldManager /// </summary> /// <returns></returns> protected int GetAnalysisResultSchemaIndex() { // Get the AnalysisResultSchema index - there is only one for Dynamo var schemaIndex = 0; if (!SpatialFieldManager.IsResultSchemaNameUnique(AbstractAnalysisDisplay.ResultsSchemaName, -1)) { var arses = SpatialFieldManager.GetRegisteredResults(); schemaIndex = arses.First( x => SpatialFieldManager.GetResultSchema(x).Name == AbstractAnalysisDisplay.ResultsSchemaName); } else { var ars = new AnalysisResultSchema(AbstractAnalysisDisplay.ResultsSchemaName, "Resulting analyses from Dynamo."); schemaIndex = SpatialFieldManager.RegisterResult(ars); } return(schemaIndex); }
/// <summary> /// Get the AnalysisResultsSchemaIndex for the SpatialFieldManager /// </summary> /// <returns></returns> protected virtual int GetAnalysisResultSchemaIndex(string resultsSchemaName, string resultsDescription, Type unitType) { // Get the AnalysisResultSchema index - there is only one for Dynamo var schemaIndex = 0; if (!SpatialFieldManager.IsResultSchemaNameUnique(resultsSchemaName, -1)) { var arses = SpatialFieldManager.GetRegisteredResults(); schemaIndex = arses.First( x => SpatialFieldManager.GetResultSchema(x).Name == resultsSchemaName); } else { var ars = new AnalysisResultSchema(resultsSchemaName, resultsDescription); if (unitType != null) { if (typeof(SIUnit).IsAssignableFrom(unitType)) { var prop = unitType.GetProperty("Conversions"); var conversions = (Dictionary <string, double>)prop.GetValue(null, new object[] { }); if (conversions != null) { var unitNames = conversions.Keys.ToList(); var multipliers = conversions.Values.ToList(); ars.SetUnits(unitNames, multipliers); ars.CurrentUnits = 0; } } } schemaIndex = SpatialFieldManager.RegisterResult(ars); } return(schemaIndex); }
private static int registerResults(SpatialFieldManager sfm, string name, string description) { IList <int> results = sfm.GetRegisteredResults(); if ((results != null) && (results.Count > 0)) { for (int i = 0; i < results.Count; i++) { try { if (sfm.GetResultSchema(i).Name.ToUpper() == name.ToUpper()) { return(i); } } catch { } // ran into cases in 2015 where this produced "Non-existent schema" } } AnalysisResultSchema resultSchema1 = new AnalysisResultSchema(name, description); int result = sfm.RegisterResult(resultSchema1); return(result); }