///<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 Autodesk.Revit.UI.Result Execute(ExternalCommandData revit,
                                                ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            Transaction trans = new Transaction(revit.Application.ActiveUIDocument.Document, "Revit.SDK.Samples.CreateComplexAreaRein");

            trans.Start();
            //initialize members
            m_revit      = revit;
            m_currentDoc = revit.Application.ActiveUIDocument;
            m_data       = new AreaReinData(revit.Application.ActiveUIDocument.Document);

            try
            {
                //check precondition and prepare necessary data to create AreaReinforcement.
                Reference     refer  = null;
                IList <Curve> curves = new List <Curve>();
                Floor         floor  = InitFloor(ref refer, ref curves);

                //ask for user's input
                AreaReinData dataOnFloor             = new AreaReinData(revit.Application.ActiveUIDocument.Document);
                CreateComplexAreaReinForm createForm = new
                                                       CreateComplexAreaReinForm(dataOnFloor);
                if (createForm.ShowDialog() == DialogResult.OK)
                {
                    //define the Major Direction of AreaReinforcement,
                    //we get direction of first Line on the Floor as the Major Direction
                    Line firstLine = (Line)(curves[0]);
                    Autodesk.Revit.DB.XYZ majorDirection = new Autodesk.Revit.DB.XYZ(
                        firstLine.GetEndPoint(1).X - firstLine.GetEndPoint(0).X,
                        firstLine.GetEndPoint(1).Y - firstLine.GetEndPoint(0).Y,
                        firstLine.GetEndPoint(1).Z - firstLine.GetEndPoint(0).Z);

                    //create AreaReinforcement by AreaReinforcement.Create() function
                    DocCreator        creator = m_revit.Application.ActiveUIDocument.Document.Create;
                    ElementId         areaReinforcementTypeId = AreaReinforcementType.CreateDefaultAreaReinforcementType(revit.Application.ActiveUIDocument.Document);
                    ElementId         rebarBarTypeId          = RebarBarType.CreateDefaultRebarBarType(revit.Application.ActiveUIDocument.Document);
                    ElementId         rebarHookTypeId         = RebarHookType.CreateDefaultRebarHookType(revit.Application.ActiveUIDocument.Document);
                    AreaReinforcement areaRein = AreaReinforcement.Create(revit.Application.ActiveUIDocument.Document, floor, curves, majorDirection, areaReinforcementTypeId, rebarBarTypeId, rebarHookTypeId);

                    //set AreaReinforcement and it's AreaReinforcementCurves parameters
                    dataOnFloor.FillIn(areaRein);
                    trans.Commit();
                    return(Autodesk.Revit.UI.Result.Succeeded);
                }
            }
            catch (ApplicationException appEx)
            {
                message = appEx.Message;
                trans.RollBack();
                return(Autodesk.Revit.UI.Result.Failed);
            }
            catch
            {
                message = "Unknow Errors.";
                trans.RollBack();
                return(Autodesk.Revit.UI.Result.Failed);
            }
            trans.RollBack();
            return(Autodesk.Revit.UI.Result.Cancelled);
        }
Example #2
0
        public async Task <ActionResult> Get(Guid id)
        {
            {
                try
                {
                    var fullDoc = DataService.GetFullDoc(id);

                    MemoryStream mem = new MemoryStream();

                    if (true)
                    {
                        DocCreator.CreatePackage(mem, fullDoc);
                    }
                    else
                    {
                        var paraTimeStamp = true;
                        // Create Document
                        using (WordprocessingDocument wordDocument =
                                   WordprocessingDocument.Create(mem, WordprocessingDocumentType.Document, true))
                        {
                            // Add a main document part.
                            MainDocumentPart mainPart = wordDocument.AddMainDocumentPart();

                            // Create the document structure and add some text.
                            mainPart.Document = new Document();
                            Body body = mainPart.Document.AppendChild(new Body());

                            // Title and Sub-title
                            Paragraph titlePara = body.AppendChild(new Paragraph());
                            Run       run       = titlePara.AppendChild(new Run());
                            run.AppendChild(new Text(fullDoc.Header.Title));

                            Paragraph subTitlePara = body.AppendChild(new Paragraph());
                            subTitlePara.AppendChild(new Run(new Text($"Created {fullDoc.Header.Created} (UTC)")));
                            // Paragraph for each para in the list
                            foreach (var para in fullDoc.Paragraphs)
                            {
                                var tsString  = paraTimeStamp ? $"[{para.TimeStamp} (UTC)] - " : "";
                                var paragraph = body.AppendChild(new Paragraph(new Run(new Text(
                                                                                           $"{tsString}{para.Text}"))));
                            }


                            mainPart.Document.Save();
                        }
                    }

                    mem.Seek(0, SeekOrigin.Begin);

                    return(File(mem, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", fullDoc.Header.FileName));
                }
                catch (KeyNotFoundException e)
                {
                    Response.StatusCode = (int)HttpStatusCode.NotFound;
                    return(null);
                }
            }
        }
Example #3
0
        /// <summary>
        /// create simple AreaReinforcement on vertical straight rectangular wall
        /// </summary>
        /// <param name="wall"></param>
        /// <returns>is successful</returns>
        private bool CreateAreaReinOnWall(Wall wall)
        {
            //make sure selected is basic wall
            if (wall.WallType.Kind != WallKind.Basic)
            {
                TaskDialog.Show("Revit", "Selected wall is not a basic wall.");
                return(false);
            }

            GeomHelper    helper = new GeomHelper();
            Reference     refer  = null;
            IList <Curve> curves = new List <Curve>();

            //check whether wall is vertical rectangular and analytical model shape is line
            if (!helper.GetWallGeom(wall, ref refer, ref curves))
            {
                ApplicationException appEx = new ApplicationException(
                    "Your selection is not a structural straight rectangular wall.");
                throw appEx;
            }

            AreaReinDataOnWall       dataOnWall = new AreaReinDataOnWall();
            CreateSimpleAreaReinForm createForm = new
                                                  CreateSimpleAreaReinForm(dataOnWall);

            //allow use select parameters to create
            if (createForm.ShowDialog() == DialogResult.OK)
            {
                DocCreator creator = m_revit.Application.ActiveUIDocument.Document.Create;

                //define the Major Direction of AreaReinforcement,
                //we get direction of first Line on the Floor as the Major Direction
                Line firstLine = (Line)(curves[0]);
                Autodesk.Revit.DB.XYZ majorDirection = new Autodesk.Revit.DB.XYZ(
                    firstLine.GetEndPoint(1).X - firstLine.GetEndPoint(0).X,
                    firstLine.GetEndPoint(1).Y - firstLine.GetEndPoint(0).Y,
                    firstLine.GetEndPoint(1).Z - firstLine.GetEndPoint(0).Z);

                //create AreaReinforcement
                IList <Curve> curveList = new List <Curve>();
                foreach (Curve curve in curves)
                {
                    curveList.Add(curve);
                }
                ElementId         areaReinforcementTypeId = AreaReinforcementType.CreateDefaultAreaReinforcementType(m_revit.Application.ActiveUIDocument.Document);
                ElementId         rebarBarTypeId          = RebarBarType.CreateDefaultRebarBarType(m_revit.Application.ActiveUIDocument.Document);
                ElementId         rebarHookTypeId         = RebarHookType.CreateDefaultRebarHookType(m_revit.Application.ActiveUIDocument.Document);
                AreaReinforcement areaRein = AreaReinforcement.Create(m_revit.Application.ActiveUIDocument.Document, wall, curveList, majorDirection, areaReinforcementTypeId, rebarBarTypeId, rebarHookTypeId);
                dataOnWall.FillIn(areaRein);
                return(true);
            }
            return(false);
        }
        ///<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 Autodesk.Revit.UI.Result Execute(ExternalCommandData revit,
                                                ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            //initialize members
            m_revit      = revit;
            m_currentDoc = revit.Application.ActiveUIDocument;
            m_data       = new AreaReinData();

            try
            {
                //check precondition and prepare necessary data to create AreaReinforcement.
                Reference  refer  = null;
                CurveArray curves = null;
                Floor      floor  = InitFloor(ref refer, ref curves);

                //ask for user's input
                AreaReinData dataOnFloor             = new AreaReinData();
                CreateComplexAreaReinForm createForm = new
                                                       CreateComplexAreaReinForm(dataOnFloor);
                if (createForm.ShowDialog() == DialogResult.OK)
                {
                    //define the Major Direction of AreaReinforcement,
                    //we get direction of first Line on the Floor as the Major Direction
                    Line firstLine = (Line)(curves.get_Item(0));
                    Autodesk.Revit.DB.XYZ majorDirection = new Autodesk.Revit.DB.XYZ(
                        firstLine.get_EndPoint(1).X - firstLine.get_EndPoint(0).X,
                        firstLine.get_EndPoint(1).Y - firstLine.get_EndPoint(0).Y,
                        firstLine.get_EndPoint(1).Z - firstLine.get_EndPoint(0).Z);

                    //create AreaReinforcement by NewAreaReinforcement function
                    DocCreator        creator  = m_revit.Application.ActiveUIDocument.Document.Create;
                    AreaReinforcement areaRein = creator.
                                                 NewAreaReinforcement(floor, curves, majorDirection);

                    //set AreaReinforcement and it's AreaReinforcementCurves parameters
                    dataOnFloor.FillIn(areaRein);
                    return(Autodesk.Revit.UI.Result.Succeeded);
                }
            }
            catch (ApplicationException appEx)
            {
                message = appEx.Message;
                return(Autodesk.Revit.UI.Result.Failed);
            }
            catch
            {
                message = "Unknow Errors.";
                return(Autodesk.Revit.UI.Result.Failed);
            }
            return(Autodesk.Revit.UI.Result.Cancelled);
        }
Example #5
0
        /// <summary>
        /// Handle the UpdateDocumentDisplayRequested event by either showing the document, or updating it
        /// if it is already being shown.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnUpdateDocumentDisplayRequested(object sender, EventArgs e)
        {
            if (_viewModel.DocDefinitionFilePathname.HasNothing())
            {
                _viewModel.NotifyUserOfMistake(message: "You need to set the pathname of the file first.");
                return;
            }

            if (_docCreator == null)
            {
                _docCreator = new DocCreator();
            }
            _docCreator.Save(path: _viewModel.DocDefinitionFilePathname);
        }
        /// <summary>
        /// create simple AreaReinforcement on vertical straight rectangular wall
        /// </summary>
        /// <param name="wall"></param>
        /// <returns>is successful</returns>
        private bool CreateAreaReinOnWall(Wall wall)
        {
            //make sure selected is basic wall
            if (wall.WallType.Kind != WallKind.Basic)
            {
                MessageBox.Show("Selected wall is not a basic wall.");
                return(false);
            }

            GeomHelper helper = new GeomHelper();
            Reference  refer  = null;
            CurveArray curves = null;

            //check whether wall is vertical rectangular and analytical model shape is line
            if (!helper.GetWallGeom(wall, ref refer, ref curves))
            {
                ApplicationException appEx = new ApplicationException(
                    "Your selection is not a structural straight rectangular wall.");
                throw appEx;
            }

            AreaReinDataOnWall       dataOnWall = new AreaReinDataOnWall();
            CreateSimpleAreaReinForm createForm = new
                                                  CreateSimpleAreaReinForm(dataOnWall);

            //allow use select parameters to create
            if (createForm.ShowDialog() == DialogResult.OK)
            {
                DocCreator creator = m_revit.Application.ActiveUIDocument.Document.Create;

                //define the Major Direction of AreaReinforcement,
                //we get direction of first Line on the Floor as the Major Direction
                Line firstLine = (Line)(curves.get_Item(0));
                Autodesk.Revit.DB.XYZ majorDirection = new Autodesk.Revit.DB.XYZ(
                    firstLine.get_EndPoint(1).X - firstLine.get_EndPoint(0).X,
                    firstLine.get_EndPoint(1).Y - firstLine.get_EndPoint(0).Y,
                    firstLine.get_EndPoint(1).Z - firstLine.get_EndPoint(0).Z);

                //create AreaReinforcement by NewAreaReinforcement function
                AreaReinforcement areaRein = creator.NewAreaReinforcement(wall, curves, majorDirection);
                dataOnWall.FillIn(areaRein);
                return(true);
            }
            return(false);
        }
        /// <summary>
        /// create simple AreaReinforcement on horizontal floor
        /// </summary>
        /// <param name="floor"></param>
        /// <returns>is successful</returns>
        private bool CreateAreaReinOnFloor(Floor floor)
        {
            GeomHelper helper = new GeomHelper();
            Reference  refer  = null;
            CurveArray curves = null;

            //check whether floor is horizontal rectangular
            //and prepare necessary to create AreaReinforcement
            if (!helper.GetFloorGeom(floor, ref refer, ref curves))
            {
                ApplicationException appEx = new ApplicationException(
                    "Your selection is not a horizontal rectangular slab.");
                throw appEx;
            }

            AreaReinDataOnFloor      dataOnFloor = new AreaReinDataOnFloor();
            CreateSimpleAreaReinForm createForm  =
                new CreateSimpleAreaReinForm(dataOnFloor);

            //allow use select parameters to create
            if (createForm.ShowDialog() == DialogResult.OK)
            {
                //define the Major Direction of AreaReinforcement,
                //we get direction of first Line on the Floor as the Major Direction
                Line firstLine = (Line)(curves.get_Item(0));
                Autodesk.Revit.DB.XYZ majorDirection = new Autodesk.Revit.DB.XYZ(
                    firstLine.get_EndPoint(1).X - firstLine.get_EndPoint(0).X,
                    firstLine.get_EndPoint(1).Y - firstLine.get_EndPoint(0).Y,
                    firstLine.get_EndPoint(1).Z - firstLine.get_EndPoint(0).Z);

                //crete AreaReinforcement by NewAreaReinforcement function
                DocCreator        creator  = m_revit.Application.ActiveUIDocument.Document.Create;
                AreaReinforcement areaRein = creator.NewAreaReinforcement(floor, curves, majorDirection);

                //set AreaReinforcement and it's AreaReinforcementCurves parameters
                dataOnFloor.FillIn(areaRein);
                return(true);
            }
            return(false);
        }