Example #1
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);
        }
Example #2
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);
                }
            }
        }
Example #3
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);
        }
Example #4
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);
        }
Example #5
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);
                    }
                }
            }
        }
Example #6
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;
                }
            }
        }
Example #7
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);
            }
        }
Example #8
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);
        }
Example #9
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);
        }
Example #10
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);
                }
            }
        }
Example #11
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);
        }
Example #12
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);
        }
Example #13
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);
        }
Example #14
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();
        }
Example #15
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);
        }
        /// <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();
            }
        }
Example #17
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;
                }
            }
        }
Example #18
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);
        }
Example #19
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);
        }
Example #20
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();
             }
         }
     }
 }
        /// <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);
        }
        /// <summary>
        /// This method is used to allow user to get reference plane by name,if there is no proper reference plane,will return null
        /// </summary>
        /// <param name="name">the name property of reference plane</param>
        /// <param name="app">the application</param>
        /// <param name="doc">the document</param>
        /// <returns>the reference plane or null</returns>
        ///  TBD:
        public static ReferencePlane GetRefPlaneByName(string name, Application app, Document doc)
        {
            ReferencePlane           r         = null;
            FilteredElementCollector collector = new FilteredElementCollector(doc);

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

            eit.Reset();
            while (eit.MoveNext())
            {
                r = eit.Current as ReferencePlane;
                if (r.Name.Equals(name))
                {
                    break;
                }
            }
            return(r);
        }
Example #24
0
        public Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData cmdData, ref string msg, ElementSet elems)
        {
            Autodesk.Revit.UI.Result result;

            try
            {
                Snoop.CollectorExts.CollectorExt.m_app       = cmdData.Application;
                Snoop.CollectorExts.CollectorExt.m_activeDoc = cmdData.Application.ActiveUIDocument.Document;  // TBD: see note in CollectorExt.cs

                UIDocument             revitDoc = cmdData.Application.ActiveUIDocument;
                Autodesk.Revit.DB.View view     = revitDoc.Document.ActiveView;
                ElementSet             ss       = cmdData.Application.ActiveUIDocument.Selection.Elements;

                if (ss.Size == 0)
                {
                    FilteredElementCollector collector = new FilteredElementCollector(revitDoc.Document, view.Id);
                    collector.WhereElementIsNotElementType();
                    FilteredElementIterator i = collector.GetElementIterator();
                    i.Reset();
                    ElementSet ss1 = cmdData.Application.Application.Create.NewElementSet();
                    while (i.MoveNext())
                    {
                        Element e = i.Current as Element;
                        ss1.Insert(e);
                    }
                    ss = ss1;
                }

                Snoop.Forms.Objects form = new Snoop.Forms.Objects(ss);
                ActiveDoc.UIApp = cmdData.Application;
                form.ShowDialog();

                result = Autodesk.Revit.UI.Result.Succeeded;
            }
            catch (System.Exception e)
            {
                msg    = e.Message;
                result = Autodesk.Revit.UI.Result.Failed;
            }

            return(result);
        }
            public static List <T> GetElements <T>(Application app, Document doc) where T : Element
            {
                var elements = new List <T>();

                var collector = new FilteredElementCollector(doc);

                collector.OfClass(typeof(T));
                FilteredElementIterator iterator = collector.GetElementIterator();

                iterator.Reset();
                while (iterator.MoveNext())
                {
                    var element = iterator.Current as T;
                    if (element != null)
                    {
                        elements.Add(element);
                    }
                }
                return(elements);
            }
        /// <summary>
        /// This method is used to get elements by type filter
        /// </summary>
        /// <typeparam name="T">the type</typeparam>
        /// <param name="app">the application</param>
        /// <param name="doc">the document</param>
        /// <returns>the list of elements</returns>
        /// TBD
        public static List <T> GetElements <T>(Application app, Document doc) where T : Autodesk.Revit.DB.Element
        {
            List <T> elements = new List <T>();

            FilteredElementCollector collector = new FilteredElementCollector(doc);

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

            eit.Reset();
            while (eit.MoveNext())
            {
                T element = eit.Current as T;
                if (element != null)
                {
                    elements.Add(element);
                }
            }
            return(elements);
        }
Example #27
0
        /// <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;
            }
        }
        /// <summary>
        /// Get all grid labels in current document
        /// </summary>
        /// <param name="document">Revit's document</param>
        /// <returns>ArrayList contains all grid labels in current document</returns>
        private static ArrayList GetAllLabelsOfGrids(Document document)
        {
            ArrayList labels = new ArrayList();

            ElementClassFilter       gridFilter = new ElementClassFilter(typeof(Grid));
            FilteredElementCollector collector  = new FilteredElementCollector(document);

            collector.WherePasses(gridFilter);
            FilteredElementIterator iter = collector.GetElementIterator();

            iter.Reset();
            while (iter.MoveNext())
            {
                Grid grid = iter.Current as Grid;
                if (null != grid)
                {
                    labels.Add(grid.Name);
                }
            }
            return(labels);
        }
Example #29
0
        /// <summary>
        ///constructor
        /// </summary>
        public RoomsData(ThisDocument hostAddIn, Autodesk.Revit.ApplicationServices.Application application)
        {
            m_application  = application;
            m_thisDocument = hostAddIn;

            RoomFilter      roomFilter    = new RoomFilter();
            RoomTagFilter   roomTagFilter = new RoomTagFilter();
            LogicalOrFilter orFilter      = new LogicalOrFilter(roomFilter, roomTagFilter);

            FilteredElementIterator elementIterator =
                (new FilteredElementCollector(m_thisDocument.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;
                }
            }

            //find out the rooms that without tag
            ClassifyRooms();
        }
Example #30
0
        /// <summary>
        /// try to find all the SpotDimensions and add them to the list
        /// </summary>
        private void GetSpotDimensions()
        {
            //get the active document
            Document document = m_revit.ActiveUIDocument.Document;

            FilteredElementIterator elementIterator = (new FilteredElementCollector(document)).OfClass(typeof(Autodesk.Revit.DB.SpotDimension)).GetElementIterator();

            elementIterator.Reset();

            while (elementIterator.MoveNext())
            {
                //find all the SpotDimensions and views
                Autodesk.Revit.DB.SpotDimension tmpSpotDimension = elementIterator.Current as Autodesk.Revit.DB.SpotDimension;
                if (null != tmpSpotDimension)
                {
                    m_spotDimensions.Add(tmpSpotDimension);
                    if (m_views.Contains(tmpSpotDimension.View.ViewName) == false)
                    {
                        m_views.Add(tmpSpotDimension.View.ViewName);
                    }
                }
            }
        }
Example #31
0
File: Data.cs Project: 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;
            }
        }