Пример #1
0
        /// <summary>
        ///  Adds some results to a surface element for specific load cases
        /// </summary>
        /// <param name="doc">Revit document</param>
        /// <param name="resultsPackageBuilder"></param>
        /// <param name="elementId"></param>
        /// <param name="loadCaseIds"></param>
        private void AddSurfaceResults(Document doc, ResultsPackageBuilder resultsPackageBuilder, ElementId elementId, ElementId [] loadCaseIds)
        {
            // Get a list of points on the contour
            List <XYZ> contourPoints = GetSurfaceContourPoints(doc, elementId);
            // Get a list of sample results in contour points
            var contourResults = GenerateSampleSurfaceResultsForContour(contourPoints);

            // Add results for the first load case
            ElementId loadCaseId1 = loadCaseIds[0];

            // Result domain for each axis first
            resultsPackageBuilder.SetSurfaceResult(elementId, loadCaseId1, DomainResultType.X, contourPoints.Select(s => s.X));
            resultsPackageBuilder.SetSurfaceResult(elementId, loadCaseId1, DomainResultType.Y, contourPoints.Select(s => s.Y));
            resultsPackageBuilder.SetSurfaceResult(elementId, loadCaseId1, DomainResultType.Z, contourPoints.Select(s => s.Z));
            // Then correspoding result values
            foreach (var contourResult in contourResults)
            {
                resultsPackageBuilder.SetSurfaceResult(elementId, loadCaseId1, contourResult.Item1, contourResult.Item2);
            }

            // Add modified results for the second load case too
            ElementId loadCaseId2 = loadCaseIds[1];

            resultsPackageBuilder.SetSurfaceResult(elementId, loadCaseId2, DomainResultType.X, contourPoints.Select(s => s.X));
            resultsPackageBuilder.SetSurfaceResult(elementId, loadCaseId2, DomainResultType.Y, contourPoints.Select(s => s.Y));
            resultsPackageBuilder.SetSurfaceResult(elementId, loadCaseId2, DomainResultType.Z, contourPoints.Select(s => s.Z));
            foreach (var contourResult in contourResults)
            {
                resultsPackageBuilder.SetSurfaceResult(elementId, loadCaseId2, contourResult.Item1, contourResult.Item2.Select(s => s * 2));
            }
        }
Пример #2
0
        /// <summary>
        /// Adds some results to a linear element for specific load cases
        /// </summary>
        /// <param name="resultsPackageBuilder">Reference to the results package</param>
        /// <param name="elementId">Id of the linear element to which results are to be added</param>
        /// <param name="loadCaseIds">Array of Ids of loads</param>
        private void AddLinearResults(ResultsPackageBuilder resultsPackageBuilder, ElementId elementId, ElementId [] loadCaseIds)
        {
            // Create a list of points ( represented here by relative coordinates on the element ) in which results will be stored
            List <double> xCoordinateValues = new List <double>()
            {
                0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0
            };

            // Create list of some results
            // Each list element contains result type and a list of result values
            List <Tuple <LinearResultType, List <double> > > valuesForForceType = new List <Tuple <LinearResultType, List <double> > >()
            {
                new Tuple <LinearResultType, List <double> > (LinearResultType.Fx, new List <double>()
                {
                    4.01, 4.02, 4.03, 4.04, 4.05, 4.06, 4.07, 4.08, 4.09, 4.10
                }),
                new Tuple <LinearResultType, List <double> > (LinearResultType.Fy, new List <double>()
                {
                    -0.40, -0.30, -0.20, -0.10, 0.00, 0.10, 0.20, 0.30, 0.40, 0.50
                }),
                new Tuple <LinearResultType, List <double> > (LinearResultType.Fz, new List <double>()
                {
                    1.00, 1.20, 1.30, 1.40, 1.50, 1.60, 1.70, 1.80, 1.90, 2.00
                }),
                new Tuple <LinearResultType, List <double> > (LinearResultType.Mx, new List <double>()
                {
                    1.60, 1.60, 1.60, 1.60, 1.60, 1.60, 1.60, 1.60, 1.60, 1.60
                }),
                new Tuple <LinearResultType, List <double> > (LinearResultType.My, new List <double>()
                {
                    1.21, 1.00, 0.90, 0.40, 0.10, 0.10, 0.40, 0.90, 1.00, 1.21
                }),
                new Tuple <LinearResultType, List <double> > (LinearResultType.Mz, new List <double>()
                {
                    6.21, 6.00, 5.90, 5.40, 5.10, 5.10, 5.40, 5.90, 6.00, 6.21
                }),
            };

            // Add results for the first load case
            ElementId loadCaseId1 = loadCaseIds[0];

            // First result domain
            resultsPackageBuilder.SetBarResult(elementId, loadCaseId1, DomainResultType.X, xCoordinateValues);
            // Then result values
            foreach (var valueForForce in valuesForForceType)
            {
                resultsPackageBuilder.SetBarResult(elementId, loadCaseId1, valueForForce.Item1, valueForForce.Item2);
            }

            // Modify results and add them for the second load case as well
            ElementId loadCaseId2 = loadCaseIds[1];

            resultsPackageBuilder.SetBarResult(elementId, loadCaseId2, DomainResultType.X, xCoordinateValues);
            foreach (var valueForForce in valuesForForceType)
            {
                resultsPackageBuilder.SetBarResult(elementId, loadCaseId2, valueForForce.Item1, valueForForce.Item2.Select(s => s * 2));
            }
        }
Пример #3
0
        /// <summary>
        /// Creates an empty results package and fills out its header fields
        /// </summary>
        /// <param name="doc">Revit document</param>
        /// <returns>Reference to the newly created package</returns>
        private ResultsPackageBuilder createResultsPackageBuilder(Document doc)
        {
            ResultsAccess         resultsAccess         = ResultsAccess.CreateResultsAccess(doc);
            ResultsPackageBuilder resultsPackageBuilder = resultsAccess.CreateResultsPackage(packageGuid, "ResultsInRevit", UnitsSystem.Metric, ResultsPackageTypes.All);

            resultsPackageBuilder.SetAnalysisName("ResultsInRevit_Analysis");
            resultsPackageBuilder.SetModelName("ResultsInRevit_Model");
            resultsPackageBuilder.SetDescription("Sample results");
            resultsPackageBuilder.SetVendorDescription("Autodesk");
            resultsPackageBuilder.SetVendorId("ADSK");

            return(resultsPackageBuilder);
        }
Пример #4
0
        /// <summary>
        ///   Adds some arbitrary(user defined), load independent results to a surface element.
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="resultsPackageBuilder"></param>
        /// <param name="elementId"></param>
        private void AddArbitrarySurfaceResults(Document doc, ResultsPackageBuilder resultsPackageBuilder, ElementId elementId)
        {
            // Get contour points and generate sample arbitrary results for the surface element
            List <XYZ> contourPoints  = GetSurfaceContourPoints(doc, elementId);
            var        contourResults = GenerateSampleArbitrarySurfaceResultsForContour(contourPoints);

            // Add result domain for load independent results for x,y,z axes
            resultsPackageBuilder.SetSurfaceResult(elementId, null, DomainResultType.X, contourPoints.Select(s => s.X));
            resultsPackageBuilder.SetSurfaceResult(elementId, null, DomainResultType.Y, contourPoints.Select(s => s.Y));
            resultsPackageBuilder.SetSurfaceResult(elementId, null, DomainResultType.Z, contourPoints.Select(s => s.Z));
            // Add result values
            foreach (var result in contourResults)
            {
                resultsPackageBuilder.AddMeasurement(result.Item1, MeasurementResultType.Surface, UnitType.UT_Area, DisplayUnitType.DUT_SQUARE_METERS, MeasurementDependencyType.LoadCaseIndependent);
                resultsPackageBuilder.SetArbitraryResult(elementId, null, result.Item1, result.Item2);
            }
        }
Пример #5
0
        /// <summary>
        /// The top level command.
        /// </summary>
        /// <param name="commandData">An object that is passed to the external application
        /// which contains data related to the command,
        /// such as the application object and active view.</param>
        /// <param name="message">A message that can be set by the external application
        /// which will be displayed if a failure or cancellation is returned by
        /// the external command.</param>
        /// <param name="elements">A set of elements to which the external application
        /// can add elements that are to be highlighted in case of failure or cancellation.</param>
        /// <returns>Return the status of the external command.
        /// A result of Succeeded means that the API external method functioned as expected.
        /// Cancelled can be used to signify that the user cancelled the external operation
        /// at some point. Failure should be returned if the application is unable to proceed with
        /// the operation.</returns>
        public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            Autodesk.Revit.UI.Result retVal = Autodesk.Revit.UI.Result.Succeeded;
            Document doc = commandData.Application.ActiveUIDocument.Document;

            // Check if this is the Revit file that is included in this example and display warning if not
            if (doc.Title != "ResultsInRevit.rvt")
            {
                Autodesk.Revit.UI.TaskDialog.Show("Wrong Revit file", "Cannot use :\n" + doc.PathName + "\n\nPlease use attached " + "\"ResultsInRevit.rvt\" file.");
                retVal = Autodesk.Revit.UI.Result.Failed;
            }

            Transaction trans = new Transaction(doc);

            try
            {
                trans.SetName("ResultsInRevit_Transaction");
                trans.Start();

                // Create new instance of empty result builder
                ResultsPackageBuilder resultsPackageBuilder = createResultsPackageBuilder(doc);
                // Add analitical results to the linear element for two load cases
                AddLinearResults(resultsPackageBuilder, linearElementId, new ElementId[] { loadCaseId1, loadCaseId2 });
                // Add some arbitrary results to the same element
                AddArbitraryLinearResults(resultsPackageBuilder, linearElementId);
                // Add analitical results to the surface element for the same load cases
                AddSurfaceResults(doc, resultsPackageBuilder, surfaceElementId, new ElementId[] { loadCaseId1, loadCaseId2 });
                // Add arbitrary results to the surface element
                AddArbitrarySurfaceResults(doc, resultsPackageBuilder, surfaceElementId);

                // End adding and close transaction
                resultsPackageBuilder.Finish();
                trans.Commit();
            }
            catch (Exception ex)
            {
                // Rollback transaction and display warning if there were any problems
                trans.RollBack();
                Autodesk.Revit.UI.TaskDialog.Show("Failed to write results to Revit", ex.Message.ToString());
                retVal = Autodesk.Revit.UI.Result.Failed;
            }

            return(retVal);
        }
Пример #6
0
        /// <summary>
        ///  Adds some arbitrary(user defined) results to a linear element. The arbitrary results that we are using here are load case independent
        /// </summary>
        /// <param name="resultsPackageBuilder"></param>
        /// <param name="elementId"></param>
        private void AddArbitraryLinearResults(ResultsPackageBuilder resultsPackageBuilder, ElementId elementId)
        {
            // Create list of some results
            // Each list element contains arbitrary result type(represented by string) and a list of result values
            List <Tuple <String, List <double> > > valuesForRnf = new List <Tuple <String, List <double> > >()
            {
                new Tuple <String, List <double> > ("RnfBarsAngleBottom", new List <double>()
                {
                    45.00, 30.00, 15.00, 60.00, 0.00, 0.00, 10.00, 0.00, 0.00, 90.00
                }),
                new Tuple <String, List <double> > ("RnfBarsAngleTop", new List <double>()
                {
                    45.00, 30.00, 15.00, 60.00, 0.00, 0.00, 10.00, 0.00, 0.00, 90.00
                }),
                new Tuple <String, List <double> > ("RnfBarsAngleLeft", new List <double>()
                {
                    45.00, 30.00, 15.00, 60.00, 0.00, 0.00, 10.00, 0.00, 0.00, 90.00
                }),
                new Tuple <String, List <double> > ("RnfBarsAngleRight", new List <double>()
                {
                    45.00, 30.00, 15.00, 60.00, 0.00, 0.00, 10.00, 0.00, 0.00, 90.00
                }),
            };

            // Add result domain for load independent results
            List <double> xCoordinateValues = new List <double>()
            {
                0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0
            };

            resultsPackageBuilder.SetBarResult(elementId, null, DomainResultType.X, xCoordinateValues);
            // Add result values
            foreach (var valueForRnf in valuesForRnf)
            {
                resultsPackageBuilder.AddMeasurement(valueForRnf.Item1, MeasurementResultType.Bar, UnitType.UT_Angle, DisplayUnitType.DUT_DEGREES_AND_MINUTES, MeasurementDependencyType.LoadCaseIndependent);
                resultsPackageBuilder.SetArbitraryResult(elementId, null, valueForRnf.Item1, valueForRnf.Item2);
            }
        }