Exemple #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 Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData commandData,
            ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            Transaction newTran = null;
            try
            {
                if (null == commandData)
                {
                    throw new ArgumentNullException("commandData");
                }

                Document doc = commandData.Application.ActiveUIDocument.Document;
                ViewsMgr view = new ViewsMgr(doc);

                newTran = new Transaction(doc);
                newTran.Start("AllViews_Sample");

                AllViewsForm dlg = new AllViewsForm(view);

                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    view.GenerateSheet(doc);
                }
                newTran.Commit();

                return Autodesk.Revit.UI.Result.Succeeded;
            }
            catch (Exception e)
            {
                message = e.Message;
                if ((newTran != null) && newTran.HasStarted() && !newTran.HasEnded())
                    newTran.RollBack();
                return Autodesk.Revit.UI.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 Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData commandData,
                                                ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            if (null == commandData)
            {
                throw new ArgumentNullException("commandData");
            }

            Document doc  = commandData.Application.ActiveUIDocument.Document;
            ViewsMgr view = new ViewsMgr(doc);

            AllViewsForm dlg = new AllViewsForm(view);

            try
            {
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    return(view.GenerateSheet(doc));
                }
            }
            catch (Exception e)
            {
                message = e.Message;
                return(Autodesk.Revit.UI.Result.Failed);
            }

            return(Autodesk.Revit.UI.Result.Succeeded);
        }
        /// <summary>
        /// Change viewport orientation.
        /// </summary>
        /// <param name="form">The Form to be updated.</param>
        /// <param name="rotation">Label line rotation.</param>
        public void SetRotation(AllViewsForm form, ViewportRotation rotation)
        {
            using (Transaction t = new Transaction(m_doc, "Change label orientation"))
            {
                t.Start();

                m_VP.Rotation = rotation;

                t.Commit();

                UpdateViewportProperties(form);
            }
        }
        /// <summary>
        /// Change viewport label length.
        /// </summary>
        /// <param name="form">The Form to be updated.</param>
        /// <param name="labelLineLength">Label line length.</param>
        public void SetLabelLength(AllViewsForm form, double labelLineLength)
        {
            using (Transaction t = new Transaction(m_doc, "Change label length"))
            {
                t.Start();

                m_VP.LabelLineLength = labelLineLength;

                t.Commit();

                UpdateViewportProperties(form);
            }
        }
        /// <summary>
        /// Change viewport label offset.
        /// </summary>
        /// <param name="form">The Form to be updated.</param>
        /// <param name="labelOffsetX">Label offset X component.</param>
        /// <param name="labelOffsetY">Label offset Y component.</param>
        public void SetLabelOffset(AllViewsForm form,
                                   double labelOffsetX, double labelOffsetY)
        {
            using (Transaction t = new Transaction(m_doc, "Change label offset"))
            {
                t.Start();

                m_VP.LabelOffset = new XYZ(labelOffsetX, labelOffsetY, 0.0);

                t.Commit();

                UpdateViewportProperties(form);
            }
        }
        /// <summary>
        /// Update Form data members bonded to UI controls.
        /// </summary>
        /// <param name="form">The Form to be updated.</param>
        public void UpdateViewportProperties(AllViewsForm form)
        {
            form.m_getMinBoxOutline = m_VP.GetBoxOutline().MinimumPoint;
            form.m_getMaxBoxOutline = m_VP.GetBoxOutline().MaximumPoint;

            form.m_getMinLabelOutline = m_VP.GetLabelOutline().MinimumPoint;
            form.m_getMaxLabelOutline = m_VP.GetLabelOutline().MaximumPoint;

            form.m_getLabelLineOffset = m_VP.LabelOffset;
            form.m_getLabelLineLength = m_VP.LabelLineLength;

            form.m_getBoxCenter   = m_VP.GetBoxCenter();
            form.m_getOrientation = m_VP.Rotation;
        }
Exemple #7
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 Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData commandData,
                                                ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            Transaction newTran = null;

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

                Document doc  = commandData.Application.ActiveUIDocument.Document;
                ViewsMgr view = new ViewsMgr(doc);

                newTran = new Transaction(doc);
                newTran.Start("AllViews_Sample");

                AllViewsForm dlg = new AllViewsForm(view);

                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    view.GenerateSheets(doc);
                }
                newTran.Commit();

                return(Autodesk.Revit.UI.Result.Succeeded);
            }
            catch (Exception e)
            {
                // message = e.Message;
                if (e.Message == "viewId cannot be added to the ViewSheet." + Environment.NewLine + "Parameter name: viewId")
                {
                    TaskDialog.Show("Error", "Cannot reuse the same view");
                }
                else
                {
                    message = e.Message;
                }
                if ((newTran != null) && newTran.HasStarted() && !newTran.HasEnded())
                {
                    newTran.RollBack();
                }
                return(Autodesk.Revit.UI.Result.Failed);
            }
        }
        /// <summary>
        /// Select a viewport by its associated view name and sheet name.
        /// </summary>
        /// <param name="form">The Form to be updated.</param>
        /// <param name="selectSheetName"> Sheet name.</param>
        /// <param name="selectAssociatedViewName">Associated view name.</param>
        public bool SelectViewport(AllViewsForm form, string selectSheetName, string selectAssociatedViewName)
        {
            m_VP = null;
            form.invalidViewport = true;

            FilteredElementCollector fec = new FilteredElementCollector(m_doc);

            fec.OfClass(typeof(Autodesk.Revit.DB.View));
            var viewSheets = fec.Cast <Autodesk.Revit.DB.View>().Where <Autodesk.Revit.DB.View>(vp => !vp.IsTemplate && vp.ViewType == ViewType.DrawingSheet);

            foreach (var view in viewSheets)
            {
                if (view.Name.Equals(selectSheetName))
                {
                    ViewSheet viewSheet = (ViewSheet)view;
                    foreach (var vp in viewSheet.GetAllViewports())
                    {
                        Viewport VP = (Viewport)(m_doc.GetElement(vp));

                        Autodesk.Revit.DB.View associatedView = m_doc.GetElement(VP.ViewId) as Autodesk.Revit.DB.View;

                        if (associatedView.Name.Equals(selectAssociatedViewName))
                        {
                            m_VP = VP;
                            break;
                        }
                    }
                }
            }

            if (m_VP == null)
            {
                throw new InvalidOperationException("Viewport not found.");
            }

            form.invalidViewport = false;
            UpdateViewportProperties(form);
            return(true);
        }
Exemple #9
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 Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData commandData,
                                                ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            Transaction newTran = null;

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

                Document doc  = commandData.Application.ActiveUIDocument.Document;
                ViewsMgr view = new ViewsMgr(doc);

                newTran = new Transaction(doc);
                newTran.Start("AllViews_Sample");

                AllViewsForm dlg = new AllViewsForm(view);

                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    view.GenerateSheet(doc);
                }
                newTran.Commit();

                return(Autodesk.Revit.UI.Result.Succeeded);
            }
            catch (Exception e)
            {
                message = e.Message;
                if ((newTran != null) && newTran.HasStarted() && !newTran.HasEnded())
                {
                    newTran.RollBack();
                }
                return(Autodesk.Revit.UI.Result.Failed);
            }
        }