Пример #1
0
        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </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 Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            //Expected results: The Analytical Panel has been moved and the connection with the Analytical Member was kept
            try
            {
                // Get the Document
                Document document = commandData.Application.ActiveUIDocument.Document;

                // Create Analytical Panel
                AnalyticalPanel analyticalPanel = CreateAnalyticalPanel.CreateAMPanel(document);

                // Create an Analytical Member connected with the Analytical Panel above
                AnalyticalMember analyticalMember = CreateAnalyticalMember.CreateMember(document);

                // Move the Analytical Panel using ElementTransformUtils
                using (Transaction transaction = new Transaction(document, "Move panel with ElementTransformUtils"))
                {
                    transaction.Start();
                    ElementTransformUtils.MoveElement(document, analyticalPanel.Id, new XYZ(5, 5, 0));
                    transaction.Commit();
                }

                return(Result.Succeeded);
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return(Result.Failed);
            }
        }
        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </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 Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            //Expected results: The Analytical Node has been moved and the connection has been kept
            try
            {
                // Get the Document
                UIDocument activeDoc = commandData.Application.ActiveUIDocument;
                Autodesk.Revit.DB.Document document = activeDoc.Document;

                // Create Analytical Panel
                AnalyticalPanel analyticalPanel = CreateAnalyticalPanel.CreateAMPanel(document);

                // Create the connected Analytical Member
                AnalyticalMember analyticalMember = CreateAnalyticalMember.CreateMember(document);

                // Select the node
                Reference eRef = activeDoc.Selection.PickObject(ObjectType.PointOnElement, "Select an Analytical Node");

                // Move the Analytical Panel using ElementTransformUtils
                using (Transaction transaction = new Transaction(document, "Move panel with ElementTransformUtils"))
                {
                    transaction.Start();
                    ElementTransformUtils.MoveElement(document, eRef.ElementId, new XYZ(-5, -5, 0));
                    transaction.Commit();
                }

                return(Result.Succeeded);
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return(Result.Failed);
            }
        }
        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </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 Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            // Expected results: the first Analytical Member has been moved and the connection with the second Analytical Member was kept
            try
            {
                // Get the document
                Document document = commandData.Application.ActiveUIDocument.Document;

                // Create the first Analytical Member
                AnalyticalMember analyticalMember = CreateAnalyticalMember.CreateMember(document);

                // Create the second Analytical Member that is convergent with the first one
                AnalyticalMember convergentAnalyticalMember = CreateAnalyticalMember.CreateConvergentMember(document);


                // Move the first Analytical Member using ElementTransformUtils
                using (Transaction transaction = new Transaction(document, "Move member with ElementTransformUtils"))
                {
                    transaction.Start();

                    ElementTransformUtils.MoveElement(document, analyticalMember.Id, new XYZ(15, 0, 0));

                    transaction.Commit();
                }

                return(Result.Succeeded);
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return(Result.Failed);
            }
        }
Пример #4
0
        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </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 Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            //Expected results: The Analytical Member is flipped, you can observe the IDs of the end nodes
            try
            {
                // Get the Document
                Document document = commandData.Application.ActiveUIDocument.Document;

                // Create an Analytical Member
                AnalyticalMember analyticalMember = CreateAnalyticalMember.CreateMember(document);

                // Start transaction
                using (Transaction transaction = new Transaction(document, "Flip Analytical Member"))
                {
                    transaction.Start();
                    // Flip the Analytical Member
                    analyticalMember.FlipCurve();
                    transaction.Commit();
                }

                return(Result.Succeeded);
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return(Result.Failed);
            }
        }
        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </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 Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            try
            {
                // Get the Document
                Document document = commandData.Application.ActiveUIDocument.Document;

                // Create an Analytical Member
                AnalyticalMember analyticalMember = CreateAnalyticalMember.CreateMember(document);

                // Start transaction
                using (Transaction transaction = new Transaction(document, "Release Conditions"))
                {
                    transaction.Start();



                    // Get release conditions of analytical member
                    IList <ReleaseConditions> releaseConditions = analyticalMember.GetReleaseConditions();
                    foreach (ReleaseConditions rc in releaseConditions)
                    {
                        Console.WriteLine("Position: " + rc.Start +
                                          "Fx: " + rc.Fx.ToString() +
                                          "Fy: " + rc.Fy.ToString() +
                                          "Fz: " + rc.Fz.ToString() +
                                          "Mx: " + rc.Mx.ToString() +
                                          "My: " + rc.My.ToString() +
                                          "Mz: " + rc.Mz.ToString());
                    }

                    // Get release type at start
                    ReleaseType releaseType = analyticalMember.GetReleaseType(true);

                    // Change release type
                    analyticalMember.SetReleaseType(true, ReleaseType.UserDefined);

                    try
                    {
                        analyticalMember.SetReleaseConditions(new ReleaseConditions(true, false, true, false, true, false, true));
                    }
                    catch (InvalidOperationException ex)
                    {
                        message = ex.Message;
                        return(Result.Failed);
                    }

                    transaction.Commit();
                }

                return(Result.Succeeded);
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return(Result.Failed);
            }
        }
Пример #6
0
        /// <summary>
        /// Creates another Analytical Member convergent with the one above
        /// </summary>
        /// <param name="document"></param>
        /// <returns></returns>
        public static AnalyticalMember CreateConvergentMember(Document document)
        {
            AnalyticalMember analyticalMember = null;

            //start Transaction
            using (Transaction transaction = new Transaction(document, "Create Convergent Analytical Member"))
            {
                transaction.Start();

                analyticalMember = CreateAnalyticalMemberFromEndpoints(document, new XYZ(0, 0, 0), new XYZ(-5, 5, 0));

                transaction.Commit();
            }
            return(analyticalMember);
        }
Пример #7
0
        /// <summary>
        /// Creates a new Analytical Member in the Document using the endpoints start and end.
        /// Optionally the Structural Role can be specified
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <returns></returns>
        private static AnalyticalMember CreateAnalyticalMemberFromEndpoints(Document doc, XYZ start, XYZ end)
        {
            AnalyticalMember analyticalMember = null;

            //create curve which will be assigned to the analytical member
            Line line = Line.CreateBound(start, end);

            //create the AnalyticalMember
            analyticalMember = AnalyticalMember.Create(doc, line);

            analyticalMember.StructuralRole = AnalyticalStructuralRole.StructuralRoleBeam;
            analyticalMember.AnalyzeAs      = AnalyzeAs.Lateral;

            return(analyticalMember);
        }
        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </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 Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            //Expected results: The first Analytical Member has been moved and the connection with the second Analytical Member was lost
            try
            {
                // Get the document
                Document document = commandData.Application.ActiveUIDocument.Document;

                // Create the first Analytical Member
                AnalyticalMember analyticalMember = CreateAnalyticalMember.CreateMember(document);

                // Create the second Analytical Member
                AnalyticalMember convergentAnalyticalMember = CreateAnalyticalMember.CreateConvergentMember(document);

                // Start transaction
                using (Transaction transaction = new Transaction(document, "Offset member"))
                {
                    transaction.Start();

                    // Get the original curve and it's ends
                    Curve originalCurve      = analyticalMember.GetCurve();
                    XYZ   originalCurveStart = originalCurve.GetEndPoint(0);
                    XYZ   originalCurveEnd   = originalCurve.GetEndPoint(1);

                    // Create new start and end with offset value
                    double offset       = 15;
                    XYZ    newLineStart = new XYZ(originalCurveStart.X + offset, 0, 0);
                    XYZ    newLineEnd   = new XYZ(originalCurveEnd.X + offset, 0, 0);

                    // Create a new bounded line using the previous coordiantes
                    Line line = Line.CreateBound(newLineStart, newLineEnd);

                    // Set the member's curve to the newly created line
                    analyticalMember.SetCurve(line);

                    transaction.Commit();
                }

                return(Result.Succeeded);
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return(Result.Failed);
            }
        }
        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </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 Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            try
            {
                // Get the Document
                Document document = commandData.Application.ActiveUIDocument.Document;

                // Create an Analytical Member
                AnalyticalMember analyticalMember = CreateAnalyticalMember.CreateMember(document);

                // Start transaction
                using (Transaction transaction = new Transaction(document, "Member Forces"))
                {
                    transaction.Start();

                    // Get member forces of analytical member
                    IList <MemberForces> memberForces = analyticalMember.GetMemberForces();
                    foreach (MemberForces mf in memberForces)
                    {
                        Console.WriteLine("Position: " + mf.Start + "Force: " + mf.Force.ToString() + "Moment: " + mf.Moment.ToString());
                    }

                    // Change some values
                    analyticalMember.SetMemberForces(true, new XYZ(10000, 5000, 0), new XYZ(0, 0, 0));
                    analyticalMember.SetMemberForces(new MemberForces(false, new XYZ(5000, 5000, 5000), new XYZ(10000, 10000, 10000)));

                    transaction.Commit();
                }

                return(Result.Succeeded);
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return(Result.Failed);
            }
        }
        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </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 Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            //Expected results: the Analytical Panel has been moved and the connection with the Analytical Member has been broken
            try
            {
                //Get the Document
                Document document = commandData.Application.ActiveUIDocument.Document;

                // Create Analytical Panel
                AnalyticalPanel analyticalPanel = CreateAnalyticalPanel.CreateAMPanel(document);

                // Create an Analytical Member connected with the Analytical Panel above
                AnalyticalMember analyticalMember = CreateAnalyticalMember.CreateMember(document);

                // Move the Analytical Panel using SketchEditScope
                SketchEditScope sketchEditScope = new SketchEditScope(document, "Move panel with SketchEditScope");
                sketchEditScope.StartWithNewSketch(analyticalPanel.Id);

                // Start transaction
                using (Transaction transaction = new Transaction(document, "Offset panel"))
                {
                    transaction.Start();

                    // Get Sketch
                    if (document.GetElement(analyticalPanel.SketchId) is Sketch sketch)
                    {
                        foreach (CurveArray curveArray in sketch.Profile)
                        {
                            // Iterate through the Curves forming the Analytical Panel and
                            // create new ones with a slight offset from the original ones before deleting them
                            foreach (Curve curve in curveArray)
                            {
                                Line line = curve as Line;
                                if (line != null)
                                {
                                    // Create new offseted Start and End points from the original line coordinates
                                    double offset       = 5.0;
                                    XYZ    newLineStart = new XYZ(line.GetEndPoint(0).X + offset, line.GetEndPoint(0).Y + offset, 0);
                                    XYZ    newLineEnd   = new XYZ(line.GetEndPoint(1).X + offset, line.GetEndPoint(1).Y + offset, 0);

                                    // Define the new line with offseted coordinates
                                    Curve offsetedLine = Line.CreateBound(newLineStart, newLineEnd);

                                    // Remove the old line
                                    document.Delete(line.Reference.ElementId);

                                    // Create the new line
                                    document.Create.NewModelCurve(offsetedLine, sketch.SketchPlane);
                                }
                            }
                        }
                    }
                    transaction.Commit();
                }
                sketchEditScope.Commit(new FailurePreproccessor());

                return(Result.Succeeded);
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return(Result.Failed);
            }
        }