Пример #1
0
        /// <summary>
        /// Populate the Dropdown menu
        /// </summary>
        public void PopulateItems()
        {
            if (this.ElementType != null)
            {
                // Clear the Items
                Items.Clear();

                // Set up a new element collector using the Type field
                var fec = new RVT.FilteredElementCollector(DocumentManager.Instance.CurrentDBDocument).OfClass(ElementType);

                // If there is nothing in the collector add the missing Type message to the Dropdown menu.
                if (fec.ToElements().Count == 0)
                {
                    Items.Add(new CoreNodeModels.DynamoDropDownItem(noTypes, null));
                    SelectedIndex = 0;
                    return;
                }

                if (this.ElementType.FullName == "Autodesk.Revit.DB.Structure.RebarHookType")
                {
                    Items.Add(new CoreNodeModels.DynamoDropDownItem("None", null));
                }

                // Walk through all elements in the collector and add them to the dropdown
                foreach (var ft in fec.ToElements())
                {
                    Items.Add(new CoreNodeModels.DynamoDropDownItem(ft.Name, ft));
                }

                Items = Items.OrderBy(x => x.Name).ToObservableCollection();
            }
        }
Пример #2
0
        /// <summary>
        /// Populate the Dropdown menu
        /// </summary>
        public override void PopulateItems()
        {
            if (this.ElementType != null)
            {
                // Clear the Items
                Items.Clear();

                // Set up a new element collector using the Type field
                var fec = new RVT.FilteredElementCollector(DocumentManager.Instance.CurrentDBDocument).OfClass(ElementType);

                // If there is nothing in the collector add the missing Type message to the Dropdown menu.
                if (fec.ToElements().Count == 0)
                {
                    Items.Add(new DSCoreNodesUI.DynamoDropDownItem(noTypes, null));
                    SelectedIndex = 0;
                    return;
                }

                if (this.ElementType.FullName == "Autodesk.Revit.DB.Structure.RebarHookType") Items.Add(new DSCoreNodesUI.DynamoDropDownItem("None", null));

                // Walk through all elements in the collector and add them to the dropdown
                foreach (var ft in fec.ToElements())
                {
                    Items.Add(new DSCoreNodesUI.DynamoDropDownItem(ft.Name, ft));
                }

                Items = Items.OrderBy(x => x.Name).ToObservableCollection();
            }
        }
Пример #3
0
        /// <summary>
        /// Get Base or SurveyPoint
        /// </summary>
        /// <param name="surveypoint"></param>
        /// <returns></returns>
        private static Point GetBaseOrSurveyPoint(bool surveypoint)
        {
            // Get Base or Survey point category
            RVT.BuiltInCategory category = (surveypoint)? RVT.BuiltInCategory.OST_SharedBasePoint : RVT.BuiltInCategory.OST_ProjectBasePoint;

            // Get Revit document
            RVT.Document doc = RevitServices.Persistence.DocumentManager.Instance.CurrentDBDocument;

            // Get all elements of the previously selected category
            Autodesk.Revit.DB.FilteredElementCollector collector = new RVT.FilteredElementCollector(doc).OfCategory(category);

            // Get the first element (should only be one)
            RVT.BasePoint element = (RVT.BasePoint)collector.ToElements().FirstOrDefault();

            if (element == null)
            {
                throw new Exception(Properties.Resources.CannotGetBaseOrSurveyPoint);
            }

            // Get the elements bounding box
            RVT.BoundingBoxXYZ box = element.get_BoundingBox(null);

            // Since the boundingbox is a point only, return Min or Max
            return(box.Max.ToPoint());
        }
Пример #4
0
        public 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>());
        }
Пример #5
0
        /// <summary>
        /// Populate the Dropdown menu
        /// </summary>
        public void PopulateDropDownItems()
        {
            if (this.ElementType != null)
            {
                // Clear the Items
                Items.Clear();

                // If the active doc is null, throw an exception
                if (DocumentManager.Instance.CurrentDBDocument == null)
                {
                    throw new Exception(Properties.Resources.NoActiveDocumentFound);
                }

                // Set up a new element collector using the Type field
                var fec = new RVT.FilteredElementCollector(DocumentManager.Instance.CurrentDBDocument).OfClass(ElementType);

                // If there is nothing in the collector add the missing Type message to the Dropdown menu.
                if (fec.ToElements().Count == 0)
                {
                    Items.Add(new CoreNodeModels.DynamoDropDownItem(Properties.Resources.NoTypesFound, null));
                    SelectedIndex = 0;
                    return;
                }

                // if the elementtype is a RebarHookType add an initial "None" value which does not come from the collector
                if (this.ElementType.FullName == "Autodesk.Revit.DB.Structure.RebarHookType")
                {
                    Items.Add(new CoreNodeModels.DynamoDropDownItem(Properties.Resources.None, null));
                }

                // Walk through all elements in the collector and add them to the dropdown
                foreach (var ft in fec.ToElements())
                {
                    Items.Add(new CoreNodeModels.DynamoDropDownItem(ft.Name, ft));
                }

                Items = Items.OrderBy(x => x.Name).ToObservableCollection();
            }
        }
Пример #6
0
        /// <summary>
        /// Get Project Rotation
        /// </summary>
        /// <returns>Rotation in degrees</returns>
        public static double ProjectRotation()
        {
            // Get project base point
            RVT.Document doc = RevitServices.Persistence.DocumentManager.Instance.CurrentDBDocument;
            Autodesk.Revit.DB.FilteredElementCollector collector = new RVT.FilteredElementCollector(doc).OfCategory(RVT.BuiltInCategory.OST_ProjectBasePoint);
            RVT.BasePoint element = (RVT.BasePoint)collector.ToElements().FirstOrDefault();

            if (element == null)
            {
                throw new Exception(Properties.Resources.CannotGetBaseOrSurveyPoint);
            }

            // Return the rotation parameter as double
            RVT.Parameter param = element.get_Parameter(RVT.BuiltInParameter.BASEPOINT_ANGLETON_PARAM);
            return(param.AsDouble().ToDegrees());
        }
Пример #7
0
        static DB.ElementId MapMaterial(DB.Document project, DB.Document family, DB.ElementId materialId, bool createIfNotExist = false)
        {
            if (project.GetElement(materialId) is DB.Material material)
            {
                using (var collector = new DB.FilteredElementCollector(family).OfClass(typeof(DB.Material)))
                {
                    if (collector.ToElements().Cast <DB.Material>().Where(x => x.Name == material.Name).FirstOrDefault() is DB.Material familyMaterial)
                    {
                        return(familyMaterial.Id);
                    }
                }

                if (createIfNotExist)
                {
                    return(DB.Material.Create(family, material.Name));
                }
            }

            return(DB.ElementId.InvalidElementId);
        }
Пример #8
0
        public static PathOfTravel[] LongestOfShortestExitPaths(Revit.Elements.Views.FloorPlanView floorPlan, Autodesk.DesignScript.Geometry.Point[] endPtsList)
        {
            if (floorPlan == null)
            {
                throw new ArgumentNullException("floorPlan", Properties.Resources.InvalidView);
            }

            if (endPtsList == null)
            {
                throw new ArgumentNullException("endPtList", Properties.Resources.InvalidEndPointList);
            }

            if (!endPtsList.Any())
            {
                throw new ArgumentException(Properties.Resources.EndPointListEmpty, "endPtList");
            }

            if (endPtsList.Any(x => x == null))
            {
                throw new ArgumentException(Properties.Resources.EndPointListHasNulls, "endPtList");
            }

            // Check that floor has some rooms
            Rvt.Document doc = DocumentManager.Instance.CurrentDBDocument;

            if (doc == null)
            {
                throw new ArgumentException(Properties.Resources.RoomsForLongestPathNotFound);
            }

            FilteredElementCollector collector = new Rvt.FilteredElementCollector(doc).OfCategory(Rvt.BuiltInCategory.OST_Rooms);

            if (collector.ToElements().Count() == 0)
            {
                throw new ArgumentException(Properties.Resources.RoomsForLongestPathNotFound);
            }

            return(InternalLongestOfShortestExitPaths(
                       (Rvt.View)floorPlan.InternalElement,
                       endPtsList.Select(x => x.ToXyz())));
        }
Пример #9
0
        /// <summary>
        /// Convert a DS Solid to a Revit FamilySymbol containing
        /// Revit FreeForms via SAT Export/Import
        /// </summary>
        /// <param name="solidGeometry"></param>
        /// <param name="name"></param>
        /// <param name="category"></param>
        /// <param name="templatePath">Revit Template to use for Family Creation</param>
        /// <param name="material">Can be null for Voids</param>
        /// <param name="isVoid">Create Void</param>
        /// <param name="subcategory">Can be string.Empty for Voids</param>
        /// <returns></returns>
        public static Autodesk.Revit.DB.FamilySymbol ToRevitFamilyType(
            this Autodesk.DesignScript.Geometry.Solid solidGeometry,
            string name,
            Revit.Elements.Category category,
            string templatePath,
            Revit.Elements.Material material,
            bool isVoid,
            string subcategory = "")
        {
            // Keep the current document and close the open transaction
            Autodesk.Revit.DB.Document document = DocumentManager.Instance.CurrentDBDocument;
            TransactionManager.Instance.ForceCloseTransaction();

            // create a temp sat file
            string tempFile = System.IO.Path.GetTempFileName() + ".sat";

            // create a temp family file
            string tempDir        = System.IO.Path.GetTempPath();
            string tempFamilyFile = System.IO.Path.Combine(tempDir, name + ".rfa");

            // scale the incoming geometry
            solidGeometry = solidGeometry.InHostUnits();

            // get a displacement vector
            Vector vector = Vector.ByTwoPoints(Autodesk.DesignScript.Geometry.BoundingBox.ByGeometry(solidGeometry).MinPoint, Autodesk.DesignScript.Geometry.Point.Origin());

            // translate the geometry to origin
            solidGeometry = solidGeometry.Translate(vector) as Autodesk.DesignScript.Geometry.Solid;

            // export geometry to SAT
            solidGeometry.ExportToSAT(tempFile);
            solidGeometry.Dispose();

            // create a new family document using the supplied template
            Autodesk.Revit.DB.Document familyDocument = document.Application.NewFamilyDocument(templatePath);

            // Get the families 3d view
            var collector = new Autodesk.Revit.DB.FilteredElementCollector(familyDocument).OfClass(typeof(Autodesk.Revit.DB.View));

            Autodesk.Revit.DB.View view = null;
            foreach (Autodesk.Revit.DB.View v in collector.ToElements())
            {
                if (!v.IsTemplate && v.ViewType == ViewType.ThreeD)
                {
                    view = v;
                }
            }

            // Open a Transaction with the FamilyDocument
            TransactionManager.Instance.EnsureInTransaction(familyDocument);

            // Import the sat file to origin in feet
            ElementId importedElementId = familyDocument.Import(tempFile, new SATImportOptions()
            {
                Placement = ImportPlacement.Origin, Unit = ImportUnit.Foot
            }, view);

            // get the solid element from the imported sat file
            var solids = GetSolidsFromElement(familyDocument.GetElement(importedElementId));

            // delete imported sat
            familyDocument.Delete(importedElementId);
            System.IO.File.Delete(tempFile);

            // Set the families category
            familyDocument.OwnerFamily.FamilyCategory = familyDocument.Settings.Categories.get_Item(category.Name);

            foreach (var solid in solids)
            {
                // Create Freeform Element
                var freeform = FreeFormElement.Create(familyDocument, solid);

                // if the geometry should be void set parameters accordingly
                if (isVoid)
                {
                    ApplyVoidSettingsToFreeForm(freeform);
                }
                else
                {
                    // Apply material if supplied
                    ApplyMaterialToFreeForm(familyDocument, material, freeform);

                    // Apply Subcategory if supplied
                    if (subcategory != string.Empty)
                    {
                        ApplySubCategoryToFreeForm(familyDocument, subcategory, freeform);
                    }
                }
            }

            // Close the FamilyDocument Transaction
            TransactionManager.Instance.ForceCloseTransaction();

            // Save Family document and load it into the project
            familyDocument.SaveAs(tempFamilyFile, new SaveAsOptions()
            {
                OverwriteExistingFile = true
            });
            var family = familyDocument.LoadFamily(document, new FamilyImportOptions());

            // close and delete family
            familyDocument.Close(false);
            System.IO.File.Delete(tempFamilyFile);

            // get first imported family symbol
            var symbols = family.GetFamilySymbolIds();

            // Restore the Project Document Transaction
            TransactionManager.Instance.EnsureInTransaction(document);

            if (symbols.Count > 0)
            {
                FamilySymbol symbol = (FamilySymbol)document.GetElement(symbols.First());

                // activate symbol
                if (!symbol.IsActive)
                {
                    symbol.Activate();
                }

                return(symbol);
            }
            else
            {
                return(null);
            }
        }
Пример #10
0
 public 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>();
 }