Esempio n. 1
0
        /// <summary>
        /// Select elements in Revit to obtain the footprint roof lines.
        /// </summary>
        /// <returns>A curve array to hold the footprint roof lines.</returns>
        public CurveArray SelectFootPrint()
        {
            m_footPrint.Clear();
            while (true)
            {
                ElementSet es = new ElementSet();
                foreach (ElementId elementId in m_selection.GetElementIds())
                {
                    es.Insert(m_commandData.Application.ActiveUIDocument.Document.GetElement(elementId));
                }
                es.Clear();
                IList <Element> selectResult;
                try
                {
                    selectResult = m_selection.PickElementsByRectangle();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    break;
                }

                if (selectResult.Count != 0)
                {
                    foreach (Autodesk.Revit.DB.Element element in selectResult)
                    {
                        Wall wall = element as Wall;
                        if (wall != null)
                        {
                            LocationCurve wallCurve = wall.Location as LocationCurve;
                            m_footPrint.Append(wallCurve.Curve);
                            continue;
                        }

                        ModelCurve modelCurve = element as ModelCurve;
                        if (modelCurve != null)
                        {
                            m_footPrint.Append(modelCurve.GeometryCurve);
                        }
                    }
                    break;
                }
                else
                {
                    TaskDialogResult result = TaskDialog.Show("Warning", "You should select a curve loop, or a wall loop, or loops combination \r\nof walls and curves to create a footprint roof.", TaskDialogCommonButtons.Ok | TaskDialogCommonButtons.Cancel);
                    if (result == TaskDialogResult.Cancel)
                    {
                        break;
                    }
                }
            }

            return(m_footPrint);
        }
        /// <summary>
        /// found the element which using the GUID
        /// that was assigned to the shared parameter in the shared parameters file.
        /// </summary>
        /// <param name="UniqueIdValue"></param>
        public void FindElement(string UniqueIdValue)
        {
            ElementSet seleElements = new ElementSet();

            foreach (ElementId elementId in m_revit.ActiveUIDocument.Selection.GetElementIds())
            {
                seleElements.Insert(m_revit.ActiveUIDocument.Document.GetElement(elementId));
            }

            // all the elements of current document
            IEnumerator i = seleElements.GetEnumerator();


            // if the selections include beams and slabs,
            // find out the element using the select value for display
            i.Reset();
            bool moreElements = i.MoveNext();

            while (moreElements)
            {
                // Get beams and slabs from selections
                Element component = i.Current as Autodesk.Revit.DB.Element;

                if (null == component)
                {
                    moreElements = i.MoveNext();
                    continue;
                }

                if (null == component.Category)
                {
                    moreElements = i.MoveNext();
                    continue;
                }

                if (("Structural Framing" != component.Category.Name) &&
                    ("Floors" != component.Category.Name))
                {
                    moreElements = i.MoveNext();
                    continue;
                }

                // Get "Unique ID" parameter
                ParameterSet attributes = component.Parameters;

                foreach (object o in attributes)
                {
                    Parameter attribute = o as Parameter;

                    if ("Unique ID" == attribute.Definition.Name)
                    {
                        if (null == attribute.AsString())
                        {
                            break;
                        }

                        // compare if the parameter's value is the same as the selected value.
                        // Clear the SelElementSet and add the found element into it.
                        // So this element will highlight in Revit UI
                        if (UniqueIdValue == attribute.AsString())
                        {
                            seleElements.Clear();
                            seleElements.Insert(component);
                            return;
                        }

                        break;
                    }
                }

                moreElements = i.MoveNext();
            }
        }
Esempio n. 3
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            #region 1.2.a. Examine command data input argument:
            //
            // access application, document, and current view:
            //
            UIApplication uiapp = commandData.Application;
            Application   app   = uiapp.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Document      doc   = uidoc.Document;
            View          view  = commandData.View;
            LanguageType  lt    = app.Language;
            ProductType   pt    = app.Product;
            string        s     = "Application = " + app.VersionName
                                  + "\r\nLanguage = " + lt.ToString()
                                  + "\r\nProduct = " + pt.ToString()
                                  + "\r\nVersion = " + app.VersionNumber
                                  + "\r\nDocument path = " + doc.PathName // empty if not yet saved
                                  + "\r\nDocument title = " + doc.Title
                                  + "\r\nView name = " + view.Name;
            LabUtils.InfoMsg(s);
            #endregion // 1.2.a. Examine command data input argument

            #region 1.2.b. List selection set content:
            //
            // list the current selection set:
            //
            Selection     sel = uidoc.Selection;
            List <string> a   = new List <string>();
            foreach (ElementId id in sel.GetElementIds())
            {
                Element e = doc.GetElement(id);

                string name = (null == e.Category)
          ? e.GetType().Name
          : e.Category.Name;

                a.Add(name + " Id="
                      + e.Id.IntegerValue.ToString());
            }
            LabUtils.InfoMsg(
                "There are {0} element{1} in the selection set{2}",
                a);

            #endregion // 1.2.b. List selection set content

            #region 1.2.c. Populate return arguments:

            // We pretend that something is wrong with the
            // first element in the selection. Pass an error
            // message back to the user and indicate the
            // error result:

            ICollection <ElementId> ids = sel.GetElementIds();

            if (0 < ids.Count)
            {
                //ElementSetIterator iter = sel.Elements.ForwardIterator();
                //iter.MoveNext();
                //Element errElem = iter.Current as Element;

                Element errElem = doc.GetElement(ids.First());
                elements.Clear();
                elements.Insert(errElem);
                message = "We pretend something is wrong with this "
                          + " element and pass back this message to user";

                return(Result.Failed);
            }
            else
            {
                // We return failed here as well.
                // As long as the message string and element set are empty,
                // it makes no difference to the user.
                // If they are not empty, the message is displayed to the
                // user and/or the elements in the set are highlighted.
                // If an automatic transaction is open, it is aborted,
                // avoiding marking the database as dirty.

                return(Result.Failed);
            }
            #endregion // 1.2.c. Populate return arguments
        }
Esempio n. 4
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            #region 1.2.a. Examine command data input argument:
              //
              // access application, document, and current view:
              //
              UIApplication uiapp = commandData.Application;
              Application app = uiapp.Application;
              UIDocument uidoc = uiapp.ActiveUIDocument;
              Document doc = uidoc.Document;
              View view = commandData.View;
              LanguageType lt = app.Language;
              ProductType pt = app.Product;
              string s = "Application = " + app.VersionName
            + "\r\nLanguage = " + lt.ToString()
            + "\r\nProduct = " + pt.ToString()
            + "\r\nVersion = " + app.VersionNumber
            + "\r\nDocument path = " + doc.PathName // empty if not yet saved
            + "\r\nDocument title = " + doc.Title
            + "\r\nView name = " + view.Name;
              LabUtils.InfoMsg( s );
              #endregion // 1.2.a. Examine command data input argument

              #region 1.2.b. List selection set content:
              //
              // list the current selection set:
              //
              Selection sel = uidoc.Selection;
              List<string> a = new List<string>();
              foreach( ElementId id in sel.GetElementIds() )
              {
            Element e = doc.GetElement( id );

            string name = ( null == e.Category )
              ? e.GetType().Name
              : e.Category.Name;

            a.Add( name + " Id="
              + e.Id.IntegerValue.ToString() );
              }
              LabUtils.InfoMsg(
            "There are {0} element{1} in the selection set{2}",
            a );

              #endregion // 1.2.b. List selection set content

              #region 1.2.c. Populate return arguments:

              // We pretend that something is wrong with the
              // first element in the selection. Pass an error
              // message back to the user and indicate the
              // error result:

              ICollection<ElementId> ids = sel.GetElementIds();

              if( 0 < ids.Count )
              {
            //ElementSetIterator iter = sel.Elements.ForwardIterator();
            //iter.MoveNext();
            //Element errElem = iter.Current as Element;

            Element errElem = doc.GetElement( ids.First()  );
            elements.Clear();
            elements.Insert( errElem );
            message = "We pretend something is wrong with this "
              + " element and pass back this message to user";

            return Result.Failed;
              }
              else
              {
            // We return failed here as well.
            // As long as the message string and element set are empty,
            // it makes no difference to the user.
            // If they are not empty, the message is displayed to the
            // user and/or the elements in the set are highlighted.
            // If an automatic transaction is open, it is aborted,
            // avoiding marking the database as dirty.

            return Result.Failed;
              }
              #endregion // 1.2.c. Populate return arguments
        }