コード例 #1
0
ファイル: AnalysisTests.cs プロジェクト: whztt07/Dynamo
        public void PointAnalysisDataByPoints_ValidArgs()
        {
            var pad = PointAnalysisData.ByPoints(TestPoints());

            Assert.NotNull(pad);
            Assert.NotNull(pad.CalculationLocations);
        }
コード例 #2
0
        public void ByViewAndPointAnalysisData_ValidArgs()
        {
            var samplePoints = new[]
            {
                Point.ByCoordinates(0, 2, 4),
                Point.ByCoordinates(0, 7, 4),
                Point.ByCoordinates(0, 19, 4)
            };

            var sampleValues = new[]
            {
                1.0,
                1092,
                -1
            };

            var data = PointAnalysisData.ByPointsAndResults(
                samplePoints,
                new List <string>()
            {
                "Test points."
            },
                new IList <double>[] { sampleValues });

            var doc  = Document.Current;
            var grid = PointAnalysisDisplay.ByViewAndPointAnalysisData(doc.ActiveView, new [] { data });

            Assert.NotNull(grid);
        }
コード例 #3
0
        public void ByViewAndPointAnalysisData_BadArgs()
        {
            var samplePoints = new[]
            {
                Point.ByCoordinates(0, 2, 4),
                Point.ByCoordinates(0, 7, 4),
                Point.ByCoordinates(0, 19, 4)
            };

            var sampleValues = new[]
            {
                1.0,
                1092,
                -1
            };

            var data = PointAnalysisData.ByPointsAndResults(
                samplePoints,
                new List <string>()
            {
                "Test points."
            },
                new IList <double>[] { sampleValues });

            var doc = Document.Current;

            Assert.Throws(typeof(System.ArgumentNullException), () => PointAnalysisDisplay.ByViewAndPointAnalysisData(null, new [] { data }));
            Assert.Throws(typeof(System.ArgumentNullException), () => PointAnalysisDisplay.ByViewAndPointAnalysisData(doc.ActiveView, null));
            Assert.Throws(typeof(System.Exception), () => PointAnalysisDisplay.ByViewAndPointAnalysisData(doc.ActiveView, new PointAnalysisData[] { }));
        }
コード例 #4
0
        /// <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();
        }
コード例 #5
0
ファイル: AnalysisTests.cs プロジェクト: whztt07/Dynamo
        public void PointAnalysisDataByPointsAndResults_ValidArgs()
        {
            var pad = PointAnalysisData.ByPointsAndResults(
                TestPoints(),
                TestResultNames(),
                TestResults());

            Assert.NotNull(pad);
            Assert.NotNull(pad.CalculationLocations);
            Assert.NotNull(pad.Results);
            Assert.AreEqual(pad.Results.Count, 3);
        }
コード例 #6
0
ファイル: AnalysisTests.cs プロジェクト: whztt07/Dynamo
        public void PointAnalysisDataByPointsAndResults_BadArgs()
        {
            Assert.Throws <ArgumentNullException>(
                () => PointAnalysisData.ByPointsAndResults(null, TestResultNames(), TestResults()));

            Assert.Throws <ArgumentNullException>(
                () => PointAnalysisData.ByPointsAndResults(TestPoints(), null, TestResults()));

            Assert.Throws <ArgumentNullException>(
                () => PointAnalysisData.ByPointsAndResults(TestPoints(), TestResultNames(), null));

            Assert.Throws <ArgumentException>(
                () => PointAnalysisData.ByPointsAndResults(TestPoints(), new [] { "cat", "foo" }, TestResults()));
        }
コード例 #7
0
        /// <summary>
        /// Show a colored Point Analysis Display in the Revit view.
        /// </summary>
        /// <param name="view">The view into which you want to draw the analysis results.</param>
        /// <param name="sampleLocations">The locations at which you want to create analysis values.</param>
        /// <param name="samples">The analysis values at the given locations.</param>
        /// <param name="name">An optional analysis results name to show on the results legend.</param>
        /// <param name="description">An optional analysis results description to show on the results legend.</param>
        /// <param name="unitType">An optional Unit type to provide conversions in the analysis results.</param>
        /// <returns>An PointAnalysisDisplay object.</returns>
        public static PointAnalysisDisplay ByViewPointsAndValues(View view,
                                                                 Autodesk.DesignScript.Geometry.Point[] sampleLocations, double[] samples,
                                                                 string name = "", string description = "", Type unitType = null)
        {
            if (view == null)
            {
                throw new ArgumentNullException("view");
            }

            if (sampleLocations == null)
            {
                throw new ArgumentNullException("samplePoints");
            }

            if (samples == null)
            {
                throw new ArgumentNullException("samples");
            }

            if (sampleLocations.Length != samples.Length)
            {
                throw new Exception("The number of sample points and number of samples must be the same");
            }

            if (string.IsNullOrEmpty(name))
            {
                name = Resource1.AnalysisResultsDefaultName;
            }

            if (string.IsNullOrEmpty(description))
            {
                description = Resource1.AnalysisResultsDefaultDescription;
            }

            var data = PointAnalysisData.ByPointsAndResults(sampleLocations, new List <string> {
                "Dynamo Data"
            }, new List <IList <double> > {
                samples
            });

            return(new PointAnalysisDisplay(view.InternalView, new List <PointAnalysisData> {
                data
            }, name, description, unitType));
        }
コード例 #8
0
        /// <summary>
        /// Show a colored Point Analysis Display in the Revit view.
        /// </summary>
        /// <param name="view">The view into which you want to draw the analysis results.</param>
        /// <param name="data">A list of PointAnalysisData objects.</param>
        /// <param name="name">An optional analysis results name to show on the results legend.</param>
        /// <param name="description">An optional analysis results description to show on the results legend.</param>
        /// <param name="unitType">An optional Unit type to provide conversions in the analysis results.</param>
        /// <returns>An PointAnalysisDisplay object.</returns>
        public static PointAnalysisDisplay ByViewAndPointAnalysisData(View view,
                        PointAnalysisData[] data,
            string name = "", string description = "", Type unitType = null)
        {
            if (view == null)
            {
                throw new ArgumentNullException("view");
            }

            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            if (!data.Any())
            {
                throw new Exception("There is no input data.");
            }

            if (string.IsNullOrEmpty(name))
            {
                name = Resource1.AnalysisResultsDefaultName;
            }

            if (string.IsNullOrEmpty(description))
            {
                description = Resource1.AnalysisResultsDefaultDescription;
            }

            return new PointAnalysisDisplay(view.InternalView, data, name, description, unitType);
        }
コード例 #9
0
        /// <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();
        }
コード例 #10
0
ファイル: AnalysisTests.cs プロジェクト: whztt07/Dynamo
 public void PointAnalysisDataByPoints_BadArgs()
 {
     Assert.Throws <ArgumentNullException>(() => PointAnalysisData.ByPoints(null));
 }