/// <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> /// 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(); }
public override Value Evaluate(FSharpList <Value> args) { this.ClearPreviousResults(); //unwrap the values IEnumerable <XYZ> nvals = ((Value.List)args[0]).Item.Select( x => (XYZ)((Value.Container)x).Item ); //unwrap the sample locations IEnumerable <XYZ> pts = ((Value.List)args[1]).Item.Select( x => (XYZ)((Value.Container)x).Item ); SpatialFieldManager = ((Value.Container)args[2]).Item as Autodesk.Revit.DB.Analysis.SpatialFieldManager; int idx = SpatialFieldManager.AddSpatialFieldPrimitive(); var samplePts = new FieldDomainPointsByXYZ(pts.ToList <XYZ>()); //for every sample location add a list //of valueatpoint objects. for now, we only //support one value per point IList <VectorAtPoint> valList = nvals.Select(n => new VectorAtPoint(new List <XYZ> { n })).ToList(); var sampleValues = new FieldValues(valList); int schemaIndex = 0; if (!SpatialFieldManager.IsResultSchemaNameUnique(DYNAMO_ANALYSIS_RESULTS_NAME, -1)) { IList <int> arses = SpatialFieldManager.GetRegisteredResults(); foreach (int i in arses) { AnalysisResultSchema arsTest = SpatialFieldManager.GetResultSchema(i); if (arsTest.Name == DYNAMO_ANALYSIS_RESULTS_NAME) { schemaIndex = i; break; } } } else { var ars = new AnalysisResultSchema(DYNAMO_ANALYSIS_RESULTS_NAME, "Resulting analyses from Dynamo."); schemaIndex = SpatialFieldManager.RegisterResult(ars); } SpatialFieldManager.UpdateSpatialFieldPrimitive(idx, samplePts, sampleValues, schemaIndex); PastResultIds.Add(idx); return(Value.NewContainer(idx)); }
/// <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> /// <param name="data"></param> /// <param name="primitiveIds"></param> /// <param name="schemaName"></param> /// <param name="description"></param> /// <param name="unitType"></param> private void InternalSetSpatialFieldValues(IStructuredData <Point, double> data, ref List <int> primitiveIds, string schemaName, string description, Type unitType) { 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 dataLocations = data.ValueLocations.Select(l => l.ToXyz()); var values = data.Values.ToList(); while (dataLocations.Any()) { // Compute the chunks var pointLocationChunk = dataLocations.Take(chunkSize); var valuesChunk = values.Take(chunkSize).ToList(); // Create the ValueAtPoint objects var valList = valuesChunk.Select(n => new ValueAtPoint(new List <double> { n })); // Create the field domain points and values var samplePts = new FieldDomainPointsByXYZ(pointLocationChunk.ToList()); var sampleValues = new FieldValues(valList.ToList()); // 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); dataLocations = dataLocations.Skip(chunkSize); values = values.Skip(chunkSize).ToList(); } TransactionManager.Instance.TransactionTaskDone(); }
/// <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="sampleLocations"></param> /// <param name="samples"></param> private void InternalSetSpatialFieldValues(IEnumerable <XYZ> sampleLocations, IEnumerable <XYZ> samples) { TransactionManager.Instance.EnsureInTransaction(Document); // Convert the analysis values to a special Revit type var valList = samples.Select(n => new VectorAtPoint(new List <XYZ> { n })).ToList(); var sampleValues = new FieldValues(valList); // Convert the sample points to a special Revit Type var samplePts = new FieldDomainPointsByXYZ(sampleLocations.ToList <XYZ>()); // Get the analysis results schema var schemaIndex = GetAnalysisResultSchemaIndex(); // Update the values SpatialFieldManager.UpdateSpatialFieldPrimitive(SpatialFieldPrimitiveId, samplePts, sampleValues, schemaIndex); TransactionManager.Instance.TransactionTaskDone(); }
/// <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="data"></param> /// <param name="schemaName"></param> /// <param name="description"></param> /// <param name="unitType"></param> private void InternalSetSpatialFieldValues(int primitiveId, VectorData data, string schemaName, string description, Type unitType) { var valList = data.Values.Select(v => new VectorAtPoint(new List <XYZ> { v.ToXyz() })); TransactionManager.Instance.EnsureInTransaction(Document); var sampleValues = new FieldValues(valList.ToList()); // Convert the sample points to a special Revit Type var samplePts = new FieldDomainPointsByXYZ(data.ValueLocations.Select(p => p.ToXyz()).ToList()); // Get the analysis results schema var schemaIndex = GetAnalysisResultSchemaIndex(schemaName, description, unitType); // Update the values SpatialFieldManager.UpdateSpatialFieldPrimitive(primitiveId, samplePts, sampleValues, schemaIndex); TransactionManager.Instance.TransactionTaskDone(); }
/// <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="sampleLocations"></param> /// <param name="samples"></param> private void InternalSetSpatialFieldValues(int primitiveId, VectorAnalysisData data, 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 valList = new List <VectorAtPoint>(); for (int i = 0; i < height; i++) { var lst = new List <XYZ>() { }; for (int j = 0; j < width; j++) { lst.Add(values.ElementAt(j).ElementAt(i).ToXyz()); } valList.Add(new VectorAtPoint(lst)); } TransactionManager.Instance.EnsureInTransaction(Document); var sampleValues = new FieldValues(valList); // Convert the sample points to a special Revit Type var samplePts = new FieldDomainPointsByXYZ(data.CalculationLocations.Select(p => p.ToXyz()).ToList()); // Get the analysis results schema var schemaIndex = GetAnalysisResultSchemaIndex(schemaName, description, unitType); // Update the values SpatialFieldManager.UpdateSpatialFieldPrimitive(primitiveId, samplePts, sampleValues, schemaIndex); TransactionManager.Instance.TransactionTaskDone(); }
/// <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); // Convert the analysis values to a special Revit type var valList = values.Select(n => new ValueAtPoint(new List<double> { n })).ToList(); var sampleValues = new FieldValues(valList); // Convert the sample points to a special Revit Type var samplePts = new FieldDomainPointsByXYZ(pointLocations.ToList<XYZ>()); // Get the analysis results schema var schemaIndex = GetAnalysisResultSchemaIndex(); // Update the values SpatialFieldManager.UpdateSpatialFieldPrimitive(SpatialFieldPrimitiveId, samplePts, sampleValues, schemaIndex); TransactionManager.Instance.TransactionTaskDone(); }
public override Value Evaluate(FSharpList<Value> args) { this.ClearPreviousResults(); //unwrap the values IEnumerable<XYZ> nvals = ((Value.List)args[0]).Item.Select( x => (XYZ)((Value.Container)x).Item ); //unwrap the sample locations IEnumerable<XYZ> pts = ((Value.List)args[1]).Item.Select( x => (XYZ)((Value.Container)x).Item ); SpatialFieldManager = ((Value.Container)args[2]).Item as Autodesk.Revit.DB.Analysis.SpatialFieldManager; int idx = SpatialFieldManager.AddSpatialFieldPrimitive(); var samplePts = new FieldDomainPointsByXYZ(pts.ToList<XYZ>()); //for every sample location add a list //of valueatpoint objects. for now, we only //support one value per point IList<VectorAtPoint> valList = nvals.Select(n => new VectorAtPoint(new List<XYZ> { n })).ToList(); var sampleValues = new FieldValues(valList); int schemaIndex = 0; if (!SpatialFieldManager.IsResultSchemaNameUnique(DYNAMO_ANALYSIS_RESULTS_NAME, -1)) { IList<int> arses = SpatialFieldManager.GetRegisteredResults(); foreach (int i in arses) { AnalysisResultSchema arsTest = SpatialFieldManager.GetResultSchema(i); if (arsTest.Name == DYNAMO_ANALYSIS_RESULTS_NAME) { schemaIndex = i; break; } } } else { var ars = new AnalysisResultSchema(DYNAMO_ANALYSIS_RESULTS_NAME, "Resulting analyses from Dynamo."); schemaIndex = SpatialFieldManager.RegisterResult(ars); } SpatialFieldManager.UpdateSpatialFieldPrimitive(idx, samplePts, sampleValues, schemaIndex); PastResultIds.Add(idx); return Value.NewContainer(idx); }
internal static void ShowVectors(Document doc, IList <Objects.VectorObject> points, bool scaleVectors) { double viewScale = 12.0 / Convert.ToDouble(doc.ActiveView.Scale); SpatialFieldManager sfm = SpatialFieldManager.GetSpatialFieldManager(doc.ActiveView); if (sfm == null) { sfm = SpatialFieldManager.CreateSpatialFieldManager(doc.ActiveView, 1); } if (sfm == null) { throw new System.ApplicationException("SFM still null!"); } sfm.Clear(); // schema if (_SchemaId != -1) { IList <int> results = sfm.GetRegisteredResults(); if (!results.Contains(_SchemaId)) { _SchemaId = -1; } } if (_SchemaId == -1) { _SchemaId = registerResults(sfm, "ShowChanges", "Description"); } IList <VectorAtPoint> valList = new List <VectorAtPoint>(); List <XYZ> dummyList = new List <XYZ>(); dummyList.Add(XYZ.BasisZ); FieldDomainPointsByXYZ pnts = null; FieldValues vals = null; List <XYZ> tmpXYZ = new List <XYZ>(); List <string> tmpNames = new List <String>(); int idx = sfm.AddSpatialFieldPrimitive(); int localPointCount = 0; int max = points.Count; for (int i = 0; i < max; i++) { tmpXYZ.Add(points[i].Origin); if (scaleVectors) { dummyList[0] = points[i].Vector.Multiply(viewScale); } else { dummyList[0] = points[i].Vector; } valList.Add(new VectorAtPoint(dummyList)); if (localPointCount > MAX_POINTS_PER_PRIMITIVE) { pnts = new FieldDomainPointsByXYZ(tmpXYZ); vals = new FieldValues(valList); sfm.UpdateSpatialFieldPrimitive(idx, pnts, vals, _SchemaId); // create a new primitive idx = sfm.AddSpatialFieldPrimitive(); // reset localPointCount = 0; tmpXYZ = new List <XYZ>(); valList = new List <VectorAtPoint>(); } localPointCount++; } // do it one more time if there are leftovers if (tmpXYZ.Count > 0) { pnts = new FieldDomainPointsByXYZ(tmpXYZ); vals = new FieldValues(valList); sfm.UpdateSpatialFieldPrimitive(idx, pnts, vals, _SchemaId); } updateView(doc.ActiveView, StyleEnum.Vectors); }
/// <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(); }
public bool AnalysisByElements() { bool result = false; try { if (radianceDictionary.Count > 0) { int resultIndex = FindIndexOfResult(sfm); bool firstLoop = true; int index = sfm.AddSpatialFieldPrimitive();//not associated with any geometry IList <XYZ> xyzPoints = new List <XYZ>(); IList <ValueAtPoint> valList = new List <ValueAtPoint>(); foreach (int keyIndex in radianceDictionary.Keys) { RadianceResult rr = radianceDictionary[keyIndex]; List <double> dblList = new List <double>(); //double values to be displayed on the face. dblList.Add(rr.Value1); dblList.Add(rr.Value2); dblList.Add(rr.Value3); if (dblList.Count != sfm.NumberOfMeasurements) { continue; } xyzPoints.Add(rr.PointXYZ); valList.Add(new ValueAtPoint(dblList)); //dblList.Clear(); } FieldDomainPointsByXYZ domainPoints = new FieldDomainPointsByXYZ(xyzPoints); FieldValues values = new FieldValues(valList); AnalysisResultSchema resultSchema = new AnalysisResultSchema(settings.LegendTitle, settings.LegendDescription); resultSchema.SetUnits(unitNames, multipliers); if (unitNames.Contains(settings.Units)) { resultSchema.CurrentUnits = unitNames.IndexOf(settings.Units); } if (overwriteResult) { sfm.SetResultSchema(resultIndex, resultSchema); } else if (firstLoop) { resultIndex = sfm.RegisterResult(resultSchema); firstLoop = false; } else { sfm.SetResultSchema(resultIndex, resultSchema); } sfm.UpdateSpatialFieldPrimitive(index, domainPoints, values, resultIndex); SetCurrentStyle(); result = true; } } catch (Exception ex) { MessageBox.Show("Failed to visulaize the FAR data. \n" + ex.Message, "FARCalculator : AnalysisByElements", MessageBoxButtons.OK, MessageBoxIcon.Warning); } return(result); }
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; SpatialFieldManager sfm = SpatialFieldManager.GetSpatialFieldManager(doc.ActiveView); if (sfm == null) { sfm = SpatialFieldManager.CreateSpatialFieldManager(doc.ActiveView, 1); } IList <Reference> refList = new List <Reference>(); try { refList = uiDoc.Selection.PickObjects(Autodesk.Revit.UI.Selection.ObjectType.Face); } catch (Exception) { // throw; } 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; uvPts.Add(min); uvPts.Add(max); valList.Add(new ValueAtPoint(new List <double>() { 0 })); valList.Add(new ValueAtPoint(new List <double>() { 0 })); /* * 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(0); * valList.Add(new ValueAtPoint(doubleList)); * doubleList.Clear(); * } * } * }*/ //FieldDomainPointsByUV pnts = new FieldDomainPointsByUV(uvPts); var points = new FieldDomainPointsByXYZ(new List <XYZ>() { new XYZ(0, 0, 0), new XYZ(0, 0, 10) }); FieldValues vals = new FieldValues(valList); int idx = sfm.AddSpatialFieldPrimitive(reference); AnalysisResultSchema resultSchema = new AnalysisResultSchema("Schema 1", "Schema 1 Description"); sfm.UpdateSpatialFieldPrimitive(idx, points, vals, sfm.RegisterResult(resultSchema)); } return(Result.Succeeded); }
public override Value Evaluate(FSharpList<Value> args) { SpatialFieldManager sfm = ((Value.Container)args[2]).Item as SpatialFieldManager; // Place analysis results in the form of vectors at each of a beam or column's analytical model curve Curve curve = ((Value.Container)args[3]).Item as Curve; int index = sfm.AddSpatialFieldPrimitive(curve, Transform.Identity); IList<double> doubleList = new List<double>(); doubleList.Add(curve.get_EndParameter(0)); // vectors will be at each end of the analytical model curve doubleList.Add(curve.get_EndParameter(1)); FieldDomainPointsByParameter pointsByParameter = new FieldDomainPointsByParameter(doubleList); List<XYZ> xyzList = new List<XYZ>(); xyzList.Add(curve.ComputeDerivatives(0, true).BasisX.Normalize()); // vectors will be tangent to the curve at its ends IList<VectorAtPoint> vectorList = new List<VectorAtPoint>(); vectorList.Add(new VectorAtPoint(xyzList)); xyzList.Clear(); xyzList.Add(curve.ComputeDerivatives(1, true).BasisX.Normalize().Negate()); vectorList.Add(new VectorAtPoint(xyzList)); FieldDomainPointsByXYZ feildPoints = new FieldDomainPointsByXYZ(xyzList); FieldValues fieldValues = new FieldValues(vectorList); int n = 0; sfm.UpdateSpatialFieldPrimitive(index, feildPoints, fieldValues, n); /* //first, cleanup the old one if (idx != -1) { sfm.RemoveSpatialFieldPrimitive(idx); } Reference reference = ((Value.Container)args[3]).Item as Reference; idx = sfm.AddSpatialFieldPrimitive(reference); Face face = dynRevitSettings.Doc.Document.GetElement(reference).GetGeometryObjectFromReference(reference) as Face; //unwrap the sample locations IEnumerable<UV> pts = ((Value.List)args[1]).Item.Select( x => (UV)((Value.Container)x).Item ); FieldDomainPointsByUV sample_pts = new FieldDomainPointsByUV(pts.ToList<UV>()); //unwrap the values IEnumerable<double> nvals = ((Value.List)args[0]).Item.Select( x => (double)((Value.Number)x).Item ); //for every sample location add a list //of valueatpoint objets. for now, we only //support one value per point IList<ValueAtPoint> valList = new List<ValueAtPoint>(); foreach (var n in nvals) { valList.Add(new ValueAtPoint(new List<double> { n })); } FieldValues sample_values = new FieldValues(valList); int schemaIndex = 0; if (!sfm.IsResultSchemaNameUnique(DYNAMO_ANALYSIS_RESULTS_NAME, -1)) { IList<int> arses = sfm.GetRegisteredResults(); foreach (int i in arses) { AnalysisResultSchema arsTest = sfm.GetResultSchema(i); if (arsTest.Name == DYNAMO_ANALYSIS_RESULTS_NAME) { schemaIndex = i; break; } } } else { AnalysisResultSchema ars = new AnalysisResultSchema(DYNAMO_ANALYSIS_RESULTS_NAME, "Resulting analyses from Dynamo."); schemaIndex = sfm.RegisterResult(ars); } sfm.UpdateSpatialFieldPrimitive(idx, sample_pts, sample_values, schemaIndex); */ return Value.NewContainer(idx); }
/// <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> /// Set the spatial field values for the current spatial field primitive. The two /// input sequences should be of the same length. /// </summary> /// <param name="sampleLocations"></param> /// <param name="samples"></param> private void InternalSetSpatialFieldValues(int primitiveId, VectorAnalysisData data, 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 valList = new List<VectorAtPoint>(); for (int i = 0; i < height; i++) { var lst = new List<XYZ>() { }; for (int j = 0; j < width; j++) { lst.Add(values.ElementAt(j).ElementAt(i).ToXyz()); } valList.Add(new VectorAtPoint(lst)); } TransactionManager.Instance.EnsureInTransaction(Document); var sampleValues = new FieldValues(valList); // Convert the sample points to a special Revit Type var samplePts = new FieldDomainPointsByXYZ(data.CalculationLocations.Select(p=>p.ToXyz()).ToList()); // Get the analysis results schema var schemaIndex = GetAnalysisResultSchemaIndex(schemaName, description, unitType); // Update the values SpatialFieldManager.UpdateSpatialFieldPrimitive(primitiveId, samplePts, sampleValues, schemaIndex); TransactionManager.Instance.TransactionTaskDone(); }