Exemple #1
0
        /// <summary>
        /// Tessellate the solid by calling the ToRevitType function.
        /// If it fails, the surface geometry of each face of the solid will be tessellated
        /// instead by calling the correspoinding Tessellate method.
        /// </summary>
        /// <param name="solid"></param>
        /// <returns></returns>
        private List <GeometryObject> Tessellate(Solid solid)
        {
            List <GeometryObject> rtGeoms = new List <GeometryObject>();

            try
            {
                rtGeoms.AddRange(solid.ToRevitType());
            }
            catch (Exception)
            {
                // Add a red bounding box geometry to identify that some errors occur
                var bbox = solid.BoundingBox;
                rtGeoms.AddRange(ProtoToRevitMesh.CreateBoundingBoxMeshForErrors(bbox.MinPoint, bbox.MaxPoint));

                foreach (var face in solid.Faces)
                {
                    if (face != null)
                    {
                        var surfaceGeometry = face.SurfaceGeometry();
                        rtGeoms.AddRange(Tessellate(surfaceGeometry));
                        surfaceGeometry.Dispose();
                        face.Dispose();
                    }
                }
            }

            return(rtGeoms);
        }
Exemple #2
0
        public static Autodesk.DesignScript.Geometry.Solid ToProtoType(this Autodesk.Revit.DB.Solid solid,
                                                                       bool performHostUnitConversion = true)
        {
            var srfs      = solid.Faces.Cast <Autodesk.Revit.DB.Face>().SelectMany(x => x.ToProtoType(false));
            var converted = Solid.ByJoinedSurfaces(srfs);

            return(performHostUnitConversion ? converted.InDynamoUnits() : converted);
        }
Exemple #3
0
        public static object SnowDrift_ByEdgeHeight(Dyn.Curve edgeCurve, bool flipDirectioin, double snowLoad_ground_psf, double snowLoad_flatRoof_psf, double roofLength_lower_ft, double roofLength_upper_ft, double roofHeight_delta_ft, double adjustmentFactor_ft = 10.0)
        {
            sDynamoUtilities dynutil = new sDynamoUtilities();

            double designLen;
            double designHeight;
            double designMaxLoad;
            double designSnowDensity;

            dynutil.GetSnowDriftInformation(snowLoad_ground_psf, snowLoad_flatRoof_psf, roofHeight_delta_ft, roofLength_lower_ft, roofLength_upper_ft, out designLen, out designHeight, out designMaxLoad, out designSnowDensity);

            double fac = designLen;

            if (flipDirectioin)
            {
                fac *= -1;
            }

            Dyn.PolyCurve edgeCrvEx = Dyn.PolyCurve.ByJoinedCurves(new Dyn.Curve[1] {
                edgeCurve.ExtendStart(adjustmentFactor_ft).ExtendEnd(adjustmentFactor_ft)
            });
            Dyn.PolyCurve driftCrv_onRoof = Dyn.PolyCurve.ByJoinedCurves(new Dyn.Curve[1] {
                edgeCrvEx.Offset(fac)
            });
            Dyn.PolyCurve driftCrv_onEdge = Dyn.PolyCurve.ByJoinedCurves(new Dyn.Curve[1] {
                edgeCrvEx.Translate(Dyn.Vector.ZAxis().Scale(designHeight)) as Dyn.Curve
            });

            List <Dyn.Solid> snows = new List <Dyn.Solid>();

            for (int i = 0; i < driftCrv_onRoof.NumberOfCurves; ++i)
            {
                List <Dyn.PolyCurve> cs = new List <Dyn.PolyCurve>();
                cs.Add(Dyn.PolyCurve.ByPoints(new Dyn.Point[3] {
                    driftCrv_onRoof.CurveAtIndex(i).StartPoint, driftCrv_onEdge.CurveAtIndex(i).StartPoint, edgeCrvEx.CurveAtIndex(i).StartPoint
                }, true));
                cs.Add(Dyn.PolyCurve.ByPoints(new Dyn.Point[3] {
                    driftCrv_onRoof.CurveAtIndex(i).EndPoint, driftCrv_onEdge.CurveAtIndex(i).EndPoint, edgeCrvEx.CurveAtIndex(i).EndPoint
                }, true));
                snows.Add(Dyn.Solid.ByLoft(cs));
            }

            Dyn.Solid snowSolid = Dyn.Solid.ByUnion(snows);

            // edgeCrvEx.Dispose();
            // driftCrv_onEdge.Dispose();
            // driftCrv_onRoof.Dispose();

            return(new Dictionary <string, object>
            {
                { "DesignLength_ft", designLen },
                { "DesignHeight_ft", designHeight },
                { "DesignMaxLoad_psf", designMaxLoad },
                { "DesignDensity_pcf", designSnowDensity },
                { "DrfitVolumeSolid", snowSolid },
            });
        }
Exemple #4
0
        public static object AwareTributaryVolumeByAreaSolid(List <Dyn.Point> pointsForLoad, List <Dyn.Surface> tributaryAreaSrfs, Dyn.Solid volume)
        {
            List <Dyn.Point>    lpts  = new List <Dyn.Point> ();
            List <Dyn.Geometry> tsols = new List <Dyn.Geometry>();
            List <double>       vols  = new List <double>();

            foreach (Dyn.Surface ts in tributaryAreaSrfs)
            {
                Dyn.Solid trisol = Dyn.PolyCurve.ByJoinedCurves(ts.PerimeterCurves()).ExtrudeAsSolid(Dyn.Vector.ZAxis().Scale(50));

                Dyn.Solid intSelected = null;

                Dyn.Geometry[] ints = trisol.Intersect(volume);
                if (ints != null && ints.Length > 0)
                {
                    for (int i = 0; i < ints.Length; ++i)
                    {
                        Dyn.Solid ins = ints[i] as Dyn.Solid;
                        if (ins != null)
                        {
                            intSelected = ins;
                        }
                    }
                }

                if (intSelected != null)
                {
                    tsols.Add(intSelected.Scale(Dyn.Plane.ByOriginNormal(intSelected.Centroid(), Dyn.Vector.ZAxis()), 0.95, 0.95, 0.95));
                    vols.Add(intSelected.Volume);

                    foreach (Dyn.Point lp in pointsForLoad)
                    {
                        if (ts.DistanceTo(lp) < 0.005)
                        {
                            lpts.Add(lp);
                            break;
                        }
                    }
                }
            }



            return(new Dictionary <string, object>
            {
                { "LoadPoints", lpts },
                { "TributarySolids", tsols },
                { "TributaryVolumes_ft3", vols }
            });
        }
Exemple #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="parameters"></param>
        /// <param name="dynSolid"></param>
        /// <returns></returns>
        public static ParasiteObject CreateParasiteObject(DynSolid dynSolid, P_Parameter[] parameters = null)
        {
            ParasiteObject parasiteObject = new ParasiteObject(dynSolid);

            if (parameters != null)
            {
                for (int i = 0; i < parameters.Length; i++)
                {
                    parasiteObject.AddParameter(parameters[i].ParameterType.ToString(), parameters[i]);
                }
            }

            return(parasiteObject);
        }
        public static IList <GeometryObject> ToRevitType(
            this Autodesk.DesignScript.Geometry.Solid solid,
            TessellatedShapeBuilderTarget target     = TessellatedShapeBuilderTarget.Mesh,
            TessellatedShapeBuilderFallback fallback = TessellatedShapeBuilderFallback.Salvage,
            ElementId MaterialId           = null,
            bool performHostUnitConversion = true)
        {
            var rp = new DefaultRenderPackage();

            if (performHostUnitConversion)
            {
                var newSolid = solid.InHostUnits();
                newSolid.Tessellate(rp, new TessellationParameters());
                newSolid.Dispose();
            }
            else
            {
                solid.Tessellate(rp, new TessellationParameters());
            }

            var tsb = new TessellatedShapeBuilder()
            {
                Fallback = fallback, Target = target, GraphicsStyleId = ElementId.InvalidElementId
            };

            tsb.OpenConnectedFaceSet(false);

            var v = rp.MeshVertices.ToList();

            for (int i = 0; i < v.Count; i += 9)
            {
                var a = new XYZ(v[i], v[i + 1], v[i + 2]);
                var b = new XYZ(v[i + 3], v[i + 4], v[i + 5]);
                var c = new XYZ(v[i + 6], v[i + 7], v[i + 8]);

                var face = new TessellatedFace(new List <XYZ>()
                {
                    a, b, c
                }, MaterialId != null ? MaterialId : MaterialsManager.Instance.DynamoMaterialId);
                tsb.AddFace(face);
            }

            tsb.CloseConnectedFaceSet();
            tsb.Build();
            var result = tsb.GetBuildResult();

            return(result.GetGeometricalObjects());
        }
Exemple #7
0
        public static List <global::Revit.Elements.Element> GetAreaAtPoint(Autodesk.DesignScript.Geometry.Point point, double areaHeight = 10.0)
        {
            Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument;

            List <global::Revit.Elements.Element> areaLocations = new List <global::Revit.Elements.Element>();

            //collect the areas to do some cool stuff
            FilteredElementCollector          areaColl = new FilteredElementCollector(doc);
            IList <Autodesk.Revit.DB.Element> areas    = areaColl.OfCategory(BuiltInCategory.OST_Areas).ToElements();

            foreach (var area in areas)
            {
                Solid solid = Rhythm.Revit.Elements.Areas.Solid(area.ToDSType(true), areaHeight);
                if (solid.DoesIntersect(point))
                {
                    areaLocations.Add(area.ToDSType(true));
                }
                solid.Dispose();
            }
            return(areaLocations);
        }
Exemple #8
0
        /// <summary>
        /// Converts a Dynamo Solid to a Parasite Brep Solid.
        /// This method iterates through all the faces of the Dynamo Solid,
        /// extracts their vertices and computes a new Parasite Brep Surface from them.
        /// Each Parasite Brep Surface is sequentially added to a Collection as input for constructing
        /// a Parasite Brep Solid
        /// </summary>
        /// <param name="solid"></param>
        /// <param name="properties"></param>
        /// <returns></returns>
        public static Parasite_BrepSolid ToParasiteType(Autodesk.DesignScript.Geometry.Solid solid, Dictionary <string, Parameter> properties = null)
        {
            Autodesk.DesignScript.Geometry.Face[] faces = solid.Faces;

            Parasite_BrepSurface[] brepSurfs = new Parasite_BrepSurface[faces.Length];

            for (int i = 0; i < faces.Length; i++)
            {
                Autodesk.DesignScript.Geometry.Loop [] loops = faces[i].Loops;

                List <Autodesk.DesignScript.Geometry.Curve> lines = new List <Autodesk.DesignScript.Geometry.Curve>();

                for (int k = 0; k < loops.Length; k++)
                {
                    Autodesk.DesignScript.Geometry.CoEdge[] coEdge = loops[k].CoEdges;


                    for (int m = 0; m < coEdge.Length; m++)
                    {
                        lines.Add(coEdge[m].Edge.CurveGeometry);
                    }
                }


                Autodesk.DesignScript.Geometry.Vertex[] vertices = faces[i].Vertices;

                Parasite_Point3d[] vertexArray = new Parasite_Point3d[vertices.Length];

                for (int j = 0; j < vertices.Length; j++)
                {
                    vertexArray[j] = ToParasiteType(vertices[j].PointGeometry);
                }


                Parasite_BrepSurface brepSrf = new Parasite_BrepSurface(vertexArray, ToParasiteType(lines), properties);
                brepSurfs[i] = brepSrf;
            }

            return(new Parasite_BrepSolid(brepSurfs, properties));
        }
Exemple #9
0
        public static List <global::Revit.Elements.Element> IntersectingElementsInRoom(global::Revit.Elements.Room room, global::Revit.Elements.Category category)
        {
            Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument;

            Autodesk.DesignScript.Geometry.Solid roomSolid = Autodesk.DesignScript.Geometry.Solid.ByUnion(room.Solids);

            //get built in category from user viewable category
            BuiltInCategory myCatEnum = (BuiltInCategory)Enum.Parse(typeof(BuiltInCategory), category.Id.ToString());

            //start the transaction
            TransactionManager.Instance.EnsureInTransaction(doc);
            //builds an id collection for later deletion
            ICollection <ElementId> idCollection = new List <ElementId>();

            global::Revit.Elements.DirectShape directShape = global::Revit.Elements.DirectShape.ByGeometry(roomSolid, global::Revit.Elements.Category.ByName("Generic Models"), global::Revit.Elements.DirectShape.DynamoPreviewMaterial, "DirectShape");
            idCollection.Add(directShape.InternalElement.Id);
            TransactionManager.Instance.TransactionTaskDone();
            doc.Regenerate();
            ElementIntersectsElementFilter filter = new ElementIntersectsElementFilter(directShape.InternalElement);
            //build a collector
            FilteredElementCollector          collector = new FilteredElementCollector(doc);
            IList <Autodesk.Revit.DB.Element> intersectingElementsInternaList = collector.OfCategory(myCatEnum).WhereElementIsNotElementType().WherePasses(filter).ToElements();
            //build a list to output geometry
            List <global::Revit.Elements.Element> intersectingElements = new List <global::Revit.Elements.Element>();

            //append the intersecting elements to the output list
            foreach (Autodesk.Revit.DB.Element thing in intersectingElementsInternaList)
            {
                intersectingElements.Add(thing.ToDSType(true));
            }
            //delete the direct shapes as we do not need them any longer
            TransactionManager.Instance.EnsureInTransaction(doc);
            foreach (ElementId id in idCollection)
            {
                doc.Delete(id);
            }
            TransactionManager.Instance.TransactionTaskDone();

            return(intersectingElements);
        }
Exemple #10
0
        public static DynamoRevitElements.DirectShape CreateRevitMass(DynamoElements.Solid BuildingSolid, DynamoRevitElements.Category Category)
        {
            if (BuildingSolid == null)
            {
                throw new ArgumentNullException(nameof(BuildingSolid));
            }

            var revitCategory = Document.Settings.Categories.get_Item(Category.Name);

            TransactionManager.Instance.EnsureInTransaction(Document);

            var revitBuilding = RevitElements.DirectShape.CreateElement(Document, revitCategory.Id);

            try
            {
                revitBuilding.SetShape(new[] { DynamoToRevitBRep.ToRevitType(BuildingSolid) });
            }
            catch (Exception ex)
            {
                try
                {
                    revitBuilding.SetShape(BuildingSolid.ToRevitType());
                }
                catch
                {
                    throw new ArgumentException(ex.Message);
                }
            }

            TransactionManager.Instance.TransactionTaskDone();

            revitCategory.Dispose();

            var directShape = revitBuilding.ToDSType(false) as DynamoRevitElements.DirectShape;

            revitBuilding.Dispose();

            return(directShape);
        }
        public static Autodesk.DesignScript.Geometry.Solid ToProtoType(this Autodesk.Revit.DB.Solid solid,
                                                                       bool performHostUnitConversion = true)
        {
            var faces = solid.Faces;
            var srfs  = new List <Surface>();

            foreach (Face face in faces)
            {
                srfs.AddRange(face.ToProtoType(false));
            }
            var converted = Solid.ByJoinedSurfaces(srfs);

            srfs.ForEach(x => x.Dispose());
            srfs.Clear();

            if (performHostUnitConversion)
            {
                UnitConverter.ConvertToDynamoUnits(ref converted);
            }

            return(converted);
        }
Exemple #12
0
 internal override IGeometryEntity[] IntersectWithSolid(Solid solid)
 {
     return(SolidEntity.IntersectWith(solid.SolidEntity));
 }
Exemple #13
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="solid"></param>
 /// <param name="selectPoint"></param>
 /// <returns></returns>
 public Solid Trim(Solid solid, Point selectPoint)
 {
     Solid[] solids = { solid };
     return(Trim(null, null, solids, selectPoint));
 }
Exemple #14
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);
            }
        }
Exemple #15
0
 /// <summary>
 /// Returns a solid by uniting one solid with another solid
 /// </summary>
 /// <param name="otherSolid">The other solid </param>
 /// <returns>Returns a Solid</returns>
 public Solid Union(Solid otherSolid)
 {
     return(Union(otherSolid, true));
 }
Exemple #16
0
        public static IEnumerable <Revit.Elements.Element> FilterBySolidIntersection(Revit.Elements.Element[] elements, Autodesk.DesignScript.Geometry.Solid solid)
        {
            Document document = DocumentManager.Instance.CurrentDBDocument;

            // Convert Proto to Revit
            var unionSolid = DynamoToRevitBRep.ToRevitType(solid) as Autodesk.Revit.DB.Solid;

            // List of unwrapped Dynamo element Ids
            List <ElementId> elementIds = elements.Select(x => x.InternalElement.Id).ToList();

            // Collect intersected elements
            var сollector = new FilteredElementCollector(document, elementIds);

            сollector.WherePasses(new ElementIntersectsSolidFilter(unionSolid));
            var colectedElements = сollector.ToElements();

            return(colectedElements.Select(x => x.ToDSType(true)));
        }
Exemple #17
0
        public static ParasiteObject CreateParasiteObject(DynSolid dynSolid)
        {
            ParasiteObject parasiteObject = new ParasiteObject(dynSolid);

            return(parasiteObject);
        }