/// <summary> /// Getting ready to preform an analysis for the given in view /// </summary> /// <remarks> /// This initializes the Spatial Field Manager, /// adds a field primitive corresponding to the face, /// and registers our result schema we want to use. /// The method clears any previous results in the view. /// </remarks> /// public void Initialize() { // create of get field manager for the view m_SFManager = SpatialFieldManager.GetSpatialFieldManager(m_view); if (m_SFManager == null) { m_SFManager = SpatialFieldManager.CreateSpatialFieldManager(m_view, 1); } // For the sake of simplicity, we remove any previous results m_SFManager.Clear(); // register schema for the results AnalysisResultSchema schema = new AnalysisResultSchema("E4623E91-8044-4721-86EA-2893642F13A9", "SDK2014-AL, Sample Schema"); m_schemaId = m_SFManager.RegisterResult(schema); // Add a spatial field for our face reference m_fieldId = m_SFManager.AddSpatialFieldPrimitive(GetReference()); m_needInitialization = false; }
/// <summary> /// Initialise the external webcam event driver. /// </summary> public static void Start(View view, Reference r) { _faceReference = r; SpatialFieldManager sfm = SpatialFieldManager.GetSpatialFieldManager( view); if (null == sfm) { sfm = SpatialFieldManager .CreateSpatialFieldManager(view, 1); } else if (0 < _sfp_index) { sfm.RemoveSpatialFieldPrimitive( _sfp_index); _sfp_index = -1; } _sfp_index = sfm.AddSpatialFieldPrimitive( _faceReference); _event = ExternalEvent.Create( new WebcamEventHandler()); Thread thread = new Thread( new ThreadStart(Run)); thread.Start(); }
/// <summary> /// Prepares a container object that carries out the calculations without invoking Revit API calls. /// </summary> /// <param name="element">The element for the calculations.</param> /// <returns>The container.</returns> public static MultithreadedCalculationContainer CreateContainer(Element element) { Document doc = element.Document; View activeView = doc.GetElement(s_activeViewId) as View; // Figure out which is the largest face facing the user XYZ viewDirection = activeView.ViewDirection.Normalize(); Face biggestFace = GetBiggestFaceFacingUser(element, viewDirection); // Get or create SpatialFieldManager for AVF results SpatialFieldManager sfm = SpatialFieldManager.GetSpatialFieldManager(activeView); if (sfm == null) { sfm = SpatialFieldManager.CreateSpatialFieldManager(activeView, 1); } // Reference the target face s_spatialFieldId = sfm.AddSpatialFieldPrimitive(biggestFace.Reference); // Compute the range of U and V for the calculation BoundingBoxUV bbox = biggestFace.GetBoundingBox(); return(new MultithreadedCalculationContainer(doc.PathName, bbox.Min, bbox.Max)); }
/// <summary> /// Get the SpatialFieldManager for a particular view. This is a singleton for every view. Note that the /// number of values per analysis point is ignored if the SpatialFieldManager has already been obtained /// for this view. This field cannot be mutated once the SpatialFieldManager is set for a partiular /// view. /// </summary> /// <param name="view"></param> /// <param name="numValuesPerAnalysisPoint"></param> /// <returns></returns> protected static SpatialFieldManager GetSpatialFieldManagerFromView(Autodesk.Revit.DB.View view, uint numValuesPerAnalysisPoint = 1) { if (view == null) { throw new ArgumentNullException("view"); } TransactionManager.Instance.EnsureInTransaction(Document); var sfm = SpatialFieldManager.GetSpatialFieldManager(view); if (sfm == null) { sfm = SpatialFieldManager.CreateSpatialFieldManager(view, (int)numValuesPerAnalysisPoint); } else { // If the number of values stored // at each location is not equal to what we are requesting, // then create a new SFM if (sfm.NumberOfMeasurements != numValuesPerAnalysisPoint) { DocumentManager.Instance.CurrentDBDocument.Delete(sfm.Id); sfm = SpatialFieldManager.CreateSpatialFieldManager(view, (int)numValuesPerAnalysisPoint); } } TransactionManager.Instance.TransactionTaskDone(); return(sfm); }
public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { ExternalCommandData cdata = commandData; Autodesk.Revit.ApplicationServices.Application app = commandData.Application.Application; Document doc = commandData.Application.ActiveUIDocument.Document; UIDocument uiDoc = commandData.Application.ActiveUIDocument; Transaction trans = new Transaction(doc, "Revit.SDK.Samples.AnalysisVisualizationFramework"); trans.Start(); SpatialFieldManager sfm = SpatialFieldManager.GetSpatialFieldManager(doc.ActiveView); if (sfm == null) { sfm = SpatialFieldManager.CreateSpatialFieldManager(doc.ActiveView, 1); } IList <Reference> refList = new List <Reference>(); refList = uiDoc.Selection.PickObjects(Autodesk.Revit.UI.Selection.ObjectType.Face); foreach (Reference reference in refList) { IList <UV> uvPts = new List <UV>(); List <double> doubleList = new List <double>(); IList <ValueAtPoint> valList = new List <ValueAtPoint>(); Face face = doc.GetElement(reference).GetGeometryObjectFromReference(reference) as Face; BoundingBoxUV bb = face.GetBoundingBox(); UV min = bb.Min; UV max = bb.Max; for (double u = min.U; u < max.U; u += (max.U - min.U) / 10) { for (double v = min.V; v < max.V; v += (max.V - min.V) / 10) { UV uv = new UV(u, v); if (face.IsInside(uv)) { uvPts.Add(uv); doubleList.Add(v + DateTime.Now.Second); valList.Add(new ValueAtPoint(doubleList)); doubleList.Clear(); } } } FieldDomainPointsByUV pnts = new FieldDomainPointsByUV(uvPts); FieldValues vals = new FieldValues(valList); int idx = sfm.AddSpatialFieldPrimitive(reference); AnalysisResultSchema resultSchema = new AnalysisResultSchema("Schema 1", "Schema 1 Description"); sfm.UpdateSpatialFieldPrimitive(idx, pnts, vals, sfm.RegisterResult(resultSchema)); } trans.Commit(); return(Result.Succeeded); }
// Execution method for the updater public void Execute(UpdaterData data) { // Remove old idling event callback UIApplication uiApp = new UIApplication(data.GetDocument().Application); uiApp.Idling -= containerOld.UpdateWhileIdling; containerOld.Stop(); // Clear the current AVF results Document doc = data.GetDocument(); View activeView = doc.GetElement(s_activeViewId) as View; SpatialFieldManager sfm = SpatialFieldManager.GetSpatialFieldManager(activeView); sfm.Clear(); // Restart the multithread calculation with a new container Element modifiedElem = doc.GetElement(data.GetModifiedElementIds().First <ElementId>()); MultithreadedCalculationContainer container = MultithreadedCalculation.CreateContainer(modifiedElem); containerOld = container; // Setup the new idling callback uiApp.Idling += new EventHandler <IdlingEventArgs>(container.UpdateWhileIdling); // Start the thread Thread threadNew = new Thread(new ThreadStart(container.Run)); threadNew.Start(); }
internal static void Clear(Autodesk.Revit.UI.UIDocument uiDoc) { Document doc = uiDoc.Document; Transaction t = null; if (doc.IsModifiable == false) { t = new Transaction(doc, "Clear Visualizations"); t.Start(); } SpatialFieldManager sfm = null; sfm = SpatialFieldManager.GetSpatialFieldManager(uiDoc.ActiveGraphicalView); if (sfm == null) { sfm = SpatialFieldManager.CreateSpatialFieldManager(uiDoc.ActiveGraphicalView, 1); } sfm.Clear(); if (t != null) { t.Commit(); } }
public void PaintSolid(Document doc, Solid s, double value) { int schemaId = -1; var rnd = new Random(); View view = doc.ActiveView; using (Transaction transaction = new Transaction(doc)) { if (transaction.Start("Create model curves") == TransactionStatus.Started) { if (view.AnalysisDisplayStyleId == ElementId.InvalidElementId) { CreateAVFDisplayStyle(doc, view); } SpatialFieldManager sfm = SpatialFieldManager.GetSpatialFieldManager(view); if (null == sfm) { sfm = SpatialFieldManager.CreateSpatialFieldManager(view, 1); } if (-1 != schemaId) { IList <int> results = sfm.GetRegisteredResults(); if (!results.Contains(schemaId)) { schemaId = -1; } } if (-1 == schemaId) { AnalysisResultSchema resultSchema1 = new AnalysisResultSchema(rnd.Next().ToString(), "Description"); schemaId = sfm.RegisterResult(resultSchema1); } FaceArray faces = s.Faces; Transform trf = Transform.Identity; foreach (Face face in faces) { int idx = sfm.AddSpatialFieldPrimitive(face, trf); IList <UV> uvPts = new List <UV>(); List <double> doubleList = new List <double>(); IList <ValueAtPoint> valList = new List <ValueAtPoint>(); BoundingBoxUV bb = face.GetBoundingBox(); uvPts.Add(bb.Min); doubleList.Add(value); valList.Add(new ValueAtPoint(doubleList)); FieldDomainPointsByUV pnts = new FieldDomainPointsByUV(uvPts); FieldValues vals = new FieldValues(valList); sfm.UpdateSpatialFieldPrimitive(idx, pnts, vals, schemaId); } transaction.Commit(); } } }
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); }
public SpatialFieldManager GetSpatialFieldManager(int numOfMeasurments) { var sfm = SpatialFieldManager.GetSpatialFieldManager(this.RevitView); if (null == sfm || sfm.NumberOfMeasurements != numOfMeasurments) { sfm = SpatialFieldManager.CreateSpatialFieldManager(this.RevitView, numOfMeasurments); } return(sfm); }
private void bttnRemove_Click(object sender, EventArgs e) { DialogResult dr = MessageBox.Show("Would you like to remove all Analysis Results of the current view?", "Remove All Analysis Results", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { SpatialFieldManager sfm = SpatialFieldManager.GetSpatialFieldManager(doc.ActiveView); sfm.Clear(); } }
internal static void ShowSolids(Document doc, IEnumerable <Solid> solids, IEnumerable <double> values) { SpatialFieldManager sfm = SpatialFieldManager.GetSpatialFieldManager(doc.ActiveView); if (sfm == null) { sfm = SpatialFieldManager.CreateSpatialFieldManager(doc.ActiveView, 1); } if (_SchemaId != -1) { IList <int> results = sfm.GetRegisteredResults(); if (!results.Contains(_SchemaId)) { _SchemaId = -1; } } if (_SchemaId == -1) { _SchemaId = registerResults(sfm, "ShowChanges", "Description"); } List <double> valueList = values.ToList(); int i = 0; foreach (Solid s in solids) { double value = valueList[i]; i++; FaceArray faces = s.Faces; Transform trf = Transform.Identity; foreach (Face face in faces) { int idx = sfm.AddSpatialFieldPrimitive(face, trf); IList <UV> uvPts = new List <UV>(); List <double> doubleList = new List <double>(); IList <ValueAtPoint> valList = new List <ValueAtPoint>(); BoundingBoxUV bb = face.GetBoundingBox(); uvPts.Add(bb.Min); doubleList.Add(value); valList.Add(new ValueAtPoint(doubleList)); FieldDomainPointsByUV pnts = new FieldDomainPointsByUV(uvPts); FieldValues vals = new FieldValues(valList); sfm.UpdateSpatialFieldPrimitive(idx, pnts, vals, _SchemaId); } } updateView(doc.ActiveView, StyleEnum.Faces); }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { try { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; View view = doc.ActiveView; // maybe has to be 3D Reference r = uidoc.Selection.PickObject( ObjectType.Face, new BimElementFilter(), _prompt); Debug.Assert(null != r, "expected non-null reference from PickObject"); Debug.Assert(null != r.Element, "expected non-null element from PickObject"); Debug.Assert(null != r.GeometryObject, "expected non-null geometry object from PickObject"); _faceReference = r; SpatialFieldManager sfm = SpatialFieldManager.GetSpatialFieldManager( view); if (null != sfm && 0 < _sfp_index) { sfm.RemoveSpatialFieldPrimitive( _sfp_index); _sfp_index = -1; } SetAnalysisDisplayStyle(doc); uiapp.Idling += new EventHandler <IdlingEventArgs>( OnIdling); return(Result.Succeeded); } catch (Exception ex) { message = ex.Message; return(Result.Failed); } }
/// <summary> /// Set up the AVF spatial field manager /// for the given view. /// </summary> static void SetUpAvfSfm( View view, Reference faceReference) { if (view.AnalysisDisplayStyleId == ElementId.InvalidElementId) { SetAvfDisplayStyle(view); } _sfm = SpatialFieldManager .GetSpatialFieldManager(view); if (null == _sfm) { _sfm = SpatialFieldManager .CreateSpatialFieldManager(view, 1); } else if (0 < _sfp_index) { _sfm.RemoveSpatialFieldPrimitive( _sfp_index); } _sfp_index = _sfm.AddSpatialFieldPrimitive( faceReference); if (-1 != _schemaId) { IList <int> results = _sfm.GetRegisteredResults(); if (!results.Contains(_schemaId)) { _schemaId = -1; } } if (-1 == _schemaId) { AnalysisResultSchema schema = new AnalysisResultSchema("Attenuation", "RvtFader signal attenuation"); List <string> unitNames = new List <string>(new string[1] { "dB" }); List <double> unitFactors = new List <double>(new double[1] { 1.0 }); schema.SetUnits(unitNames, unitFactors); _schemaId = _sfm.RegisterResult(schema); } }
public static Element RequestAnalysisResultInstanceSelection(string message) { var doc = dynRevitSettings.Doc; try { View view = doc.ActiveView as View; SpatialFieldManager sfm = SpatialFieldManager.GetSpatialFieldManager(view); Element AnalysisResult; if (sfm != null) { sfm.GetRegisteredResults(); Autodesk.Revit.UI.Selection.Selection choices = doc.Selection; choices.Elements.Clear(); //MessageBox.Show(message); DynamoLogger.Instance.Log(message); Reference fsRef = doc.Selection.PickObject(ObjectType.Element); if (fsRef != null) { AnalysisResult = doc.Document.GetElement(fsRef.ElementId) as Element; if (AnalysisResult != null) { return(AnalysisResult); } else { return(null); } } else { return(null); } } else { return(null); } } catch (Exception ex) { DynamoLogger.Instance.Log(ex); return(null); } }
public static Element RequestAnalysisResultInstanceSelection(UIDocument doc, string message, dynElementSettings settings) { try { View view = doc.ActiveView as View; SpatialFieldManager sfm = SpatialFieldManager.GetSpatialFieldManager(view); Element AnalysisResult; if (sfm != null) { sfm.GetRegisteredResults(); Selection choices = doc.Selection; choices.Elements.Clear(); //MessageBox.Show(message); settings.Bench.Log(message); Reference fsRef = doc.Selection.PickObject(ObjectType.Element); if (fsRef != null) { AnalysisResult = doc.Document.get_Element(fsRef.ElementId) as Element; if (AnalysisResult != null) { return(AnalysisResult); } else { return(null); } } else { return(null); } } else { return(null); } } catch (Exception ex) { settings.Bench.Log(ex.Message); return(null); } }
private void VerifyNoSpatialFieldManager() { var doc = DocumentManager.Instance.CurrentDBDocument; var view = doc.ActiveView; TransactionManager.Instance.EnsureInTransaction(doc); var sfm = SpatialFieldManager.GetSpatialFieldManager(view); Assert.Null(sfm); TransactionManager.Instance.TransactionTaskDone(); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { var uiApp = commandData.Application; var doc = uiApp.ActiveUIDocument.Document; SetStatusText("Updating CO2e visualisation..."); var view = new ViewFinder(doc).Get3DViewNamed("CO2e"); if (view == null) { TaskDialog.Show("Error", "A 3D view named 'CO2e' must exist to view the AMEE CO2e visualization."); return(Result.Failed); } new AnalysisDisplayStyles().SetCO2eAnalysisDisplayStyle(view); var sfm = SpatialFieldManager.GetSpatialFieldManager(view); if (sfm == null) { sfm = SpatialFieldManager.CreateSpatialFieldManager(view, 1); // One measurement value for each point } sfm.Clear(); var sw = new Stopwatch(); sw.Start(); var collector = new FilteredElementCollector(doc, view.Id); ICollection <Element> co2eElements = collector.WherePasses(Settings.CreateFilterForElementsWithCO2eParameter()).WhereElementIsNotElementType().ToElements(); var count = 0; foreach (var element in co2eElements) { if (count++ > 200) { logger.InfoFormat("Skipping CO2e visualisation update for element {0} since we have already updated more than 200", element.Name); continue; } SetStatusText("Updating CO2e visualisation for element {0}...", element.Name); CO2eVisualisationCreator.UpdateCO2eVisualization(sfm, element); } sw.Stop(); SetStatusText("Updated all CO2e visualisations in {0}", sw.Elapsed); logger.InfoFormat("Updated all CO2e visualisations in {0}", sw.Elapsed); return(Result.Succeeded); }
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); } } }
/// <summary> /// Paint solid by AVF /// </summary> /// <param name="solid">Solid to be painted</param> /// <param name="view">The view that shows solid</param> private void PaintSolid(Solid solid, View view) { String viewName = view.Name; SpatialFieldManager sfm = SpatialFieldManager.GetSpatialFieldManager(view); if (sfm == null) { sfm = SpatialFieldManager.CreateSpatialFieldManager(view, 1); } if (m_schemaId != -1) { IList <int> results = sfm.GetRegisteredResults(); if (!results.Contains(m_schemaId)) { m_schemaId = -1; } } // set up the display style if (m_schemaId == -1) { AnalysisResultSchema resultSchema1 = new AnalysisResultSchema("PaintedSolid " + viewName, "Description"); AnalysisDisplayStyle displayStyle = AnalysisDisplayStyle.CreateAnalysisDisplayStyle(this.RevitDoc, "Real_Color_Surface" + viewName, new AnalysisDisplayColoredSurfaceSettings(), new AnalysisDisplayColorSettings(), new AnalysisDisplayLegendSettings()); resultSchema1.AnalysisDisplayStyleId = displayStyle.Id; m_schemaId = sfm.RegisterResult(resultSchema1); } // get points of all faces in the solid FaceArray faces = solid.Faces; Transform trf = Transform.Identity; foreach (Face face in faces) { int idx = sfm.AddSpatialFieldPrimitive(face, trf); IList <UV> uvPts = null; IList <ValueAtPoint> valList = null; ComputeValueAtPointForFace(face, out uvPts, out valList, 1); FieldDomainPointsByUV pnts = new FieldDomainPointsByUV(uvPts); FieldValues vals = new FieldValues(valList); sfm.UpdateSpatialFieldPrimitive(idx, pnts, vals, m_schemaId); } }
/// <summary> /// This method creates points from the space syntax meta data and maps the cell /// indices value to those points. /// Note: If the provided face was aquired by user selection, the face.Reference is null, /// and the Reference, which is returned by the selection must be passed to this method. /// </summary> /// <param name="doc">the document of the active view</param> /// <param name="spaceSyntax">the object parsed from xml</param> /// <param name="face">the face of the a floor on which it i</param> /// <param name="faceReference">the reference to the face</param> /// <returns>whether the computation succeeded or was</returns> public static void CreateSpaceSyntaxAnalysisResult(Document doc, SpaceSyntax spaceSyntax, Face face, Reference faceReference) { SpatialFieldManager sfm = SpatialFieldManager.GetSpatialFieldManager(doc.ActiveView); if (sfm == null) { sfm = SpatialFieldManager.CreateSpatialFieldManager(doc.ActiveView, 1); } var uvPts = new List <UV>(); var doubleList = new List <double>(); var valList = new List <ValueAtPoint>(); // we map u to x and v to y var localOriginInGlobalVector = face.Evaluate(new UV(0.0, 0.0)); var matrixAInverted = CalculateMatrixForGlobalToLocalCoordinateSystem(face); double deltaX = Math.Abs(spaceSyntax.MinX - spaceSyntax.MaxX) / spaceSyntax.DomainColumns; double deltaY = Math.Abs(spaceSyntax.MinY - spaceSyntax.MaxY) / spaceSyntax.DomainRows; double minX = spaceSyntax.MinX + deltaX / 2.0; double minY = spaceSyntax.MinY + deltaY / 2.0; for (double y = minY, i = 1.0; y < spaceSyntax.MaxY; y += deltaY, i += 1.0) { for (double x = minX, j = 1.0; x < spaceSyntax.MaxX; x += deltaX, j += 1.0) { var globalPoint = new XYZ(x, y, 0.0); // z-coordinate is irrelevant, since the UV space is parallel var localUV = GlobalToLocalCoordinate(matrixAInverted, localOriginInGlobalVector, globalPoint); if (face.IsInside(localUV)) { uvPts.Add(localUV); doubleList.Add(GetValueFromSpaceSyntax(spaceSyntax, (int)j, (int)i)); valList.Add(new ValueAtPoint(doubleList)); doubleList.Clear(); } } } var points = new FieldDomainPointsByUV(uvPts); var values = new FieldValues(valList); int index = sfm.AddSpatialFieldPrimitive(faceReference); var resultSchema = CreateResultSchemaWithUnitNames(); sfm.UpdateSpatialFieldPrimitive(index, points, values, sfm.RegisterResult(resultSchema)); }
private void VerifySpatialFieldManagerAndValues(string displayStyleName) { var doc = DocumentManager.Instance.CurrentDBDocument; var view = doc.ActiveView; TransactionManager.Instance.EnsureInTransaction(doc); var p = view.get_Parameter(BuiltInParameter.VIEW_ANALYSIS_DISPLAY_STYLE); p.SetValueString(displayStyleName); var sfm = SpatialFieldManager.GetSpatialFieldManager(view); Assert.NotNull(sfm); TransactionManager.Instance.TransactionTaskDone(); }
public void Execute(UpdaterData data) { Document doc = data.GetDocument(); Autodesk.Revit.DB.View view = doc.ActiveView; SpatialFieldManager sfm = SpatialFieldManager.GetSpatialFieldManager(view); UpdaterData tempData = data; if (sfm != null) { // Cache the spatial field manager if ther is one if (m_sfm == null) { //FilteredElementCollector collector = new FilteredElementCollector(doc); //collector.OfClass(typeof(SpatialFieldManager)); //var sfm = from element in collector // select element; //if (sfm.Count<Element>() > 0) // if we actually found an SFM //{ //m_sfm = sfm.Cast<SpatialFieldManager>().ElementAt<SpatialFieldManager>(0); m_sfm = sfm; //TaskDialog.Show("ah hah", "found spatial field manager adding to cache"); //} } if (m_sfm != null) { // if we find an sfm has been updated and it matches what already have one cached, send it to dyanmo //foreach (ElementId addedElemId in data.GetAddedElementIds()) //{ //SpatialFieldManager sfm = doc.get_Element(addedElemId) as SpatialFieldManager; //if (sfm != null) //{ // TaskDialog.Show("ah hah", "found spatial field manager yet, passing to dynamo"); dynElementSettings.SharedInstance.SpatialFieldManagerUpdated = sfm; //Dynamo.Elements.OnDynElementReadyToBuild(EventArgs.Empty);//kick it //} //} } } else { //TaskDialog.Show("ah hah", "no spatial field manager yet, please run sr tool"); } }
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); } } }
public static void PaintSolid(Document doc, Solid solid, double value) { Autodesk.Revit.DB.View view = doc.ActiveView; if (view.AnalysisDisplayStyleId == ElementId.InvalidElementId) { CreateAVFDisplayStyle(doc, view); } SpatialFieldManager sfm = SpatialFieldManager.GetSpatialFieldManager(view); if (sfm == null) { sfm = SpatialFieldManager.CreateSpatialFieldManager(view, 1); } sfm.Clear(); IList <int> results = sfm.GetRegisteredResults(); AnalysisResultSchema resultSchema1 = new AnalysisResultSchema("PaintedSolid2", "Description"); int schemaId = sfm.RegisterResult(resultSchema1); foreach (Face face in solid.Faces) { int idx = sfm.AddSpatialFieldPrimitive(face, Transform.Identity); IList <UV> uvPts = new List <UV>(); List <double> doubleList = new List <double>(); IList <ValueAtPoint> valList = new List <ValueAtPoint>(); BoundingBoxUV bb = face.GetBoundingBox(); uvPts.Add(bb.Min); doubleList.Add(value); valList.Add(new ValueAtPoint(doubleList)); FieldDomainPointsByUV pnts = new FieldDomainPointsByUV(uvPts); FieldValues vals = new FieldValues(valList); sfm.UpdateSpatialFieldPrimitive(idx, pnts, vals, schemaId); } // UIDocument uidoc = new UIDocument(doc); //uidoc.RefreshActiveView(); }
public static ElementId RequestAnalysisResultInstanceSelection( string message, ILogger logger) { var doc = DocumentManager.Instance.CurrentUIDocument; try { var view = doc.ActiveView; var sfm = SpatialFieldManager.GetSpatialFieldManager(view); if (sfm != null) { sfm.GetRegisteredResults(); var choices = doc.Selection; choices.Elements.Clear(); logger.Log(message); var fsRef = doc.Selection.PickObject(ObjectType.Element); if (fsRef != null) { var analysisResult = doc.Document.GetElement(fsRef.ElementId); return(analysisResult.Id); } return(null); } return(null); } catch (Exception ex) { logger.Log(ex); return(null); } }
public static Element RequestAnalysisResultInstanceSelection(string message) { UIDocument doc = DocumentManager.Instance.CurrentUIDocument; try { View view = doc.ActiveView; SpatialFieldManager sfm = SpatialFieldManager.GetSpatialFieldManager(view); if (sfm != null) { sfm.GetRegisteredResults(); Autodesk.Revit.UI.Selection.Selection choices = doc.Selection; choices.Elements.Clear(); //MessageBox.Show(message); dynSettings.Controller.DynamoLogger.Log(message); Reference fsRef = doc.Selection.PickObject(ObjectType.Element); if (fsRef != null) { Element analysisResult = doc.Document.GetElement(fsRef.ElementId); return(analysisResult); } return(null); } return(null); } catch (Exception ex) { dynSettings.Controller.DynamoLogger.Log(ex); return(null); } }
/// <summary> /// Paint a solid in a new named view /// </summary> /// <param name="s">solid</param> /// <param name="viewName">Given the name of view</param> public void PaintSolid(Solid s, String viewName) { View view; if (!viewNameList.Contains(viewName)) { view = m_doc.Create.NewView3D(new XYZ(1, 1, 1)); view.Name = viewName; viewNameList.Add(viewName); } else { view = (((new FilteredElementCollector(m_doc). OfClass(typeof(View))).Cast <View>()). Where(e => e.Name == viewName)).First <View>(); } SpatialFieldManager sfm = SpatialFieldManager.GetSpatialFieldManager(view); if (sfm == null) { sfm = SpatialFieldManager.CreateSpatialFieldManager(view, 1); } if (SchemaId != -1) { IList <int> results = sfm.GetRegisteredResults(); if (!results.Contains(SchemaId)) { SchemaId = -1; } } if (SchemaId == -1) { AnalysisResultSchema resultSchema1 = new AnalysisResultSchema("PaintedSolid" + viewName, "Description"); AnalysisDisplayStyle displayStyle = AnalysisDisplayStyle.CreateAnalysisDisplayStyle( m_doc, "Real_Color_Surface" + viewName, new AnalysisDisplayColoredSurfaceSettings(), new AnalysisDisplayColorSettings(), new AnalysisDisplayLegendSettings()); resultSchema1.AnalysisDisplayStyleId = displayStyle.Id; SchemaId = sfm.RegisterResult(resultSchema1); } FaceArray faces = s.Faces; Transform trf = Transform.Identity; foreach (Face face in faces) { int idx = sfm.AddSpatialFieldPrimitive(face, trf); IList <UV> uvPts = null; IList <ValueAtPoint> valList = null; ComputeValueAtPointForFace(face, out uvPts, out valList, 1); FieldDomainPointsByUV pnts = new FieldDomainPointsByUV(uvPts); FieldValues vals = new FieldValues(valList); sfm.UpdateSpatialFieldPrimitive(idx, pnts, vals, SchemaId); } }
/// <summary> /// The idling callback which adds data to the AVF results. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void UpdateWhileIdling(object sender, IdlingEventArgs e) { UIApplication uiApp = sender as UIApplication; // Get SpatialFieldManager AnalysisResultSchema resultSchema = new AnalysisResultSchema("Schema Name", "Description"); SpatialFieldManager sfm = SpatialFieldManager.GetSpatialFieldManager(uiApp.ActiveUIDocument.Document.ActiveView); if (sfm == null) { sfm = SpatialFieldManager.CreateSpatialFieldManager(uiApp.ActiveUIDocument.Document.ActiveView, 1); } int schemaIndex = sfm.RegisterResult(resultSchema); // If stopping, clear results and unset event. if (m_stop) { lock (results) { results.Clear(); } uiApp.Idling -= UpdateWhileIdling; return; } // If document was closed and new document opened, do not run the update. if (uiApp.ActiveUIDocument.Document.PathName == m_docName) { // Lock access to current calculated results lock (results) { if (results.Count == 0) { return; } // Turn each result to an AVF ValueAtPoint foreach (ResultsData rData in results) { uvPts.Add(new UV(rData.UV.U, rData.UV.V)); IList <double> doubleList = new List <double>(); doubleList.Add(rData.Value); valList.Add(new ValueAtPoint(doubleList)); } FieldDomainPointsByUV pntsByUV = new FieldDomainPointsByUV(uvPts); FieldValues fieldValues = new FieldValues(valList); // Update with calculated values Transaction t = new Transaction(uiApp.ActiveUIDocument.Document); t.SetName("AVF"); t.Start(); if (!m_stop) { sfm.UpdateSpatialFieldPrimitive(s_spatialFieldId, pntsByUV, fieldValues, schemaIndex); } t.Commit(); // Clear results already processed. results.Clear(); // If no more results to process, remove the idling event if (m_uvToCalculateCount == 0) { uiApp.Idling -= UpdateWhileIdling; s_oldViewId = s_activeViewId; s_oldSpatialFieldId = s_spatialFieldId; } } } }
public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiApp = commandData.Application; UIDocument uiDoc = uiApp.ActiveUIDocument; Document doc = uiDoc.Document; s_docName = doc.PathName; Element element = null; try { element = doc.GetElement(uiDoc.Selection.PickObject(ObjectType.Element, "Select an element for the AVF demonstration.")); } catch (System.Exception) { message = "User aborted the tool."; return(Result.Cancelled); } // Set up SpatialFieldManager to hold results s_activeViewId = doc.ActiveView.Id; SpatialFieldManager oldSfm = null; View oldView = null; if (s_oldViewId != null) { oldView = doc.GetElement(s_oldViewId) as View; } if (oldView != null) { oldSfm = SpatialFieldManager.GetSpatialFieldManager(oldView); } // If a previous SFM was being managed, delete it if (oldSfm != null) { oldSfm.RemoveSpatialFieldPrimitive(s_oldSpatialFieldId); } // Setup container object for executing the calculation MultithreadedCalculationContainer container = CreateContainer(element); // Register updater to watch for geometry changes SpatialFieldUpdater updater = new SpatialFieldUpdater(container, uiApp.ActiveAddInId); if (!UpdaterRegistry.IsUpdaterRegistered(updater.GetUpdaterId())) { UpdaterRegistry.RegisterUpdater(updater, doc); } IList <ElementId> idCollection = new List <ElementId>(); idCollection.Add(element.Id); UpdaterRegistry.RemoveAllTriggers(s_updaterId); UpdaterRegistry.AddTrigger(updater.GetUpdaterId(), doc, idCollection, Element.GetChangeTypeGeometry()); // Register idling event uiApp.Idling += new EventHandler <IdlingEventArgs>(container.UpdateWhileIdling); // Start new thread Thread thread = new Thread(new ThreadStart(container.Run)); thread.Start(); return(Autodesk.Revit.UI.Result.Succeeded); }