Example #1
0
        /// <summary>
        /// Obtain a Family from the current document given it's name
        /// </summary>
        /// <param name="name">The name of the family in the current document</param>
        /// <returns></returns>
        public static Family ByName(string name)
        {
            if (name == null)
            {
                throw new ArgumentNullException();
            }

            TransactionManager.Instance.EnsureInTransaction(Document);

            // look up the loaded family
            var fec = new Autodesk.Revit.DB.FilteredElementCollector(Document);

            fec.OfClass(typeof(Autodesk.Revit.DB.Family));

            // obtain the family type with the provided name
            var families = fec.Cast <Autodesk.Revit.DB.Family>();

            var family = families.FirstOrDefault(x => x.Name == name);

            if (family == null)
            {
                throw new Exception(Properties.Resources.FamilySymbolNotFound1);
            }

            TransactionManager.Instance.TransactionTaskDone();

            return(new Family(family));
        }
Example #2
0
        protected static IList <Autodesk.Revit.DB.ReferencePoint> GetAllReferencePoints()
        {
            var fec = new Autodesk.Revit.DB.FilteredElementCollector(DocumentManager.Instance.CurrentUIDocument.Document);

            fec.OfClass(typeof(Autodesk.Revit.DB.ReferencePoint));
            return(fec.ToElements().Cast <Autodesk.Revit.DB.ReferencePoint>().ToList());
        }
Example #3
0
        internal static IEnumerable <Autodesk.Revit.DB.Level> GetAllLevels()
        {
            var collector = new Autodesk.Revit.DB.FilteredElementCollector(DocumentManager.Instance.CurrentDBDocument);

            collector.OfClass(typeof(Autodesk.Revit.DB.Level));
            return(collector.ToElements().Cast <Autodesk.Revit.DB.Level>());
        }
Example #4
0
        public void OpenNewFileNotCleanupOldElements()
        {
            string filePath = Path.Combine(workingDirectory, @".\Bugs\MAGN_7229_1.dyn");
            string testPath = Path.GetFullPath(filePath);

            ViewModel.OpenCommand.Execute(testPath);

            var doc = DocumentManager.Instance.CurrentDBDocument;
            var fec = new Autodesk.Revit.DB.FilteredElementCollector(DocumentManager.Instance.CurrentUIDocument.Document);

            fec.OfClass(typeof(Autodesk.Revit.DB.ReferencePoint));
            Assert.AreEqual(4, fec.ToElements().Count());

            filePath = Path.Combine(workingDirectory, @".\Bugs\MAGN_7229_2.dyn");
            testPath = Path.GetFullPath(filePath);
            ViewModel.OpenCommand.Execute(testPath);
            fec.OfClass(typeof(Autodesk.Revit.DB.ReferencePoint));
            Assert.AreEqual(6, fec.ToElements().Count());

            Model.ClearCurrentWorkspace();
            fec.OfClass(typeof(Autodesk.Revit.DB.ReferencePoint));
            Assert.AreEqual(6, fec.ToElements().Count());
        }
Example #5
0
        /// <summary>
        /// Obtain a Family from the current document given it's name
        /// </summary>
        /// <param name="name">The name of the family in the current document</param>
        /// <returns></returns>
        public static Family ByName(string name)
        {
            if (name == null)
            {
                throw new ArgumentNullException();
            }

            TransactionManager.Instance.EnsureInTransaction(Document);

            // look up the loaded family
            var fec = new Autodesk.Revit.DB.FilteredElementCollector(Document);
            fec.OfClass(typeof(Autodesk.Revit.DB.Family));

            // obtain the family symbol with the provided name
            var families = fec.Cast<Autodesk.Revit.DB.Family>();

            var family = families.FirstOrDefault(x => x.Name == name);

            if (family == null)
            {
                throw new Exception("A FamilySymbol with the specified name does not exist in the document");
            }

            TransactionManager.Instance.TransactionTaskDone();

            return new Family(family);
        }