private void UnhideAllElements(Document myDoc)
        {
            List <ElementId> allNonViewElementsIds = new List <ElementId>();

            FilteredElementCollector docFilter = new FilteredElementCollector(myDoc);

            if (docFilter != null)
            {
                FilteredElementIterator docIterator = docFilter.WhereElementIsNotElementType().GetElementIterator();

                while (docIterator.MoveNext())
                {
                    Element curElem = docIterator.Current;
                    if (!(curElem is Autodesk.Revit.DB.View))
                    {
                        allNonViewElementsIds.Add(curElem.Id);
                    }
                }
            }

            List <View> allViews = GetAllViews(myDoc);

            foreach (View curView in allViews)
            {
                curView.UnhideElements(allNonViewElementsIds);
            }
        }
Пример #2
0
        /// <summary>
        /// iterate all the symbols of levels and beams
        /// </summary>
        /// <returns>A value that signifies if the initialization was successful for true or failed for false</returns>
        private bool Initialize()
        {
            try
            {
                ElementClassFilter       levelFilter = new ElementClassFilter(typeof(Level));
                ElementClassFilter       famFilter   = new ElementClassFilter(typeof(Family));
                LogicalOrFilter          orFilter    = new LogicalOrFilter(levelFilter, famFilter);
                FilteredElementCollector collector   = new FilteredElementCollector(m_revit.ActiveUIDocument.Document);
                FilteredElementIterator  i           = collector.WherePasses(orFilter).GetElementIterator();
                i.Reset();
                bool moreElement = i.MoveNext();
                while (moreElement)
                {
                    object o = i.Current;

                    // add level to list
                    Level level = o as Level;
                    if (null != level)
                    {
                        m_levels.Add(new LevelMap(level));
                        goto nextLoop;
                    }

                    // get
                    Family f = o as Family;
                    if (null == f)
                    {
                        goto nextLoop;
                    }

                    foreach (ElementId elementId in f.GetFamilySymbolIds())
                    {
                        object       symbol     = m_revit.ActiveUIDocument.Document.GetElement(elementId);
                        FamilySymbol familyType = symbol as FamilySymbol;
                        if (null == familyType)
                        {
                            goto nextLoop;
                        }
                        if (null == familyType.Category)
                        {
                            goto nextLoop;
                        }

                        // add symbols of beams and braces to lists
                        string categoryName = familyType.Category.Name;
                        if ("Structural Framing" == categoryName)
                        {
                            m_beamMaps.Add(new SymbolMap(familyType));
                        }
                    }
nextLoop:
                    moreElement = i.MoveNext();
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
            return(true);
        }
Пример #3
0
        /// <summary>
        /// Get the levels and wall types from revit and insert into the lists
        /// </summary>
        private void InitializeListData()
        {
            // Assert the lists have been constructed
            if (null == m_wallTypeList || null == m_levelList)
            {
                throw new Exception("necessary data members don't initialize.");
            }

            // Get all wall types from revit
            Document document = m_commandData.Application.ActiveUIDocument.Document;
            FilteredElementCollector filteredElementCollector = new FilteredElementCollector(document);

            filteredElementCollector.OfClass(typeof(WallType));
            m_wallTypeList = filteredElementCollector.Cast <WallType>().ToList <WallType>();

            // Sort the wall type list by the name property
            WallTypeComparer comparer = new WallTypeComparer();

            m_wallTypeList.Sort(comparer);

            // Get all levels from revit
            FilteredElementIterator iter = (new FilteredElementCollector(document)).OfClass(typeof(Level)).GetElementIterator();

            iter.Reset();
            while (iter.MoveNext())
            {
                Level level = iter.Current as Level;
                if (null == level)
                {
                    continue;
                }
                m_levelList.Add(level);
            }
        }
Пример #4
0
        /// <summary>
        /// 获取文档下的所有视图
        /// </summary>
        /// <param name="doc"></param>
        /// <returns></returns>
        public static ViewSet GetAllViews(Document doc)
        {
            ViewSet views = new ViewSet();
            FilteredElementCollector collector = new FilteredElementCollector(doc);
            FilteredElementIterator  it        = collector.OfClass(typeof(View)).GetElementIterator();

            it.Reset();
            while (it.MoveNext())
            {
                View view = it.Current as View3D;
                if (null != view && !view.IsTemplate && view.CanBePrinted)
                {
                    views.Insert(view);
                }
                else if (null == view)
                {
                    View view2D = it.Current as View;
                    if (view2D.ViewType == ViewType.FloorPlan | view2D.ViewType == ViewType.CeilingPlan | view2D.ViewType == ViewType.AreaPlan | view2D.ViewType == ViewType.Elevation | view2D.ViewType == ViewType.Section)
                    {
                        views.Insert(view2D);
                    }
                }
            }
            return(views);
        }
Пример #5
0
        /// <summary>
        /// find Column which will be used to placed to Wall
        /// </summary>
        /// <param name="rvtDoc">Revit document</param>
        /// <param name="familyName">Family name of Column</param>
        /// <param name="symbolName">Symbol of Column</param>
        /// <returns></returns>
        private FamilySymbol FindFamilySymbol(Document rvtDoc, string familyName, string symbolName)
        {
            FilteredElementCollector collector = new FilteredElementCollector(rvtDoc);
            FilteredElementIterator  itr       = collector.OfClass(typeof(Family)).GetElementIterator();

            itr.Reset();
            while (itr.MoveNext())
            {
                Autodesk.Revit.DB.Element elem = (Autodesk.Revit.DB.Element)itr.Current;
                if (elem.GetType() == typeof(Autodesk.Revit.DB.Family))
                {
                    if (elem.Name == familyName)
                    {
                        Autodesk.Revit.DB.Family family = (Autodesk.Revit.DB.Family)elem;
                        foreach (Autodesk.Revit.DB.ElementId symbolId in family.GetFamilySymbolIds())
                        {
                            Autodesk.Revit.DB.FamilySymbol symbol = (Autodesk.Revit.DB.FamilySymbol)rvtDoc.GetElement(symbolId);
                            if (symbol.Name == symbolName)
                            {
                                return(symbol);
                            }
                        }
                    }
                }
            }
            return(null);
        }
Пример #6
0
        /// <summary>
        /// Get all printable views and sheets
        /// </summary>
        private void GetAllPrintableViews()
        {
            FilteredElementCollector collector = new FilteredElementCollector(m_commandData.Application.ActiveUIDocument.Document);
            FilteredElementIterator  itor      = collector.OfClass(typeof(View)).GetElementIterator();

            itor.Reset();
            m_printableViews.Clear();
            m_printableSheets.Clear();

            while (itor.MoveNext())
            {
                View view = itor.Current as View;
                // skip view templates because they're invisible in project browser, invalid for print
                if (null == view || view.IsTemplate || !view.CanBePrinted)
                {
                    continue;
                }
                else if (view.ViewType == Autodesk.Revit.DB.ViewType.DrawingSheet)
                {
                    m_printableSheets.Insert(view);
                }
                else
                {
                    m_printableViews.Insert(view);
                }
            }
        }
Пример #7
0
        /// <summary>
        /// get all the rooms and room tags in the project
        /// </summary>
        private void GetAllRoomsAndTags()
        {
            // get the active document
            Document        document      = m_revit.ActiveUIDocument.Document;
            RoomFilter      roomFilter    = new RoomFilter();
            RoomTagFilter   roomTagFilter = new RoomTagFilter();
            LogicalOrFilter orFilter      = new LogicalOrFilter(roomFilter, roomTagFilter);

            FilteredElementIterator elementIterator =
                (new FilteredElementCollector(document)).WherePasses(orFilter).GetElementIterator();

            elementIterator.Reset();

            // try to find all the rooms and room tags in the project and add to the list
            while (elementIterator.MoveNext())
            {
                object obj = elementIterator.Current;

                // find the rooms, skip those rooms which don't locate at Level yet.
                Room tmpRoom = obj as Room;
                if (null != tmpRoom && null != tmpRoom.Level)
                {
                    m_rooms.Add(tmpRoom);
                    continue;
                }

                // find the room tags
                RoomTag tmpTag = obj as RoomTag;
                if (null != tmpTag)
                {
                    m_roomTags.Add(tmpTag);
                    continue;
                }
            }
        }
Пример #8
0
        /// <summary>
        /// Obtain all data which is necessary for generate floor.
        /// </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>
        public void ObtainData(ExternalCommandData commandData)
        {
            if (null == commandData)
            {
                throw new ArgumentNullException("commandData");
            }

            UIDocument doc = commandData.Application.ActiveUIDocument;

            m_document = doc.Document;
            ElementSet es = new ElementSet();

            foreach (ElementId elementId in doc.Selection.GetElementIds())
            {
                es.Insert(doc.Document.GetElement(elementId));
            }

            ElementSet walls = WallFilter(es);

            m_creApp = commandData.Application.Application.Create;
            Profile  = m_creApp.NewCurveArray();

            FilteredElementIterator iter = (new FilteredElementCollector(doc.Document))
                                           .OfClass(typeof(FloorType))
                                           .GetElementIterator();

            ObtainFloorTypes(iter);
            ObtainProfile(walls);
            ObtainLevel(walls);
            Generate2D();
            Structural = true;
        }
Пример #9
0
        private void geSelectedtViewportsIdsAndPositions()
        {
            this.selViewportsIdsAndPositions.Clear();

            FilteredElementCollector docFilter = new FilteredElementCollector(doc).OfClass(typeof(Autodesk.Revit.DB.Viewport));

            if (docFilter != null)
            {
                FilteredElementIterator docFilterIterator = docFilter.GetElementIterator();
                while (docFilterIterator.MoveNext())
                {
                    Autodesk.Revit.DB.Viewport curViewport = docFilterIterator.Current as Autodesk.Revit.DB.Viewport;
                    if (curViewport != null)
                    {
                        ElementId curViewId = curViewport.ViewId;
                        if (curViewId != null)
                        {
                            Autodesk.Revit.DB.View curView = doc.GetElement(curViewId) as Autodesk.Revit.DB.View;
                            if (curView != null)
                            {
                                if (curView.Scale == this.selectedScale)
                                {
                                    XYZ curXYZ = curViewport.GetBoxCenter();
                                    this.selViewportsIdsAndPositions.Add(curViewport.Id, curXYZ);
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #10
0
        /// <summary>
        /// Get all reference planes in current revit project.
        /// </summary>
        /// <returns>The number of all reference planes.</returns>
        private int GetAllReferencePlanes()
        {
            m_referencePlanes.Clear();
            DataRow row;

            FilteredElementIterator itor = (new FilteredElementCollector(m_document.Document)).OfClass(typeof(Autodesk.Revit.DB.ReferencePlane)).GetElementIterator();

            Autodesk.Revit.DB.ReferencePlane refPlane = null;

            itor.Reset();
            while (itor.MoveNext())
            {
                refPlane = itor.Current as Autodesk.Revit.DB.ReferencePlane;
                if (null == refPlane)
                {
                    continue;
                }
                else
                {
                    row              = m_referencePlanes.NewRow();
                    row["ID"]        = refPlane.Id.IntegerValue;
                    row["BubbleEnd"] = Format(refPlane.BubbleEnd);
                    row["FreeEnd"]   = Format(refPlane.FreeEnd);
                    row["Normal"]    = Format(refPlane.Normal);
                    m_referencePlanes.Rows.Add(row);
                }
            }

            return(m_referencePlanes.Rows.Count);
        }
Пример #11
0
        /// <summary>
        /// Scans all elements in the active document and creates a list of
        /// the categories of those elements.
        /// </summary>
        /// <returns>Sorted dictionary of categories.</returns>
        public SortedDictionary <string, Category> ScanCategories()
        {
            m_Categories = new SortedDictionary <string, Category>();

            // get all elements in the active document
            FilteredElementCollector filterCollector = new FilteredElementCollector(m_ActiveDocument);

            filterCollector.WhereElementIsNotElementType();

            FilteredElementIterator iterator = filterCollector.GetElementIterator();

            // create sorted dictionary of the categories of the elements
            while (iterator.MoveNext())
            {
                Element element = iterator.Current;

                if (element.Category != null)
                {
                    if (!m_Categories.ContainsKey(element.Category.Name))
                    {
                        m_Categories.Add(element.Category.Name, element.Category);
                    }
                }
            }

            return(m_Categories);
        }
Пример #12
0
        /// <summary>
        /// Iterates through all the BarDescriptions in the project.
        /// store these data in a data table m_barDescriptions and
        /// store the AreaReinforcements id value in a array list m_areaReinforcementIdList
        /// </summary>
        private bool PrepareAllNeededData()
        {
            // reset the Columns of data table m_barDescriptions
            SetDataTableCloumn();

            AreaReinforcement       tempAreaReinforcement = null;
            FilteredElementIterator i = (new FilteredElementCollector(m_revit.Application.ActiveUIDocument.Document)).OfClass(typeof(AreaReinforcement)).GetElementIterator();

            while (i.MoveNext())
            {
                tempAreaReinforcement = i.Current as AreaReinforcement;
                if (tempAreaReinforcement != null)
                {
                    // store all the AreaReinforcements id value in a array list m_areaReinforcementIdList
                    m_areaReinforcementIdList.Add(tempAreaReinforcement.Id.IntegerValue);

                    // store BarDescriptions in a data table m_barDescriptions
                    for (int j = 0; j < tempAreaReinforcement.NumBarDescriptions; j++)
                    {
                        BarDescription barDescription = tempAreaReinforcement.get_BarDescription(j);

                        SetCurrentBarDescriptionToTable(tempAreaReinforcement, barDescription);
                    }
                }
            }

            if (null == tempAreaReinforcement)
            {
                return(false);
            }
            return(true);
        }
Пример #13
0
        /// <summary>
        /// Finds all the views in the active document.
        /// </summary>
        /// <param name="doc">the active document</param>
        private void GetAllViews(Document doc)
        {
            FilteredElementCollector collector = new FilteredElementCollector(doc);
            FilteredElementIterator  itor      = collector.OfClass(typeof(Autodesk.Revit.DB.View)).GetElementIterator();

            itor.Reset();
            while (itor.MoveNext())
            {
                Autodesk.Revit.DB.View view = itor.Current as Autodesk.Revit.DB.View;
                // skip view templates because they're invisible in project browser
                if (null == view || view.IsTemplate)
                {
                    continue;
                }
                else
                {
                    ElementType objType = doc.GetElement(view.GetTypeId()) as ElementType;
                    if (null == objType || objType.Name.Equals("Schedule") ||
                        objType.Name.Equals("Drawing Sheet"))
                    {
                        continue;
                    }
                    else
                    {
                        m_allViews.Insert(view);
                        AssortViews(view.Name, objType.Name);
                    }
                }
            }
        }
Пример #14
0
        /// <summary>
        /// The top level command.
        /// </summary>
        /// <param name="revit">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)
        {
            // Initialization
            m_app = revit.Application;
            m_doc = revit.Application.ActiveUIDocument.Document;

            // Find a 3D view to use for the ray tracing operation
            Get3DView("{3D}");

            Selection   selection    = revit.Application.ActiveUIDocument.Selection;
            List <Wall> wallsToCheck = new List <Wall>();

            // If wall(s) are selected, process them.
            if (selection.Elements.Size > 0)
            {
                foreach (Autodesk.Revit.DB.Element e in selection.Elements)
                {
                    if (e is Wall)
                    {
                        wallsToCheck.Add((Wall)e);
                    }
                }

                if (wallsToCheck.Count <= 0)
                {
                    message = "No walls were found in the active document selection";
                    return(Result.Cancelled);
                }
            }
            // Find all walls in the document and process them.
            else
            {
                FilteredElementCollector collector = new FilteredElementCollector(m_doc);
                FilteredElementIterator  iter      = collector.OfClass(typeof(Wall)).GetElementIterator();
                iter.Reset();
                while (iter.MoveNext())
                {
                    wallsToCheck.Add((Wall)iter.Current);
                }
            }

            // Execute the check for embedded columns
            CheckWallsForEmbeddedColumns(wallsToCheck);

            // Process the results, in this case set the active selection to contain all embedded columns
            if (m_allColumnsOnWalls.Count > 0)
            {
                foreach (ElementId id in m_allColumnsOnWalls)
                {
                    ElementId familyInstanceId = id;
                    Autodesk.Revit.DB.Element familyInstance = m_doc.GetElement(familyInstanceId);
                    selection.Elements.Add(familyInstance);
                }
            }
            return(Result.Succeeded);
        }
Пример #15
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            m_app = commandData.Application;
            m_doc = commandData.Application.ActiveUIDocument.Document;

            Get3DView("{3D}");

            Selection   selection    = m_app.ActiveUIDocument.Selection;
            List <Wall> wallsToCheck = new List <Wall>();

            // If wall(s) are selected, process them.
            if (selection.GetElementIds().Count > 0)
            {
                foreach (ElementId eId in selection.GetElementIds())
                {
                    Element e = m_doc.GetElement(eId);
                    if (e is Wall)
                    {
                        wallsToCheck.Add((Wall)e);
                    }
                }

                if (wallsToCheck.Count <= 0)
                {
                    message = "No walls were found in the active document selection";
                    return(Result.Cancelled);
                }
            }
            // Find all walls in the document and process them.
            else
            {
                FilteredElementCollector collector = new FilteredElementCollector(m_doc);
                FilteredElementIterator  iter      = collector.OfClass(typeof(Wall)).GetElementIterator();
                while (iter.MoveNext())
                {
                    wallsToCheck.Add((Wall)iter.Current);
                }
            }

            // Execute the check for embedded columns
            CheckWallsForEmbeddedColumns(wallsToCheck);

            // Process the results, in this case set the active selection to contain all embedded columns
            ICollection <ElementId> toSelected = new List <ElementId>();

            if (m_allColumnsOnWalls.Count > 0)
            {
                foreach (ElementId id in m_allColumnsOnWalls)
                {
                    ElementId familyInstanceId = id;
                    Element   familyInstance   = m_doc.GetElement(familyInstanceId);
                    toSelected.Add(familyInstance.Id);
                }
                selection.SetElementIds(toSelected);
            }
            return(Result.Succeeded);
        }
Пример #16
0
        /// <summary>
        /// check whether the selected is expected, find all hooktypes in current project
        /// </summary>
        /// <param name="selected">selected elements</param>
        /// <returns>whether the selected AreaReinforcement is expected</returns>
        private bool PreData()
        {
            ElementSet selected = m_commandData.Application.ActiveUIDocument.Selection.Elements;

            //selected is not only one AreaReinforcement
            if (selected.Size != 1)
            {
                return(false);
            }
            foreach (Object o in selected)
            {
                m_areaRein = o as AreaReinforcement;
            }
            if (null == m_areaRein)
            {
                return(false);
            }

            //make sure hook type and bar type exist in current project and get them
            m_hookTypes = new Hashtable();
            m_barTypes  = new Hashtable();

            Document activeDoc = m_commandData.Application.ActiveUIDocument.Document;


            FilteredElementIterator itor = (new FilteredElementCollector(activeDoc)).OfClass(typeof(RebarHookType)).GetElementIterator();

            itor.Reset();
            while (itor.MoveNext())
            {
                RebarHookType hookType = itor.Current as RebarHookType;
                if (null != hookType)
                {
                    string hookTypeName = hookType.Name;
                    m_hookTypes.Add(hookTypeName, hookType.Id);
                }
            }

            itor = (new FilteredElementCollector(activeDoc)).OfClass(typeof(RebarBarType)).GetElementIterator();
            itor.Reset();
            while (itor.MoveNext())
            {
                RebarBarType barType = itor.Current as RebarBarType;
                if (null != barType)
                {
                    string barTypeName = barType.Name;
                    m_barTypes.Add(barTypeName, barType.Id);
                }
            }
            if (m_hookTypes.Count == 0 || m_barTypes.Count == 0)
            {
                return(false);
            }

            return(true);
        }
Пример #17
0
        /// <summary>
        /// Find out all useful elements.
        /// </summary>
        private void FindElements()
        {
            IList <ElementFilter> filters = new List <ElementFilter>(4);

            filters.Add(new ElementClassFilter(typeof(Level)));
            filters.Add(new ElementClassFilter(typeof(View)));
            filters.Add(new ElementClassFilter(typeof(Floor)));
            filters.Add(new ElementClassFilter(typeof(FloorType)));

            LogicalOrFilter          orFilter  = new LogicalOrFilter(filters);
            FilteredElementCollector collector = new FilteredElementCollector(m_revit.ActiveUIDocument.Document);
            FilteredElementIterator  iterator  = collector.WherePasses(orFilter).GetElementIterator();

            while (iterator.MoveNext())
            {
                // Find out all levels.
                Level level = (iterator.Current) as Level;
                if (null != level)
                {
                    m_levelList.Add(level.Elevation, level);
                    continue;
                }

                // Find out all views.
                View view = (iterator.Current) as View;
                if (null != view && !view.IsTemplate)
                {
                    m_viewList.Add(view);
                    continue;
                }

                // Find out all floors.
                Floor floor = (iterator.Current) as Floor;
                if (null != floor)
                {
                    m_floorList.Add(floor);
                    continue;
                }

                // Find out all foundation slab types.
                FloorType floorType = (iterator.Current) as FloorType;
                if (null == floorType)
                {
                    continue;
                }
                if ("Structural Foundations" == floorType.Category.Name)
                {
                    m_slabTypeList.Add(floorType);
                }
            }
        }
Пример #18
0
        /// <summary>
        /// Initialize the data member
        /// </summary>
        private void Initialize()
        {
            Document doc = m_commandData.Application.ActiveUIDocument.Document;
            FilteredElementIterator iter = (new FilteredElementCollector(doc)).OfClass(typeof(Level)).GetElementIterator();

            iter.Reset();
            while (iter.MoveNext())
            {
                m_levels.Add(iter.Current as Level);
            }

            foreach (RoofType roofType in m_commandData.Application.ActiveUIDocument.Document.RoofTypes)
            {
                m_roofTypes.Add(roofType);
            }

            // FootPrint Roofs
            m_footPrintRoofs = new ElementSet();
            iter             = (new FilteredElementCollector(doc)).OfClass(typeof(FootPrintRoof)).GetElementIterator();
            iter.Reset();
            while (iter.MoveNext())
            {
                m_footPrintRoofs.Insert(iter.Current as FootPrintRoof);
            }

            // Extrusion Roofs
            m_extrusionRoofs = new ElementSet();
            iter             = (new FilteredElementCollector(doc)).OfClass(typeof(ExtrusionRoof)).GetElementIterator();
            iter.Reset();
            while (iter.MoveNext())
            {
                m_extrusionRoofs.Insert(iter.Current as ExtrusionRoof);
            }

            // Reference Planes
            iter = (new FilteredElementCollector(doc)).OfClass(typeof(ReferencePlane)).GetElementIterator();
            iter.Reset();
            while (iter.MoveNext())
            {
                ReferencePlane plane = iter.Current as ReferencePlane;
                // just use the vertical plane
                if (Math.Abs(plane.Normal.DotProduct(Autodesk.Revit.DB.XYZ.BasisZ)) < 1.0e-09)
                {
                    if (plane.Name == "Reference Plane")
                    {
                        plane.Name = "Reference Plane" + "(" + plane.Id.IntegerValue.ToString() + ")";
                    }
                    m_referencePlanes.Add(plane);
                }
            }
        }
Пример #19
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(ExternalCommandData commandData,
                                                ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            Transaction transaction = new Transaction(commandData.Application.ActiveUIDocument.Document, "External Tool");

            try
            {
                transaction.Start();
                Application app         = commandData.Application.Application;
                bool        haveOpening = false;

                //search Opening in Revit
                List <OpeningInfo>      openingInfos = new List <OpeningInfo>();
                FilteredElementIterator iter         = (new FilteredElementCollector(commandData.Application.ActiveUIDocument.Document)).OfClass(typeof(Opening)).GetElementIterator();
                iter.Reset();
                while (iter.MoveNext())
                {
                    Object obj = iter.Current;
                    if (obj is Opening)
                    {
                        haveOpening = true;
                        Opening     opening     = obj as Opening;
                        OpeningInfo openingInfo = new OpeningInfo(opening, commandData.Application);
                        openingInfos.Add(openingInfo);
                    }
                }

                if (!haveOpening)
                {
                    message = "don't have opening in the project";
                    return(Autodesk.Revit.UI.Result.Cancelled);
                }

                //show dialogue
                using (OpeningForm openingForm = new OpeningForm(openingInfos))
                {
                    openingForm.ShowDialog();
                }
            }
            catch (Exception e)
            {
                message = e.ToString();
                return(Autodesk.Revit.UI.Result.Failed);
            }
            finally
            {
                transaction.Commit();
            }

            return(Autodesk.Revit.UI.Result.Succeeded);
        }
Пример #20
0
        /// <summary>
        /// constructor
        /// </summary>
        public ObjectViewer()
        {
            UIDocument doc       = Command.CommandData.Application.ActiveUIDocument;
            ElementSet selection = new ElementSet();

            foreach (ElementId elementId in doc.Selection.GetElementIds())
            {
                selection.Insert(doc.Document.GetElement(elementId));
            }
            // only one element should be selected
            if (0 == selection.Size)
            {
                throw new ErrorMessageException("Please select an element.");
            }

            if (1 < selection.Size)
            {
                throw new ErrorMessageException("Please select only one element.");
            }
            // get selected element
            foreach (Element e in selection)
            {
                m_selected = e;
            }
            // get current view and all views
            m_currentView = doc.Document.ActiveView;
            FilteredElementIterator itor = (new FilteredElementCollector(doc.Document)).OfClass(typeof(View)).GetElementIterator();

            itor.Reset();
            while (itor.MoveNext())
            {
                View view = itor.Current as View;
                // Skip view templates because they're invisible in project browser, invalid for geometry elements
                if (null != view && !view.IsTemplate)
                {
                    m_allViews.Add(view);
                }
            }

            // create a instance of Sketch3D
            GeometryData geomFactory = new GeometryData(m_selected, m_currentView);

            m_currentSketch3D = new Sketch3D(geomFactory.Data3D, Graphics2DData.Empty);

            //get a instance of ParametersFactory and then use it to create Parameters
            ParasFactory parasFactory = new ParasFactory(m_selected);

            m_paras = parasFactory.CreateParas();
        }
Пример #21
0
        public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elements)
        {
            UIDocument uiDoc = cmdData.Application.ActiveUIDocument;

            try
            {
                Transaction ts = new Transaction(uiDoc.Document, "space");
                ts.Start();

                //Level
                Level level = null;
                FilteredElementIterator levelsIterator = (new FilteredElementCollector(uiDoc.Document)).OfClass(typeof(Level)).GetElementIterator();
                levelsIterator.Reset();
                while (levelsIterator.MoveNext())
                {
                    level = levelsIterator.Current as Level;
                    break;
                }
                using break faction >

                      //Phase面域
                      Parameter para = uiDoc.Document.ActiveView.get_Parameter(BuiltInParameter.VIEW_PHASE);
                ElementId phaseId = para.AsElementId();
                Phase     phase   = uiDoc.Document.get_Element(phaseId) as Phase;

                if (phase == null)
                {
                    System.Windows.Forms.MessageBox.Show("The phase of the active view is null, you can't create spaces in a null phase");
                }

                //CreateSpace
                if (uiDoc.Document.ActiveView.ViewType == ViewType.FloorPlan)
                {
                    uiDoc.Document.Create.NewSpaces(level, phase, uiDoc.ActiveView);
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show("You can not create spaces in this plan view");
                }

                ts.Commit();
            }
            catch (Exception ex)
            {
                TaskDialog.Show("ex", ex.ToString());
            }

            return(Result.Succeeded);
        }
Пример #22
0
        public static T GetElementByNameAs <T>(Document doc, string name) where T : class
        {
            FilteredElementCollector collector = new FilteredElementCollector(doc);
            FilteredElementIterator  it        = collector.OfClass(typeof(View)).GetElementIterator();

            it.Reset();
            while (it.MoveNext())
            {
                if (it.Current.Name == name)
                {
                    return(it.Current as T);
                }
            }
            return(null);
        }
Пример #23
0
        /// <summary>
        /// get all materials exist in current document
        /// </summary>
        /// <returns></returns>
        private void GetAllMaterial()
        {
            FilteredElementCollector collector = new FilteredElementCollector(m_revit.ActiveUIDocument.Document);
            FilteredElementIterator  i         = collector.OfClass(typeof(Material)).GetElementIterator();

            i.Reset();
            bool moreValue = i.MoveNext();

            while (moreValue)
            {
                Autodesk.Revit.DB.Material material = i.Current as Autodesk.Revit.DB.Material;
                if (material == null)
                {
                    moreValue = i.MoveNext();
                    continue;
                }
                //get the type of the material
                Parameter materialAttribute = material.get_Parameter(BuiltInParameter.PHY_MATERIAL_PARAM_TYPE);
                if (materialAttribute == null)
                {
                    moreValue = i.MoveNext();
                    continue;
                }
                //add materials to different ArrayList according to their types
                switch ((MaterialType)materialAttribute.AsInteger())
                {
                case MaterialType.Steel:
                {
                    m_steels.Add(new MaterialMap(material));
                    break;
                }

                case MaterialType.Concrete:
                {
                    m_concretes.Add(new MaterialMap(material));
                    break;
                }

                default:
                {
                    break;
                }
                }
                //map between materials and their elementId
                m_allMaterialMap.Add(material.Id.IntegerValue, material);
                moreValue = i.MoveNext();
            }
        }
Пример #24
0
        /// <summary>
        /// Constructor, initialize all the fields.
        /// </summary>
        /// <param name="rvtDoc">Revit Document</param>
        public Detector(Document rvtDoc)
        {
            m_rvtDoc = rvtDoc;
            FilteredElementCollector collector = new FilteredElementCollector(m_rvtDoc);
            FilteredElementIterator  iter      = collector.OfClass(typeof(View3D)).GetElementIterator();

            iter.Reset();
            while (iter.MoveNext())
            {
                m_view3d = iter.Current as View3D;
                if (null != m_view3d && !m_view3d.IsTemplate)
                {
                    break;
                }
            }
        }
Пример #25
0
        /// <summary>
        /// Initialize the data member, obtain the Space and Zone elements.
        /// </summary>
        private void Initialize()
        {
            Dictionary <int, List <Space> > spaceDictionary = new Dictionary <int, List <Space> >();
            Dictionary <int, List <Zone> >  zoneDictionary  = new Dictionary <int, List <Zone> >();

            Document activeDoc = m_commandData.Application.ActiveUIDocument.Document;

            FilteredElementIterator levelsIterator = (new FilteredElementCollector(activeDoc)).OfClass(typeof(Level)).GetElementIterator();
            FilteredElementIterator spacesIterator = (new FilteredElementCollector(activeDoc)).WherePasses(new SpaceFilter()).GetElementIterator();
            FilteredElementIterator zonesIterator  = (new FilteredElementCollector(activeDoc)).OfClass(typeof(Zone)).GetElementIterator();

            levelsIterator.Reset();
            while (levelsIterator.MoveNext())
            {
                Level level = levelsIterator.Current as Level;
                if (level != null)
                {
                    m_levels.Add(level);
                    spaceDictionary.Add(level.Id.IntegerValue, new List <Space>());
                    zoneDictionary.Add(level.Id.IntegerValue, new List <Zone>());
                }
            }

            spacesIterator.Reset();
            while (spacesIterator.MoveNext())
            {
                Space space = spacesIterator.Current as Space;
                if (space != null)
                {
                    spaceDictionary[space.LevelId.IntegerValue].Add(space);
                }
            }

            zonesIterator.Reset();
            while (zonesIterator.MoveNext())
            {
                Zone zone = zonesIterator.Current as Zone;
                if (zone != null && activeDoc.GetElement(zone.LevelId) != null)
                {
                    zoneDictionary[zone.LevelId.IntegerValue].Add(zone);
                }
            }

            m_spaceManager = new SpaceManager(m_commandData, spaceDictionary);
            m_zoneManager  = new ZoneManager(m_commandData, zoneDictionary);
        }
Пример #26
0
        /// <summary>
        /// Join geometry between overlapping solids.
        /// </summary>
        /// <param name="document">The active document</param>
        /// <returns>The number of geometry combination be joined in this document.</returns>
        public int Join(Document document)
        {
            int combinated = 0;

            // CombinableElement is of an element type that exists in the API, but not in Revit's native object model.
            // We use a combination of GenericForm and GeomCombination elements instead to find all CombinableElement.
            LogicalOrFilter filter = new LogicalOrFilter(
                new ElementClassFilter(typeof(GenericForm)),
                new ElementClassFilter(typeof(GeomCombination)));

            FilteredElementIterator itor = (new FilteredElementCollector(document)).WherePasses(filter).GetElementIterator();

            itor.Reset();
            while (itor.MoveNext())
            {
                GenericForm gf = itor.Current as GenericForm;
                if (null != gf && !gf.IsSolid)
                {
                    continue;
                }

                CombinableElement ce = itor.Current as CombinableElement;
                if (null == ce)
                {
                    continue;
                }
                else
                {
                    m_elements.Add(ce);
                }
            }
            // Added all solid forms in this document.

            while (1 < m_elements.Count)
            {
                GeomCombination geomCombination = JoinOverlapping(m_elements, document);
                if (null == geomCombination)
                {
                    return(combinated);//No overlapping.
                }

                combinated++;
            }

            return(combinated);
        }
        private void CreateDesignOptions(int id)
        {
            StringBuilder strBld = new StringBuilder();

            FilteredElementCollector curColector = new FilteredElementCollector(doc).OfClass(typeof(DesignOption));
            FilteredElementIterator  curIterator = curColector.GetElementIterator();

            while (curIterator.MoveNext())
            {
                Element curElement = curIterator.Current;
                if (curElement.Name.Contains("Option"))
                {
                    string curInfoStr = "";
                    curInfoStr += "Id=" + curElement.Id.ToString() + ", ";
                    curInfoStr += "Name=" + curElement.Name + ", ";

                    ParameterSet orderedParams = curElement.Parameters;
                    foreach (Parameter curParam in orderedParams)
                    {
                        if (curParam.Definition.Name == "Design Option Set Id")
                        {
                            curInfoStr += curParam.Definition.Name + "=" + curParam.AsElementId().ToString();

                            ElementId curDesignOptionSetId = curParam.AsElementId();
                            if (curDesignOptionSetId != null)
                            {
                                Element curDesignOptionSet = doc.GetElement(curDesignOptionSetId);

                                if (curDesignOptionSet != null)
                                {
                                    curInfoStr += ", Design Option Set=" + curDesignOptionSet.Name;
                                }
                            }
                        }
                    }

                    strBld.AppendLine(curInfoStr);
                }
            }


            AlmMessageBox mesBox = new AlmMessageBox(strBld.ToString());

            mesBox.Show();
        }
Пример #28
0
 private void ObtaineViewList(FilteredElementIterator elements)
 {
     this.ViewListName = new List <string>();
     elements.Reset();
     while (elements.MoveNext())
     {
         Element element = elements.Current;
         View3D  view3D  = element as View3D;
         if (view3D != null)
         {
             if (view3D.ViewType == ViewType.ThreeD && view3D.IsTemplate == false)
             {
                 this.ViewListName.Add(view3D.Name);
                 this.ViewListName.Sort();
             }
         }
     }
 }
Пример #29
0
        /// <summary>
        /// get all materials exist in current document
        /// </summary>
        /// <returns></returns>
        private void GetAllMaterial()
        {
            FilteredElementCollector collector = new FilteredElementCollector(m_revit.ActiveUIDocument.Document);
            FilteredElementIterator  i         = collector.OfClass(typeof(Material)).GetElementIterator();

            i.Reset();
            bool moreValue = i.MoveNext();

            while (moreValue)
            {
                Autodesk.Revit.DB.Material material = i.Current as Autodesk.Revit.DB.Material;
                if (material == null)
                {
                    moreValue = i.MoveNext();
                    continue;
                }
                //get the type of the material
                StructuralAssetClass materialType = GetMaterialType(material);

                //add materials to different ArrayList according to their types
                switch (materialType)
                {
                case StructuralAssetClass.Metal:
                {
                    m_steels.Add(new MaterialMap(material));
                    break;
                }

                case StructuralAssetClass.Concrete:
                {
                    m_concretes.Add(new MaterialMap(material));
                    break;
                }

                default:
                {
                    break;
                }
                }
                //map between materials and their elementId
                m_allMaterialMap.Add(material.Id.IntegerValue, material);
                moreValue = i.MoveNext();
            }
        }
        /// <summary>
        /// This method allows user to get view by name
        /// </summary>
        /// <param name="name">the name property of view</param>
        /// <param name="app">the application</param>
        /// <param name="doc">the document</param>
        /// <returns>the view or null</returns>
        /// TBD
        public static View GetViewByName(string name, Application app, Document doc)
        {
            View v = null;
            FilteredElementCollector collector = new FilteredElementCollector(doc);

            collector.OfClass(typeof(View));
            FilteredElementIterator eit = collector.GetElementIterator();

            eit.Reset();
            while (eit.MoveNext())
            {
                v = eit.Current as View;
                if (v.Name.Equals(name))
                {
                    break;
                }
            }
            return(v);
        }
Пример #31
0
Файл: Data.cs Проект: AMEE/revit
        /// <summary>
        /// Obtain all types are available for floor.
        /// </summary>
        /// <param name="elements">all elements within the Document.</param>
        private void ObtainFloorTypes(FilteredElementIterator elements)
        {
            m_floorTypes = new Hashtable();
            FloorTypesName = new List<string>();

            elements.Reset();
            while (elements.MoveNext())
            {
                Autodesk.Revit.DB.FloorType ft = elements.Current as Autodesk.Revit.DB.FloorType;

                if (null == ft || null == ft.Category || !ft.Category.Name.Equals("Floors"))
                {
                    continue;
                }

                m_floorTypes.Add(ft.Name, ft);
                FloorTypesName.Add(ft.Name);
                FloorType = ft;
            }
        }