/// <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> /// /// </summary> /// <param name="view"></param> /// <param name="data"></param> protected FaceAnalysisDisplay( Autodesk.Revit.DB.View view, ISurfaceData <Autodesk.DesignScript.Geometry.UV, double> data, string resultsName, string description, Type unitType) { var sfm = GetSpatialFieldManagerFromView(view); // create a new spatial field primitive TransactionManager.Instance.EnsureInTransaction(Document); sfm.Clear(); sfm.SetMeasurementNames(new List <string>() { Properties.Resources.Dynamo_AVF_Data_Name }); InternalSetSpatialFieldManager(sfm); var primitiveIds = new List <int>(); var reference = data.Surface.Tags.LookupTag(DefaultTag) as Reference; if (reference == null) { // Dont' throw an exception here. Handle the case of a bad tag // in the static constructor. return; } var primitiveId = SpatialFieldManager.AddSpatialFieldPrimitive(reference); primitiveIds.Add(primitiveId); InternalSetSpatialFieldValues(primitiveId, data, resultsName, description, unitType); TransactionManager.Instance.TransactionTaskDone(); }
/// <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; }
public RadianceDisplay(Document document, SettingProperties settingProperties, ToolStripProgressBar toolStripProgressBar, SpatialFieldManager fieldManager) { doc = document; settings = settingProperties; progressBar = toolStripProgressBar; sfm = fieldManager; }
/// <summary> /// Set the SpatialFieldManager PrimitiveId from Thread Local Storage /// </summary> /// <returns></returns> protected Tuple <SpatialFieldManager, List <int> > GetElementAndPrimitiveIdFromTrace() { // This is a provisional implementation until we can store both items in trace var id = ElementBinder.GetRawDataFromTrace(); if (id == null) { return(null); } var idPair = id as SpmPrimitiveIdPair; if (idPair == null) { return(null); } var primitiveIds = idPair.PrimitiveIds; var sfmId = idPair.SpatialFieldManagerID; SpatialFieldManager sfm = null; // if we can't get the sfm, return null if (!Document.TryGetElement(new ElementId(sfmId), out sfm)) { return(null); } return(new Tuple <SpatialFieldManager, List <int> >(sfm, primitiveIds)); }
/// <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); }
/// <summary> /// Get the SpatialFieldManager PrimitiveId from Thread Local Storage /// </summary> /// <returns></returns> protected Tuple <SpatialFieldManager, Dictionary <Reference, int> > GetElementAndRefPrimitiveIdFromTrace() { // This is a provisional implementation until we can store both items in trace var id = ElementBinder.GetRawDataFromTrace(); if (id == null) { return(null); } var idPair = id as SpmRefPrimitiveIdListPair; if (idPair == null) { return(null); } var sfmId = idPair.SpatialFieldManagerID; var keyValues = idPair.RefIdPairs; SpatialFieldManager sfm = null; // if we can't get the sfm, return null if (!Document.TryGetElement(new ElementId(sfmId), out sfm)) { return(null); } return(new Tuple <SpatialFieldManager, Dictionary <Reference, int> >(sfm, keyValues)); }
public FieldOfViewAnalysis(Document document, SettingProperties settingProperties, ToolStripProgressBar toolStripProgressBar, SpatialFieldManager fieldManager) { doc = document; settings = settingProperties; progressBar = toolStripProgressBar; sfm = fieldManager; }
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(); } }
// 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(); }
/// <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)); }
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); }
private static int GetFirstRegisteredResult(SpatialFieldManager sfm, AnalysisResultSchema analysisResultSchema) { IList <int> registeredResults = new List <int>(); registeredResults = sfm.GetRegisteredResults(); return(registeredResults.Count == 0 ? sfm.RegisterResult(analysisResultSchema) : registeredResults.First()); }
/// <summary> /// Set the spatial field values for the current spatial field primitive. The two /// input sequences should be of the same length. /// </summary> /// <param name="pointLocations"></param> /// <param name="values"></param> private void InternalSetSpatialFieldValues(IEnumerable <XYZ> pointLocations, IEnumerable <double> values) { TransactionManager.Instance.EnsureInTransaction(Document); var chunkSize = 1000; while (pointLocations.Any()) { // Convert the analysis values to a special Revit type var pointLocationChunk = pointLocations.Take(chunkSize).ToList <XYZ>(); var valuesChunk = values.Take(chunkSize).ToList(); var valList = valuesChunk.Select(n => new ValueAtPoint(new List <double> { n })).ToList(); // Convert the sample points to a special Revit Type var samplePts = new FieldDomainPointsByXYZ(pointLocationChunk.ToList <XYZ>()); var sampleValues = new FieldValues(valList); // Get the analysis results schema var schemaIndex = GetAnalysisResultSchemaIndex(); // Update the values var primitiveId = SpatialFieldManager.AddSpatialFieldPrimitive(); primitiveIds.Add(primitiveId); SpatialFieldManager.UpdateSpatialFieldPrimitive(primitiveId, samplePts, sampleValues, schemaIndex); pointLocations = pointLocations.Skip(chunkSize); values = values.Skip(chunkSize); } TransactionManager.Instance.TransactionTaskDone(); }
/// <summary> /// Create a Vector Analysis Display in the current view /// </summary> /// <param name="view"></param> /// <param name="data"></param> /// <param name="resultsName"></param> /// <param name="description"></param> /// <param name="unitType"></param> private VectorAnalysisDisplay(Autodesk.Revit.DB.View view, VectorData data, string resultsName, string description, Type unitType) { var sfm = GetSpatialFieldManagerFromView(view); TransactionManager.Instance.EnsureInTransaction(Document); sfm.Clear(); sfm.SetMeasurementNames(new List <string>() { Properties.Resources.Dynamo_AVF_Data_Name }); var primitiveIds = new List <int>(); InternalSetSpatialFieldManager(sfm); var primitiveId = SpatialFieldManager.AddSpatialFieldPrimitive(); InternalSetSpatialFieldValues(primitiveId, data, resultsName, description, unitType); primitiveIds.Add(primitiveId); TransactionManager.Instance.TransactionTaskDone(); }
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(); } } }
public FARCalculator(Document document, SettingProperties settingProperties, ToolStripProgressBar toolStripProgressBar, SpatialFieldManager fieldManager) { doc = document; settings = settingProperties; progressBar = toolStripProgressBar; progressBar.Maximum = settings.SelectedElements.Count; progressBar.Value = 0; sfm = fieldManager; }
/// <summary> /// Set the spatial field values for the current spatial field primitive. The two /// input sequences should be of the same length. /// </summary> /// <param name="pointLocations"></param> /// <param name="values"></param> private void InternalSetSpatialFieldValues(PointAnalysisData data, ref List <int> primitiveIds, string schemaName, string description, Type unitType) { var values = data.Results.Values; var height = values.First().Count(); var width = values.Count(); // Transpose and convert the analysis values to a special Revit type var transposedVals = new List <List <double> >(); for (int i = 0; i < height; i++) { var lst = new List <double>() { }; for (int j = 0; j < width; j++) { lst.Add(values.ElementAt(j).ElementAt(i)); } transposedVals.Add(lst); } TransactionManager.Instance.EnsureInTransaction(Document); // We chunk here because the API has a limitation for the // number of points that can be sent in one run. var chunkSize = 1000; var pointLocations = data.CalculationLocations.Select(l => l.ToXyz()); while (pointLocations.Any()) { // Convert the analysis values to a special Revit type var pointLocationChunk = pointLocations.Take(chunkSize).ToList <XYZ>(); var valuesChunk = transposedVals.Take(chunkSize).ToList(); var valList = valuesChunk.Select(n => new ValueAtPoint(n)).ToList(); // Convert the sample points to a special Revit Type var samplePts = new FieldDomainPointsByXYZ(pointLocationChunk.ToList <XYZ>()); var sampleValues = new FieldValues(valList); // Get the analysis results schema var schemaIndex = GetAnalysisResultSchemaIndex(schemaName, description, unitType); // Update the values var primitiveId = SpatialFieldManager.AddSpatialFieldPrimitive(); primitiveIds.Add(primitiveId); SpatialFieldManager.UpdateSpatialFieldPrimitive(primitiveId, samplePts, sampleValues, schemaIndex); pointLocations = pointLocations.Skip(chunkSize); transposedVals = transposedVals.Skip(chunkSize).ToList(); } TransactionManager.Instance.TransactionTaskDone(); }
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); } }
public ViewAnalysisManager(UIApplication uiapp, List <Room> rooms, AnalysisSettings settings, AnalysisDataCollection analysisDataCollection) { try { m_app = uiapp; m_doc = m_app.ActiveUIDocument.Document; selectedRooms = rooms; analysisSettings = settings; overwriteData = analysisSettings.OverwriteData; dataCollection = analysisDataCollection; epsilon = m_app.Application.ShortCurveTolerance; categoryFilters.Add(new ElementCategoryFilter(BuiltInCategory.OST_Walls)); //intercepting elements. categoryFilters.Add(new ElementCategoryFilter(BuiltInCategory.OST_Windows)); //passing elements categoryFilters.Add(new ElementCategoryFilter(BuiltInCategory.OST_CurtainWallPanels)); //passing elements categoryFilters.Add(new ElementCategoryFilter(BuiltInCategory.OST_Doors)); //passing elements categoryFilters.Add(new ElementCategoryFilter(BuiltInCategory.OST_StructuralColumns)); //intercepting elements if (includeLinkedModel) { categoryFilters.Add(new ElementCategoryFilter(BuiltInCategory.OST_RvtLinks)); } //find elements in link m_view = FindDefault3DView(); linkedInstances = GetLinkedInstancesInfo(); if (analysisSettings.ExteriorWallByParameter) { exteriorElementIds = BuildingEnvelopUtil.FindExteriorWallsByParameter(m_doc, linkedInstances, includeLinkedModel); } else { exteriorElementIds = BuildingEnvelopUtil.FindExteriorWallsByAnalyzer(m_doc, m_view, selectedRooms.First(), includeLinkedModel); bool paramResult = BuildingEnvelopUtil.SetExteriorWallParameter(m_doc, exteriorElementIds); } if (exteriorElementIds.Count > 0) { roomDictionary = GetRoomData(selectedRooms); if (roomDictionary.Count > 0) { m_sfm = SetSpatialFieldManager(m_doc.ActiveView, out resultIndex); } } else { MessageBox.Show("Please select exterior walls and set LEED_IsExteriorWall parameter true.\n", "Exterior Walls Not Defined", MessageBoxButton.OK, MessageBoxImage.Warning); } } catch (Exception ex) { MessageBox.Show("Failed to run View Analysis.\n" + ex.Message, "View Analysis Manager", MessageBoxButton.OK, MessageBoxImage.Warning); } }
/// <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); } }
/// <summary> /// /// </summary> /// <param name="view"></param> /// <param name="data"></param> protected FaceAnalysisDisplay( Autodesk.Revit.DB.View view, IEnumerable <ISurfaceAnalysisData <Autodesk.DesignScript.Geometry.UV, double> > data, string resultsName, string description, Type unitType) { var sfm = GetSpatialFieldManagerFromView(view, (uint)data.First().Results.Count()); //var sfmAndId = GetElementAndPrimitiveIdFromTrace(); // we can rebind as we're dealing with the same view //if (sfmAndId != null && sfmAndId.Item1.Id == sfm.Id) //{ // InternalSetSpatialFieldManager(sfmAndId.Item1); // InternalSetSpatialPrimitiveIds(sfmAndId.Item2); // InternalSetSpatialFieldValues(sampleLocations, samples); // return; //} //// the input view has changed, remove the old primitive from the old view //if (sfmAndId != null) //{ // var oldSfm = sfmAndId.Item1; // var oldId = sfmAndId.Item2; // oldSfm.RemoveSpatialFieldPrimitive(oldId); //} // create a new spatial field primitive TransactionManager.Instance.EnsureInTransaction(Document); // TEMPORARY UNTIL WE RESOLVE TRACE sfm.Clear(); sfm.SetMeasurementNames(data.SelectMany(d => d.Results.Keys).Distinct().ToList()); InternalSetSpatialFieldManager(sfm); var primitiveIds = new List <int>(); foreach (var d in data) { var reference = d.Surface.Tags.LookupTag(DefaultTag) as Reference; if (reference == null) { continue; } var primitiveId = SpatialFieldManager.AddSpatialFieldPrimitive(reference); primitiveIds.Add(primitiveId); InternalSetSpatialFieldValues(primitiveId, d, resultsName, description, unitType); } //SetElementAndPrimitiveIdsForTrace(SpatialFieldManager, primitiveIds); TransactionManager.Instance.TransactionTaskDone(); }
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(); }
/// <summary> /// Set the SpatialFieldManager and PrimitiveId in Thread Local Storage /// </summary> /// <param name="manager"></param> /// <param name="primitiveId"></param> protected void SetElementAndPrimitiveIdForTrace(SpatialFieldManager manager, int primitiveId) { if (manager == null) { throw new Exception(); } SpmPrimitiveIdPair idPair = new SpmPrimitiveIdPair(); idPair.SpatialFieldManagerID = manager.Id.IntegerValue; idPair.PrimitiveID = primitiveId; ElementBinder.SetRawDataForTrace(idPair); }
public static void UpdateCO2eVisualization(SpatialFieldManager sfm, Element element) { try { logger.InfoFormat("Adding CO2e Analysis for element: {0}", element.Name); double CO2eForElement = 0; if (element.ParametersMap.Contains("CO2e")) { CO2eForElement = element.ParametersMap.get_Item("CO2e").AsDouble(); } int count = 0; foreach (Face face in GetFaces(element)) { var idx = sfm.AddSpatialFieldPrimitive(face.Reference); IList<UV> uvPts = new List<UV>(); IList<ValueAtPoint> valList = new List<ValueAtPoint>(); var bb = face.GetBoundingBox(); AddMeasurement(CO2eForElement, bb.Min.U, bb.Min.V, uvPts, valList); AddMeasurement(CO2eForElement, bb.Min.U, bb.Max.V, uvPts, valList); AddMeasurement(CO2eForElement, bb.Max.U, bb.Max.V, uvPts, valList); AddMeasurement(CO2eForElement, bb.Max.U, bb.Min.V, uvPts, valList); logger.DebugFormat("elementId: {0}, face: {1}, spf idx: {2}, bounding box: {3},{4},{5},{6}", element.Id.IntegerValue, count, idx, bb.Min.U, bb.Min.V, bb.Max.U, bb.Max.V); var pnts = new FieldDomainPointsByUV(uvPts); var vals = new FieldValues(valList); var resultSchema1 = new AnalysisResultSchema("CO2e schema", "AMEE CO2e schema"); sfm.UpdateSpatialFieldPrimitive(idx, pnts, vals, GetFirstRegisteredResult(sfm, resultSchema1)); count++; } } catch (Exception e) { logger.Error(e); } }
protected void SetElementAndPrimitiveIdListTrace(SpatialFieldManager manager, List<int> primitiveIds) { if (manager == null) { throw new Exception(); } var idPair = new SpmPrimitiveIdListPair { SpatialFieldManagerID = manager.Id.IntegerValue, PrimitiveIDs = primitiveIds }; ElementBinder.SetRawDataForTrace(idPair); }
/// <summary> /// Set the SpatialFieldManager and PrimitiveId in Thread Local Storage /// </summary> /// <param name="manager"></param> /// <param name="primitiveId"></param> protected void SetElementAndPrimitiveIdForTrace(SpatialFieldManager manager, int primitiveId) { if (manager == null) { throw new Exception(); } // This is provisional until we can store an Int and ElementId simultaneously in TLS var id = primitiveId * PrimitiveIdPrimeFactor + manager.Id.IntegerValue; throw new NotImplementedException("This Element ID scheme is not yet implemented"); // ElementBinder.SetElementForTrace(new ElementId(id)); }
/// <summary> /// Set the SpatialFieldManager /// </summary> /// <param name="manager"></param> protected void InternalSetSpatialFieldManager(SpatialFieldManager manager) { this.SpatialFieldManager = manager; }
private static int GetFirstRegisteredResult(SpatialFieldManager sfm, AnalysisResultSchema analysisResultSchema) { IList<int> registeredResults = new List<int>(); registeredResults = sfm.GetRegisteredResults(); return registeredResults.Count == 0 ? sfm.RegisterResult(analysisResultSchema) : registeredResults.First(); }
/// <summary> /// Default Constructor /// </summary> /// <param name="doc"></param> public LightingCalculations(Document doc, SpatialFieldManager sfm) { m_doc = doc; m_sfm = sfm; }
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"); } }