Beispiel #1
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document   doc   = uidoc.Document;
            Selection  sel   = uidoc.Selection;

            Floor currentFloor = doc.GetElement(sel.PickObject(ObjectType.Element, new FloorSelectionFilter(), "Selecione um piso")) as Floor;

            IList <Reference> topFaceReferenceList = HostObjectUtils.GetTopFaces(currentFloor);

            using (Transaction t = new Transaction(doc, "Criar plataformas"))
            {
                t.Start();
                foreach (Reference currentRef in topFaceReferenceList)
                {
                    Face currentFace = GetFaceFromReference(currentRef, currentFloor);
                    CreatePadFromFace(currentFace, currentFloor, doc);
                }
                t.Commit();
            }

            try
            {
            }
            catch (Exception)
            {
            }

            return(Result.Succeeded);
        }
Beispiel #2
0
        public static List <Spatial.Face3D> TopProfiles(this HostObject hostObject)
        {
            List <Spatial.Face3D> result = new List <Spatial.Face3D>();

            foreach (Reference reference in HostObjectUtils.GetTopFaces(hostObject))
            {
                GeometryObject geometryObject = hostObject.GetGeometryObjectFromReference(reference);
                if (geometryObject == null)
                {
                    continue;
                }

                Autodesk.Revit.DB.Face face = geometryObject as Autodesk.Revit.DB.Face;
                if (face == null)
                {
                    continue;
                }

                List <Spatial.Face3D> face3Ds = face.ToSAM();
                if (face3Ds == null || face3Ds.Count == 0)
                {
                    continue;
                }

                result.AddRange(face3Ds);
            }

            return(result);
        }
Beispiel #3
0
        //Nesting the various profiles into a polycurve segments
        private List <ICurve> GetProfiles(DB.CeilingAndFloor floor)
        {
            var  profiles = new List <ICurve>();
            var  faces    = HostObjectUtils.GetTopFaces(floor);
            Face face     = floor.GetGeometryObjectFromReference(faces[0]) as Face;
            var  crvLoops = face.GetEdgesAsCurveLoops();

            foreach (var crvloop in crvLoops)
            {
                var poly = new Polycurve(ModelUnits);
                foreach (var curve in crvloop)
                {
                    var c = curve;

                    if (c == null)
                    {
                        continue;
                    }

                    poly.segments.Add(CurveToSpeckle(c));
                }
                profiles.Add(poly);
            }
            return(profiles);
        }
Beispiel #4
0
        /// <summary>
        /// This node will return the bottom face or faces for the input host object. This particular method works for ceilings, roofs, or floors.
        /// </summary>
        /// <param name="hostObject">The host object to retrieve top faces for.</param>
        /// <returns></returns>
        public static IEnumerable <List <Surface> > TopSurface(global::Revit.Elements.Element hostObject)
        {
            Autodesk.Revit.DB.HostObject internalHost = hostObject.InternalElement as Autodesk.Revit.DB.HostObject;

            IList <Reference> sideRefs = HostObjectUtils.GetTopFaces(internalHost);

            List <Autodesk.Revit.DB.Face> exteriorGeometryObjects = new List <Autodesk.Revit.DB.Face>(sideRefs.Select(r => internalHost.GetGeometryObjectFromReference(r)).Cast <Autodesk.Revit.DB.Face>());

            return(exteriorGeometryObjects.Select(g => g.ToProtoType(true).ToList()));
        }
Beispiel #5
0
        static internal IList <EdgeInfo> GetRoofEdgeInfoList(FootPrintRoof currentRoof, bool topFaces = true)
        {
            //TODO see if theres any segmented curves (segmented sketch lines) on the footprint of the roof
            //If yes, ask the user to correct then OR exit the command OR merge the sketchlines

            IList <EdgeInfo> resultingEdgeInfoList = new List <EdgeInfo>();
            IList <EdgeInfo> tempEdgeInfoList      = new List <EdgeInfo>();

            IList <Reference> currentListOfReferences = new List <Reference>();

            if (topFaces)
            {
                currentListOfReferences = HostObjectUtils.GetTopFaces(currentRoof);
            }
            else
            {
                currentListOfReferences = HostObjectUtils.GetBottomFaces(currentRoof);
            }

            IList <PlanarFace> currentListOfFaces = new List <PlanarFace>();

            IsListOfPlanarFaces(currentListOfReferences, currentRoof, out currentListOfFaces);

            IList <Curve> nonDuplicatedEdgeList = GetNonDuplicatedCurvesFromListOfFaces(currentListOfFaces);

            foreach (Curve currentCurve in nonDuplicatedEdgeList)
            {
                tempEdgeInfoList.Add(GetCurveInformation(currentRoof, currentCurve, currentListOfFaces));
            }

            foreach (EdgeInfo currentEdgeInfo in tempEdgeInfoList)
            {
                EdgeInfo newEdgeInfo = currentEdgeInfo;
                newEdgeInfo.RelatedRidgeEaves = GetRidgeInfoList(newEdgeInfo.Edges[0], tempEdgeInfoList);
                resultingEdgeInfoList.Add(newEdgeInfo);
            }

            resultingEdgeInfoList = MergeEdgeCurves(resultingEdgeInfoList);

            //foreach (EdgeInfo currentEdgeInfo in resultingEdgeInfoList)
            //{
            //    if (currentEdgeInfo.Edges.Count > 1)
            //        System.Diagnostics.Debug.WriteLine("Merged Edge");

            //    Document doc = currentEdgeInfo.CurrentRoof.Document;
            //    PlanarFace pfce = currentEdgeInfo.GetRelatedPanels()[0] as PlanarFace;
            //    Plane pl = new Plane(pfce.FaceNormal, pfce.Origin);
            //    SketchPlane skp = SketchPlane.Create(doc, pl);
            //    doc.Create.NewModelCurve(currentEdgeInfo.Curve, skp);
            //}


            return(resultingEdgeInfoList);
        }
Beispiel #6
0
            public bool AllowElement(Element elem)
            {
                if ((elem as FootPrintRoof) != null)
                {
                    FootPrintRoof currentFootPrintRoof = elem as FootPrintRoof;

                    IList <PlanarFace> pfaces = new List <PlanarFace>();
                    if (Support.IsListOfPlanarFaces(HostObjectUtils.GetTopFaces(currentFootPrintRoof), currentFootPrintRoof, out pfaces))
                    {
                        return(true);
                    }
                }
                return(false);
            }
Beispiel #7
0
        // Get Profile--------------------------------------------------------------------
        public static List <XYZ> Get_Profile(Document doc, Element element)
        {
            List <XYZ> list_Profile_point = new List <XYZ>();

            try
            {
                IList <Reference> sideFaces = null;
                if (element.Category.Name == "Walls")
                {
                    sideFaces = HostObjectUtils.GetSideFaces(element as Wall, ShellLayerType.Exterior);
                }
                else
                {
                    sideFaces = HostObjectUtils.GetTopFaces(element as Floor);
                }

                Element e2   = doc.GetElement(sideFaces[0]);
                Face    face = e2.GetGeometryObjectFromReference(sideFaces[0]) as Face;

                // The normal of the wall external face.
                XYZ normal = face.ComputeNormal(new UV(0, 0));

                // Get edge loops as curve loops.
                IList <CurveLoop> curveLoops = face.GetEdgesAsCurveLoops();

                // ExporterIFCUtils class can also be used for
                // non-IFC purposes. The SortCurveLoops method
                // sorts curve loops (edge loops) so that the
                // outer loops come first.
                IList <IList <CurveLoop> > curveLoopLoop = ExporterIFCUtils.SortCurveLoops(curveLoops);
                foreach (IList <CurveLoop> curveLoops2 in curveLoopLoop)
                {
                    foreach (CurveLoop curveLoop2 in curveLoops2)
                    {
                        // Check if curve loop is counter-clockwise.
                        bool isCCW = curveLoop2.IsCounterclockwise(normal);
                        foreach (Curve curve in curveLoop2)
                        {
                            list_Profile_point.Add(curve.GetEndPoint(0));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            return(list_Profile_point);
        }
        /***************************************************/

        public static List <Face> LinkPanelFaces(this Floor floor, RevitSettings settings)
        {
            List <Face> result = new List <Face>();

            foreach (Reference reference in HostObjectUtils.GetTopFaces(floor))
            {
                PlanarFace pf = floor.GetGeometryObjectFromReference(reference) as PlanarFace;
                if (pf != null)
                {
                    result.Add(pf);
                }
            }

            return(result);
        }
Beispiel #9
0
        /***************************************************/

        public static List <Plane> PanelPlanes(this RoofBase roof)
        {
            List <Plane> result = new List <Plane>();

            foreach (Reference reference in HostObjectUtils.GetTopFaces(roof))
            {
                PlanarFace pf = roof.GetGeometryObjectFromReference(reference) as PlanarFace;
                if (pf != null)
                {
                    result.Add(Plane.CreateByNormalAndOrigin(pf.FaceNormal, pf.Origin));
                }
            }

            return(result);
        }
Beispiel #10
0
        public static List <Curve> GetFloorOuterBoundary(Floor floor)
        {
            Reference rf   = HostObjectUtils.GetTopFaces(floor).First();
            Face      face = floor.GetGeometryObjectFromReference(rf) as Face;

            PlanarFace pface = face as PlanarFace;

            if (pface == null)
            {
                return(null);
            }

            List <Curve> profile = GetFaceOuterBoundary(pface);


            return(profile);
        }
Beispiel #11
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            var uiapp = commandData.Application;
            var app   = uiapp.Application;
            var uidoc = uiapp.ActiveUIDocument;
            var doc   = uidoc.Document;

            var sel    = uidoc.Selection;
            var acview = uidoc.ActiveView;


            var floor = sel.PickObject(ObjectType.Element, doc.GetSelectionFilter(m => m is Floor)).GetElement(doc) as Floor;

            var faces = HostObjectUtils.GetTopFaces(floor);

            MessageBox.Show(faces.Count.ToString());



            return(Result.Succeeded);
        }
Beispiel #12
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Autodesk.Revit.DB.HostObject host = null;
            if (!DA.GetData("Host", ref host) || host is null)
            {
                return;
            }

            var doc = Revit.ActiveDBDocument;

            try
            {
                var bottom = HostObjectUtils.GetBottomFaces(host).Select(reference => new Types.Face(reference, doc));
                DA.SetDataList("Bottom", bottom);
            }
            catch (Autodesk.Revit.Exceptions.ArgumentException) { }

            try
            {
                var top = HostObjectUtils.GetTopFaces(host).Select(reference => new Types.Face(reference, doc));
                DA.SetDataList("Top", top);
            }
            catch (Autodesk.Revit.Exceptions.ArgumentException) { }

            try
            {
                var interior = HostObjectUtils.GetSideFaces(host, ShellLayerType.Interior).Select(reference => new Types.Face(reference, doc));
                DA.SetDataList("Interior", interior);
            }
            catch (Autodesk.Revit.Exceptions.ArgumentException) { }

            try
            {
                var exterior = HostObjectUtils.GetSideFaces(host, ShellLayerType.Exterior).Select(reference => new Types.Face(reference, doc));
                DA.SetDataList("Exterior", exterior);
            }
            catch (Autodesk.Revit.Exceptions.ArgumentException) { }
        }
Beispiel #13
0
            public bool AllowReference(Reference reference, XYZ position)
            {
                if (doc == null)
                {
                    return(false);
                }

                Element currentFootPrintElem = doc.GetElement(reference);

                if (currentFootPrintElem == null)
                {
                    return(false);
                }

                FootPrintRoof currentFootPrintRoof = currentFootPrintElem as FootPrintRoof;

                if (currentFootPrintRoof == null)
                {
                    return(false);
                }

                Edge currentEdge = Support.GetEdgeFromReference(reference, currentFootPrintRoof);

                IList <PlanarFace> pfaces = new List <PlanarFace>();

                Support.IsListOfPlanarFaces(HostObjectUtils.GetTopFaces(currentFootPrintRoof), currentFootPrintRoof, out pfaces);

                EdgeInfo currentInfo = Support.GetCurveInformation(currentFootPrintRoof, currentEdge.AsCurve(), pfaces);

                System.Diagnostics.Debug.WriteLine(currentInfo.RoofLineType.ToString());

                if (currentInfo.RoofLineType != RoofLineType.Ridge && currentInfo.RoofLineType != RoofLineType.RidgeSinglePanel)
                {
                    return(false);
                }

                return(true);
            }
Beispiel #14
0
        static internal IList <Face> GetEdgeRelatedPanels(Edge targetEdge, FootPrintRoof targetRoof)
        {
            IList <Face> resultingListOfFaces = new List <Face>();
            Face         targetFace0          = targetEdge.GetFace(0);
            Face         targetFace1          = targetEdge.GetFace(1);

            IList <Reference> currentListOfReferences = HostObjectUtils.GetTopFaces(targetRoof).Union(HostObjectUtils.GetBottomFaces(targetRoof)).ToList();

            IList <PlanarFace> targetRoofPlanarFaces = new List <PlanarFace>();

            IsListOfPlanarFaces(currentListOfReferences, targetRoof, out targetRoofPlanarFaces);

            if (targetRoofPlanarFaces.Contains(targetFace0))
            {
                resultingListOfFaces.Add(targetFace0);
            }
            if (targetRoofPlanarFaces.Contains(targetFace1))
            {
                resultingListOfFaces.Add(targetFace1);
            }

            return(resultingListOfFaces);
        }
Beispiel #15
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Document      doc   = uidoc.Document;
            Selection     sel   = uidoc.Selection;

            var acview = doc.ActiveView;

            var IsAlignTopFAce    = false; //根据设置确定
            var IsAlignBottomFAce = true;  //根据设置确定

            var selectedIds = sel.GetElementIds();

            var selectionCollector = new FilteredElementCollector(doc, selectedIds);//选择集集合

            var beamFilter = new ElementCategoryFilter(BuiltInCategory.OST_StructuralFraming);

            var roofFilter  = new ElementCategoryFilter(BuiltInCategory.OST_Roofs);
            var floorFilter = new ElementCategoryFilter(BuiltInCategory.OST_Floors);
            var rampFilter  = new ElementCategoryFilter(BuiltInCategory.OST_Ramps);
            var structuralFoundationFilter = new ElementCategoryFilter(BuiltInCategory.OST_StructuralFoundation);

            var roofcollector          = new FilteredElementCollector(doc, selectedIds).WhereElementIsNotElementType().WherePasses(roofFilter);
            var floorCollector         = new FilteredElementCollector(doc, selectedIds).WhereElementIsNotElementType().WherePasses(floorFilter);
            var rampCollector          = new FilteredElementCollector(doc, selectedIds).WhereElementIsNotElementType().WherePasses(rampFilter);
            var strFoundationCollector = new FilteredElementCollector(doc, selectedIds).WhereElementIsNotElementType().WherePasses(structuralFoundationFilter);
            var beamCollector          = new FilteredElementCollector(doc, selectedIds).WhereElementIsNotElementType().WherePasses(beamFilter);

            //(1.梁随屋面)将与屋面在同一层的梁进行处理 使之紧贴屋面
            // -1. 获取屋面顶面或底面边界线

            var floorfaces = default(IList <Reference>);

            foreach (Floor floor in floorCollector)
            {
                if (IsAlignBottomFAce)
                {
                    floorfaces = HostObjectUtils.GetBottomFaces(floor);
                }
                else if (IsAlignTopFAce)
                {
                    floorfaces = HostObjectUtils.GetTopFaces(floor);
                }
                //排除空引用
                floorfaces = floorfaces.Where(m => floor.GetGeometryObjectFromReference(m) as Face != null).ToList();

                //for test
                #region test  weather face is null
                //foreach (var reference in floorfaces)
                //{
                //    //var type = roof.GetGeometryObjectFromReference(reference).GetType().ToString();
                //    //MessageBox.Show(type);

                //    var face = floor.GetGeometryObjectFromReference(reference) as Face;
                //    if (face != null)
                //    {
                //        var edgeloops = face.GetEdgesAsCurveLoops();
                //        foreach (var edgeloop in edgeloops)
                //        {
                //            foreach (Curve c in edgeloop)
                //            {
                //                doc.NewLine(c as Line);
                //            }
                //        }
                //    }
                //    else
                //    {
                //        //var face1 = roof.GetGeometryObjectFromReference(reference);
                //        //MessageBox.Show("null");
                //    }
                //}
                #endregion

                if (floorfaces.Count == 0 || floorfaces == null)
                {
                    continue;
                }

                //用屋面边线切断所有 投影相交的梁

                foreach (FamilyInstance beam in beamCollector)
                {
                }
            }

            return(Result.Succeeded);
        }
Beispiel #16
0
        private Result SlopeSelectedBuildingPad(UIDocument targetUIdoc, ref string message, double maxPointDistInFeet, double targetAngleInRadians)
        {
            Document  doc = targetUIdoc.Document;
            Selection sel = targetUIdoc.Selection;

            View3D current3dView = doc.ActiveView as View3D;

            if (current3dView == null)
            {
                message = Properties.Messages.SlopeGradingFromPads_Not3DView;
                return(Result.Failed);
            }

            BuildingPad selectedBuildingPad = doc.GetElement(sel.PickObject(ObjectType.Element, new PadSelectionFilter(), Properties.Messages.SlopeGradingFromPads_SelectPad)) as BuildingPad;

            //Check if the Pad is associate with a Surface (never seen one doesnt, but anyways)
            ElementId topoElementID = selectedBuildingPad.HostId;

            if (topoElementID.Equals(ElementId.InvalidElementId))
            {
                message = Properties.Messages.SlopeGradingFromPads_NoTopoAssociate;
                return(Result.Failed);
            }

            TopographySurface currentTopo = doc.GetElement(topoElementID) as TopographySurface;

            if (currentTopo == null)
            {
                message = Properties.Messages.SlopeGradingFromPads_NoTopoAssociate;;
                return(Result.Failed);
            }

            IList <CurveLoop> PadBoundaryLoops = new List <CurveLoop>();
            CurveLoop         outerLoop        = null;

            IList <Reference> TopFacesReferences = HostObjectUtils.GetTopFaces(selectedBuildingPad);

            if (TopFacesReferences.Count > 1)
            {
                message = Properties.Messages.SlopeGradingFromPads_PadsWithMoreThanOneUpperFace;
                return(Result.Failed);
            }

            XYZ plannarDirection = XYZ.BasisZ;
            XYZ plannarOrigin    = XYZ.Zero;

            // interate on the only face
            foreach (Reference currentFaceRef in TopFacesReferences)
            {
                GeometryObject currentFaceObj = selectedBuildingPad.GetGeometryObjectFromReference(currentFaceRef);
                if (currentFaceObj is PlanarFace)
                {
                    PlanarFace currentPlanarFace = currentFaceObj as PlanarFace;
                    plannarDirection = currentPlanarFace.FaceNormal;
                    plannarOrigin    = currentPlanarFace.Origin;
                    PadBoundaryLoops = currentPlanarFace.GetEdgesAsCurveLoops();
                }
                else
                {
                    message = Properties.Messages.SlopeGradingFromPads_UpperFaceNotPlanar;
                    return(Result.Failed);
                }
            }

            //Sort the curves so the outer loop comes first
            IList <IList <CurveLoop> > curveLoopLoop = ExporterIFCUtils.SortCurveLoops(PadBoundaryLoops);

            if (curveLoopLoop.Count > 0)
            {
                IList <CurveLoop> firstList = curveLoopLoop.First();
                if (firstList.Count > 0)
                {
                    outerLoop = firstList.First();
                }
            }

            if (outerLoop == null)
            {
                message = Properties.Messages.SlopeGradingFromPads_OuterLoopIssue;
                return(Result.Failed);
            }

            //This will be the list of elements that the ReferenceIntersector will shoot the rays
            //If we try to shoot the rays only in the toposurface and the it has subregions, the reference
            //intersection will not recognize these regions, so its necessary to shoot rays to the surface and its subregions
            IList <ElementId> currentSubRegionsAndSurface = currentTopo.GetHostedSubRegionIds();

            currentSubRegionsAndSurface.Add(topoElementID);

            //Search for the max distance from the Pad to the topography
            //Doesnt matter if it is upwards or downwards, but we will check that, since the ray has to go to one direction
            //This is to estabilish what the distance will be using to create the slope to the right amount
            ReferenceIntersector topoRefIntersec = new ReferenceIntersector(currentSubRegionsAndSurface, FindReferenceTarget.Mesh, current3dView);

            double maxDist = double.NegativeInfinity;

            foreach (Curve currentCurve in outerLoop)
            {
                int    numberOfInteractions = 0;
                double increaseAmount       = 0;
                double currentParameter     = 0;
                EstabilishInteractionPoints(currentCurve, maxPointDistInFeet, out numberOfInteractions, out increaseAmount);

                for (int i = 0; i < numberOfInteractions; i++)
                {
                    if (i == 0)
                    {
                        currentParameter = 0;
                    }
                    else
                    {
                        currentParameter += increaseAmount;
                    }

                    XYZ currentPointToEvaluate = currentCurve.Evaluate(currentParameter, true);

                    ReferenceWithContext currentRefContext = topoRefIntersec.FindNearest(currentPointToEvaluate, XYZ.BasisZ);
                    if (currentRefContext == null)
                    {
                        currentRefContext = topoRefIntersec.FindNearest(currentPointToEvaluate, XYZ.BasisZ.Negate());
                    }

                    if (currentRefContext == null)
                    {
                        continue;
                    }

                    double currentDist = currentRefContext.Proximity;
                    if (currentDist > maxDist)
                    {
                        maxDist = currentDist;
                    }
                }
            }

            // if we haven't changed the maxdist yet, something went wrong
            if (maxDist == double.NegativeInfinity)
            {
                message = Properties.Messages.SlopeGradingFromPads_NoTopoAssociate;
                return(Result.Failed);
            }

            //Estabilish the offset from the pad
            double offsetDist = maxDist / Math.Tan(targetAngleInRadians);

            using (TopographyEditScope topoEditGroup = new TopographyEditScope(doc, Properties.Messages.SlopeGradingFromPads_Transaction))
            {
                topoEditGroup.Start(topoElementID);
                using (Transaction t = new Transaction(doc, Properties.Messages.SlopeGradingFromPads_Transaction))
                {
                    t.Start();

                    CurveLoop offsetLoop = null;

                    try
                    {
                        offsetLoop = CurveLoop.CreateViaOffset(outerLoop, offsetDist, plannarDirection);
                    }
                    catch
                    {
                        message += Properties.Messages.SlopeGradingFromPads_OuterOffsetLoopIssue;
                        return(Result.Failed);
                    }

                    #region DebugCurve Loop

                    //Plane p = new Plane(plannarDirection, plannarOrigin);
                    //SketchPlane sktP = SketchPlane.Create(doc, p);
                    //foreach (Curve currentOffsetCurve in offsetLoop)
                    //{
                    //    doc.Create.NewModelCurve(currentOffsetCurve, sktP);
                    //}

                    #endregion


                    foreach (Curve currentOffsetCurve in offsetLoop)
                    {
                        int    numberOfInteractions = 0;
                        double increaseAmount       = 0;
                        double currentParameter     = 0;

                        EstabilishInteractionPoints(currentOffsetCurve, maxPointDistInFeet, out numberOfInteractions, out increaseAmount);

                        for (int i = 0; i < numberOfInteractions; i++)
                        {
                            if (i == 0)
                            {
                                currentParameter = 0;
                            }
                            else
                            {
                                currentParameter += increaseAmount;
                            }

                            XYZ currentPointOffset = currentOffsetCurve.Evaluate(currentParameter, true);

                            ReferenceWithContext currentRefContext = topoRefIntersec.FindNearest(currentPointOffset, XYZ.BasisZ);
                            if (currentRefContext == null)
                            {
                                currentRefContext = topoRefIntersec.FindNearest(currentPointOffset, XYZ.BasisZ.Negate());
                            }
                            //if we couldn't find points upwards and downwards, the topo is near the border, so we cant add points
                            if (currentRefContext == null)
                            {
                                continue;
                            }

                            Reference currentReference  = currentRefContext.GetReference();
                            XYZ       currentPointToAdd = currentReference.GlobalPoint;

                            if (currentTopo.ContainsPoint(currentPointToAdd))
                            {
                                continue;
                            }

                            IList <XYZ> ListPointToAdd = new List <XYZ>();
                            ListPointToAdd.Add(currentPointToAdd);

                            currentTopo.AddPoints(ListPointToAdd);
                        }
                    }

                    foreach (Curve currentCurve in outerLoop)
                    {
                        int    numberOfInteractions = 0;
                        double increaseAmount       = 0;
                        double currentParameter     = 0;
                        EstabilishInteractionPoints(currentCurve, maxPointDistInFeet, out numberOfInteractions, out increaseAmount);

                        for (int i = 0; i < numberOfInteractions; i++)
                        {
                            if (i == 0)
                            {
                                currentParameter = 0;
                            }
                            else
                            {
                                currentParameter += increaseAmount;
                            }

                            XYZ currentPointToAdd = currentCurve.Evaluate(currentParameter, true);

                            if (currentTopo.ContainsPoint(currentPointToAdd))
                            {
                                continue;
                            }

                            IList <XYZ> ListPointToAdd = new List <XYZ>();
                            ListPointToAdd.Add(currentPointToAdd);

                            currentTopo.AddPoints(ListPointToAdd);
                        }
                    }
                    t.Commit();
                }
                topoEditGroup.Commit(new TopographyFailurePreprocessor());

                return(Result.Succeeded);
            }
        }
Beispiel #17
0
        private static List <Polygon> GetProfile(this Autodesk.Revit.DB.Element element)
        {
            Document          doc             = element.Document;
            List <Polygon>    polygons        = new List <Polygon>();
            IList <Reference> firstSideFaces  = null;
            IList <Reference> secondSideFaces = null;

            switch (element)
            {
            case Wall revitWall:
                //use host object utils to get the outside face
                firstSideFaces  = HostObjectUtils.GetSideFaces(revitWall, ShellLayerType.Exterior);
                secondSideFaces = HostObjectUtils.GetSideFaces(revitWall, ShellLayerType.Interior);
                break;

            case Autodesk.Revit.DB.Floor revitFloor:
                firstSideFaces  = HostObjectUtils.GetTopFaces(revitFloor);
                secondSideFaces = HostObjectUtils.GetBottomFaces(revitFloor);
                break;
            }
            Element faceElement = doc.GetElement(firstSideFaces[0]);

            if (!(faceElement.GetGeometryObjectFromReference(firstSideFaces[0]) is Face exteriorFace) || !(faceElement.GetGeometryObjectFromReference(secondSideFaces[0]) is Face interiorFace))
            {
                return(null);
            }
            //this lets us pick the biggest face of the two sides. This is important because we want the shapes to close. 😁
            Face face = exteriorFace.Area > interiorFace.Area ? exteriorFace : interiorFace;
            // get the edges as curve loops and use the IFCUtils to sort them
            // credit: https://thebuildingcoder.typepad.com/blog/2015/01/getting-the-wall-elevation-profile.html
            IList <CurveLoop> curveLoops = face.GetEdgesAsCurveLoops();
            //this does the sorting so outside is the first item
            IList <CurveLoop> loops = ExporterIFCUtils.SortCurveLoops(curveLoops)[0];

            for (int i = 0; i < loops.Count; i++)
            {
                //here for outermost loop
                if (i == 0)
                {
                    var            outer    = loops[i];
                    List <Vector3> vertices = new List <Vector3>();
                    foreach (Autodesk.Revit.DB.Curve c in outer)
                    {
                        vertices.Add(c.GetEndPoint(0).ToVector3());
                    }
                    polygons.Add(new Polygon(vertices));
                }
                //here for the inner loops (voids)
                else
                {
                    var            inner    = loops[i];
                    List <Vector3> vertices = new List <Vector3>();
                    foreach (Autodesk.Revit.DB.Curve c in inner)
                    {
                        vertices.Add(c.GetEndPoint(0).ToVector3());
                    }
                    Polygon innerPolygon = new Polygon(vertices);
                    polygons.Add(innerPolygon);
                }
            }

            return(polygons);
        }
Beispiel #18
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document   doc   = uidoc.Document;

            if ((uidoc.ActiveView as View3D) == null)
            {
                message = "Por favor, rode este comando em uma vista 3d";
                return(Result.Failed);
            }

            Reference     currentReference     = uidoc.Selection.PickObject(ObjectType.Edge);
            FootPrintRoof currentFootPrintRoof = doc.GetElement(currentReference.ElementId) as FootPrintRoof;
            Edge          edge = currentFootPrintRoof.GetGeometryObjectFromReference(currentReference) as Edge;

            IList <PlanarFace> pfaces = new List <PlanarFace>();

            Support.IsListOfPlanarFaces(HostObjectUtils.GetBottomFaces(currentFootPrintRoof).Union(HostObjectUtils.GetTopFaces(currentFootPrintRoof)).ToList()
                                        , currentFootPrintRoof, out pfaces);

            RoofClasses.EdgeInfo currentInfo = Support.GetCurveInformation(currentFootPrintRoof, edge.AsCurve(), pfaces);

            using (Transaction t = new Transaction(doc, "Test"))
            {
                t.Start();

                FamilySymbol fs = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_GenericModel).WhereElementIsElementType().Where(type => type.Name.Contains("DebugPoint")).FirstOrDefault() as FamilySymbol;
                fs.Activate();
                doc.Create.NewFamilyInstance((currentInfo.Curve as Line).Direction, fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
                doc.Create.NewFamilyInstance(((currentInfo.Curve as Line).Direction).Rotate(-90), fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
                doc.Create.NewFamilyInstance(((currentInfo.Curve as Line).Direction).Rotate(45), fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
                t.Commit();
            }

            return(Result.Succeeded);
        }
Beispiel #19
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;
            Document      doc   = uidoc.Document;
            View          view  = doc.ActiveView;
            //TaskDialog.Show("Revit", "Hello World");

            // Create filters and collect walls/ slabs/ columns id in corresponding collector
            // walls
            IList <ElementId>        walls_id       = new List <ElementId>();
            FilteredElementCollector wall_collector = new FilteredElementCollector(doc).OfClass(typeof(Wall));

            foreach (Element w in wall_collector)
            {
                if (w is Wall)
                {
                    walls_id.Add(w.Id);
                }
            }
            // columns
            IList <ElementId>        columns_id       = new List <ElementId>();
            FilteredElementCollector column_collector = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_StructuralColumns);

            foreach (Element c in column_collector)
            {
                if (c is FamilyInstance)
                {
                    columns_id.Add(c.Id);
                }
            }
            // slabs
            IList <ElementId>        slabs_id  = new List <ElementId>();
            FilteredElementCollector collector = new FilteredElementCollector(doc).OfClass(typeof(Floor));

            foreach (Element e in collector)
            {
                if (e is Floor)
                {
                    slabs_id.Add(e.Id);
                }
            }

            //call create parts on walls/ slabs/ columns collectors
            using (Transaction t = new Transaction(doc, "Create Part")) {
                t.Start();
                // Create parts from the selected element
                // There is "CreateParts" but no "CreatePart", so needed to use a list containing the one element
                PartUtils.CreateParts(doc, walls_id);
                PartUtils.CreateParts(doc, columns_id);
                PartUtils.CreateParts(doc, slabs_id);
                t.Commit();
            }

            // start divide parts for walls, columns, slabs
            foreach (ElementId w_id in walls_id)
            {
                ICollection <ElementId> partsList = PartUtils.GetAssociatedParts(doc, w_id, true, true);

                // Get all levels
                ICollection <ElementId> levels = new FilteredElementCollector(doc).OfClass(typeof(Level)).OfCategory(BuiltInCategory.OST_Levels).ToElementIds();

                // Create a list of curves which needs to be used in DivideParts but for this example
                // the divide is being done by levels so the curve list will be empty
                IList <Curve> curve_list = new List <Curve>();

                // Get the host object corresponding to the selected element
                // HostObject is the parent class for walls, roof, floors, etc.
                HostObject hostObj = doc.GetElement(w_id) as HostObject;

                // Get the reference of one of the major faces of the selected element
                // Will be used to create a sketch plane
                Reference r = HostObjectUtils.GetSideFaces(hostObj, ShellLayerType.Exterior).First();

                using (Transaction t = new Transaction(doc, "Divide Part at Levels"))
                {
                    t.Start();
                    //Plane ref_plane = Plane.CreateByNormalAndOrigin(faceNormal, XYZ.Zero);
                    SketchPlane wall_sketchPlane = SketchPlane.Create(doc, r);
                    //SketchPlane sketchPlane = doc.Create.NewSketchPlane(r);
                    // Divide the parts
                    PartUtils.DivideParts(doc, partsList, levels, curve_list, wall_sketchPlane.Id);
                    t.Commit();
                }
            }

            // since walls and columns are all divided by all levels, so just use the sketch-plane of the last wall element
            ElementId borrow_from_wall = walls_id[0];

            foreach (ElementId c_id in columns_id)
            {
                ICollection <ElementId> partsList  = PartUtils.GetAssociatedParts(doc, c_id, true, true);
                ICollection <ElementId> levels     = new FilteredElementCollector(doc).OfClass(typeof(Level)).OfCategory(BuiltInCategory.OST_Levels).ToElementIds();
                IList <Curve>           curve_list = new List <Curve>();
                HostObject hostObj = doc.GetElement(borrow_from_wall) as HostObject;
                Reference  r       = HostObjectUtils.GetSideFaces(hostObj, ShellLayerType.Exterior).First();

                using (Transaction t = new Transaction(doc, "Divide Part at Levels")) {
                    t.Start();
                    SketchPlane column_sketchPlane = SketchPlane.Create(doc, r);
                    PartUtils.DivideParts(doc, partsList, levels, curve_list, column_sketchPlane.Id);
                    t.Commit();
                }
            }

            foreach (ElementId s_id in slabs_id)
            {
                //Selection sel = uidoc.Selection;
                //ISelectionFilter f = new JtElementsOfClassSelectionFilter<Grid>();
                //Reference elemRef = sel.PickObject(ObjectType.Element, f, "Pick a grid");
                //Grid grid = doc.GetElement(elemRef) as Grid;
                //ICollection<ElementId> grid_list = new List<ElementId>();
                //grid_list.Add(grid.Id);
                //IList<Curve> gridCurves = grid.GetCurvesInView(DatumExtentType.Model, view);

                ICollection <ElementId> partsList = PartUtils.GetAssociatedParts(doc, s_id, true, true);

                // Get all levels
                ICollection <ElementId> grids = new FilteredElementCollector(doc).OfClass(typeof(Grid)).OfCategory(BuiltInCategory.OST_Grids).ToElementIds();


                // Create a list of curves which needs to be used in DivideParts but for this example
                // the divide is being done by levels so the curve list will be empty
                IList <Curve> curve_list = new List <Curve>();

                HostObject hostObj = doc.GetElement(s_id) as HostObject;
                Reference  r       = HostObjectUtils.GetTopFaces(hostObj).First();
                using (Transaction t = new Transaction(doc, "Divide Part at Grids")) {
                    t.Start();
                    //Transaction sketchPlaneTransaction = new Transaction(doc, "Create Sketch Plane");
                    SketchPlane grid_sketchPlane = SketchPlane.Create(doc, r);
                    //SketchPlane grid_sketchPlane = null;
                    //sketchPlaneTransaction.Commit();
                    PartUtils.DivideParts(doc, partsList, grids, curve_list, grid_sketchPlane.Id);
                    t.Commit();
                }
            }
            // Set the view's "Parts Visibility" parameter so that parts are shown
            Parameter p = doc.ActiveView.get_Parameter(BuiltInParameter.VIEW_PARTS_VISIBILITY);

            using (Transaction t = new Transaction(doc, "Set View Parameter"))
            {
                t.Start();
                p.Set(0); // 0 = Show Parts, 1 = Show Original, 2 = Show Both
                t.Commit();
            }



            //ICollection<ElementId> elementIdsToDivide = new List<ElementId>();
            //if (PartUtils.AreElementsValidForCreateParts(doc, slabs_id))
            //{
            //    // AreElementsValidForCreateParts returned true, so the selected element is not a part but it is an element that can be used to create a part.
            //    Transaction createPartTransaction = new Transaction(doc, "Create Part");
            //    createPartTransaction.Start();
            //    PartUtils.CreateParts(doc, slabs_id); // create the parts
            //    createPartTransaction.Commit();
            //    foreach (ElementId e_id in slabs_id)
            //    {
            //        elementIdsToDivide = PartUtils.GetAssociatedParts(doc, e_id, true, true);
            //    }// get the id of the newly created part
            //}
            ////else if (pickedElement is Part)
            ////{
            ////    // The selected element is a part, so that part will be divided.
            ////    elementIdsToDivide.Add(pickedElement.Id);
            ////}
            //// Create geometry that will be used to divide the part. For this example, a new part will be divided from the main part that is one quarter of the face. More complex intelligence could be coded to divide the part based on construction logistics or the properties of the materials being used to create the part.
            //XYZ pointRight = null;
            //XYZ pointTop = null;
            //XYZ pointCorner = null;
            //XYZ pointCenter = null;

            //SketchPlane sketchPlane = null;
            //Plane plane = null;

            //Options opt = new Options();
            //opt.ComputeReferences = true;
            //foreach (Element e in slabs)
            //{
            //    GeometryElement geomElem = e.get_Geometry(opt);
            //    foreach (GeometryObject geomObject in geomElem)
            //    {
            //        if (geomObject is Solid) // get the solid geometry of the selected element
            //        {
            //            Solid solid = geomObject as Solid;
            //            FaceArray faceArray = solid.Faces;
            //            foreach (Face face in faceArray)
            //            {
            //                // find the center of the face
            //                BoundingBoxUV bbox = face.GetBoundingBox();
            //                UV center = new UV((bbox.Max.U - bbox.Min.U) / 2 + bbox.Min.U, (bbox.Max.V - bbox.Min.V) / 2 + bbox.Min.V);
            //                XYZ faceNormal = face.ComputeNormal(center);
            //                if (faceNormal.IsAlmostEqualTo(XYZ.BasisZ)) // this example is designed to work with a floor or other element with a large face whose normal is in the Z direction
            //                {
            //                    Transaction sketchPlaneTransaction = new Transaction(doc, "Create Sketch Plane");
            //                    sketchPlaneTransaction.Start();
            //                    plane = Plane.CreateByNormalAndOrigin(faceNormal, XYZ.Zero);
            //                    sketchPlane = SketchPlane.Create(doc, plane);
            //                    //sketchPlane = doc.SketchPlane.Create(face as PlanarFace);
            //                    sketchPlaneTransaction.Commit();

            //                    pointCenter = face.Evaluate(center);

            //                    UV top = new UV((bbox.Max.U - bbox.Min.U) / 2 + bbox.Min.U, bbox.Max.V);
            //                    pointTop = face.Evaluate(top);

            //                    UV right = new UV(bbox.Max.U, (bbox.Max.V - bbox.Min.V) / 2 + bbox.Min.V);
            //                    pointRight = face.Evaluate(right);

            //                    UV corner = new UV(bbox.Max.U, bbox.Max.V);
            //                    pointCorner = face.Evaluate(corner);

            //                    break;
            //                }
            //            }
            //        }
            //    }
            //}

            ////Selection sel = uidoc.Selection;
            ////Reference elemRef = sel.PickObject(
            ////ObjectType.Element, f, "Pick a grid");
            ////Grid grid = doc.GetElement(elemRef) as Grid;

            //// Create the curves that will be used for the part division.
            //IList<Curve> curveList = new List<Curve>();
            ////Curve curve1 = app.Create.NewLine(pointCenter, pointRight, true);
            //Curve curve1 = Line.CreateBound(pointCenter, pointRight);
            //curveList.Add(curve1);
            ////Curve curve2 = app.Create.NewLine(pointRight, pointCorner, true);
            //Curve curve2 = Line.CreateBound(pointRight, pointCorner);
            //curveList.Add(curve2);
            ////Curve curve3 = app.Create.NewLine(pointCorner, pointTop, true);
            //Curve curve3 = Line.CreateBound(pointCorner, pointTop);
            //curveList.Add(curve3);
            ////Curve curve4 = app.Create.NewLine(pointTop, pointCenter, true);
            //Curve curve4 = Line.CreateBound(pointTop, pointCenter);
            //curveList.Add(curve4);

            //// intersectingReferenceIds will be empty for this example.
            //ICollection<ElementId> intersectingReferenceIds = new List<ElementId>();

            //// Divide the part
            //Transaction dividePartTransaction = new Transaction(doc, "Divide Part");
            //dividePartTransaction.Start();
            //PartMaker maker = PartUtils.DivideParts(doc, elementIdsToDivide, intersectingReferenceIds, curveList, sketchPlane.Id);
            //dividePartTransaction.Commit();
            ////ICollection<ElementId> divElems = maker.GetSourceElementIds(); // Get the ids of the divided elements

            //// Set the view's "Parts Visibility" parameter so that parts are shown
            //Parameter partVisInView = doc.ActiveView.get_Parameter(BuiltInParameter.VIEW_PARTS_VISIBILITY);
            //Transaction setPartVizTransaction = new Transaction(doc, "Set View Parameter");
            //setPartVizTransaction.Start();
            //partVisInView.Set(0); // 0 = Show Parts, 1 = Show Original, 2 = Show Both
            //setPartVizTransaction.Commit();
            ////// Access current selection



            return(Result.Succeeded);
        }
Beispiel #20
0
        static public string CreateRoof(Dyn.Element roofElement, IList <Dyn.FamilyType> listOfFamilyTypes, Dyn.FamilyType ridgeFamilyType)
        {
            Document doc = DocumentManager.Instance.CurrentDBDocument;

            RoofStorage.revitApp = doc.Application;

            FootPrintRoof currentRoof = roofElement.InternalElement as FootPrintRoof;

            if (currentRoof == null)
            {
                throw new Exception("Error, element is not a footprint roof.");
            }

            Parameter selectedRoofSlopeParameter = currentRoof.get_Parameter(BuiltInParameter.ROOF_SLOPE);
            double    selectedRoofSlope          = selectedRoofSlopeParameter.AsDouble();

            //Verify if the roof has all the same slopes
            if (selectedRoofSlope <= 0)
            {
                throw new Exception("Error, it was not possible to estabilish a unique slope for the roof, please, make sure all eaves have the same slope.");
            }
            //Verify if the roof has the minimal slope
            if (selectedRoofSlope < 0.098)
            {
                throw new Exception("Error, please make sure the roof has a minimum of 10% slope.");
            }

            IList <Reference>  faceRefList    = HostObjectUtils.GetTopFaces(currentRoof);
            IList <PlanarFace> planarFaceList = new List <PlanarFace>();

            if (!IsListOfPlanarFaces(faceRefList, currentRoof, out planarFaceList))
            {
                throw new Exception("Error, invalid roof selected, please make sure all faces of the roof are flat.");
            }

            FamilySymbol ridgeFamilySymbol = ridgeFamilyType.InternalElement as FamilySymbol;

            if (ridgeFamilySymbol == null)
            {
                throw new Exception("Error, ridgeFamilyType is not a valid Family Type.");
            }

            if (!AdaptiveComponentFamilyUtils.IsAdaptiveComponentFamily(ridgeFamilySymbol.Family))
            {
                throw new Exception("Error, ridgeFamilyType is not a valid Adaptive component type");
            }

            if (AdaptiveComponentFamilyUtils.GetNumberOfPlacementPoints(ridgeFamilySymbol.Family) != 2)
            {
                throw new Exception("Error, ridgeFamilyType must have two insertion points");
            }

            IList <FamilySymbol> listOfFamilySymbols = ConvertDynFamilyTypeListToRevitFamilySymbolList(listOfFamilyTypes);

            if (listOfFamilySymbols.Count() < 1)
            {
                throw new Exception("Error, no adaptive family types were found on the input list");
            }

            if (doc.ActiveView as View3D == null)
            {
                throw new Exception("Error, please use this command on a 3d view");
            }

            //currentPointSymbol.Activate();
            string results = "";

            results += "Number of Roof Instances " + planarFaceList.Count() + "\n";

            foreach (PlanarFace currentFace in planarFaceList)
            {
                int numberOfCurves = GetOuterCurveLoop(currentFace).Count();

                FamilySymbol currentFamilySymbol = listOfFamilySymbols.Where(fs => AdaptiveComponentFamilyUtils.GetNumberOfPlacementPoints(fs.Family) == numberOfCurves).FirstOrDefault();

                if (currentFamilySymbol == null)
                {
                    continue;
                }

                CreateAdaptiveComponent(doc, currentFace, currentFamilySymbol);
            }

            IList <Curve> ridgeCurves = GetListOfRidgesHipsAndValleys(planarFaceList);

            results += "Number of Ridge Instances " + ridgeCurves.Count();

            foreach (Curve currentCurve in ridgeCurves)
            {
                curveInfo curvI = GetCurveInformation(currentRoof, currentCurve, planarFaceList);

                if (curvI.roofLineType == RoofLineType.Ridge || curvI.roofLineType == RoofLineType.Hip)
                {
                    CreateAdaptiveComponentFromLine(doc, currentCurve, ridgeFamilySymbol);
                }
            }


            return(results);
        }
        public void InsertOpening(Document doc, FamilySymbol familySymbol)
        {
            Element host = doc.GetElement(HostId);

            if (host.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Walls)
            {
                Wall      wall      = host as Wall;
                Reference reference = HostObjectUtils.GetSideFaces(wall, ShellLayerType.Exterior).First();
                ElementId levelId   = host.LevelId;

                Face face = host.GetGeometryObjectFromReference(reference) as Face;
                IntersectionResult intResult = face.Project(LocationPoint);
                if (intResult == null)
                {
                    return;                    // important to prompt user if no face found
                }
                double distance = intResult.Distance;
                if (distance > 0.001)
                {
                    reference = HostObjectUtils.GetSideFaces(wall, ShellLayerType.Interior).First();;
                }

                FamilyInstance fi        = doc.Create.NewFamilyInstance(reference, LocationPoint, new XYZ(0, 0, 0), familySymbol);
                Parameter      parameter = fi.get_Parameter(BuiltInParameter.INSTANCE_SCHEDULE_ONLY_LEVEL_PARAM);
                if (parameter != null)
                {
                    parameter.Set(levelId);
                }

                if (OpeningType == OpeningType.Round)
                {
                    fi.LookupParameter("D").Set(_cloudOpening.Diameter);
                    fi.LookupParameter("Cut Offset").Set(_cloudOpening.Offset);
                    fi.get_Parameter(new Guid("f417eece-19f0-4253-9820-f876661146e3")).Set(GtbPairGuid);
                }
                if (OpeningType == OpeningType.Rectangular)
                {
                    fi.LookupParameter("b").Set(_cloudOpening.Width);
                    fi.LookupParameter("h").Set(_cloudOpening.Height);
                    fi.LookupParameter("Cut Offset").Set(_cloudOpening.Offset);
                    fi.get_Parameter(new Guid("f417eece-19f0-4253-9820-f876661146e3")).Set(GtbPairGuid);
                }
                fi.LookupParameter("Depth").Set(Depth);
            }


            if (host.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Floors)
            {
                Floor          floor     = host as Floor;
                Reference      reference = HostObjectUtils.GetTopFaces(floor).First();
                ElementId      levelId   = host.LevelId;
                FamilyInstance fi        = doc.Create.NewFamilyInstance(reference, LocationPoint, new XYZ(0, 0, 0), familySymbol);
                Parameter      parameter = fi.get_Parameter(BuiltInParameter.INSTANCE_SCHEDULE_ONLY_LEVEL_PARAM);
                if (parameter != null)
                {
                    parameter.Set(levelId);
                }

                if (OpeningType == OpeningType.Round)
                {
                    fi.LookupParameter("D").Set(_cloudOpening.Diameter);
                    fi.LookupParameter("Cut Offset").Set(_cloudOpening.Offset);
                    fi.get_Parameter(new Guid("f417eece-19f0-4253-9820-f876661146e3")).Set(GtbPairGuid);
                }
                if (OpeningType == OpeningType.Rectangular)
                {
                    fi.LookupParameter("b").Set(_cloudOpening.Width);
                    fi.LookupParameter("h").Set(_cloudOpening.Height);
                    fi.LookupParameter("Cut Offset").Set(_cloudOpening.Offset);
                    fi.get_Parameter(new Guid("f417eece-19f0-4253-9820-f876661146e3")).Set(GtbPairGuid);
                }
                fi.LookupParameter("Depth").Set(Depth);
            }


            if (host.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Ceilings)
            {
                Ceiling        ceiling   = host as Ceiling;
                Reference      reference = HostObjectUtils.GetTopFaces(ceiling).First();
                ElementId      levelId   = host.LevelId;
                FamilyInstance fi        = doc.Create.NewFamilyInstance(reference, LocationPoint, new XYZ(0, 0, 0), familySymbol);
                Parameter      parameter = fi.get_Parameter(BuiltInParameter.INSTANCE_SCHEDULE_ONLY_LEVEL_PARAM);
                if (parameter != null)
                {
                    parameter.Set(levelId);
                }

                if (OpeningType == OpeningType.Round)
                {
                    fi.LookupParameter("D").Set(_cloudOpening.Diameter);
                    fi.LookupParameter("Cut Offset").Set(_cloudOpening.Offset);
                    fi.get_Parameter(new Guid("f417eece-19f0-4253-9820-f876661146e3")).Set(GtbPairGuid);
                }
                if (OpeningType == OpeningType.Rectangular)
                {
                    fi.LookupParameter("b").Set(_cloudOpening.Width);
                    fi.LookupParameter("h").Set(_cloudOpening.Height);
                    fi.LookupParameter("Cut Offset").Set(_cloudOpening.Offset);
                    fi.get_Parameter(new Guid("f417eece-19f0-4253-9820-f876661146e3")).Set(GtbPairGuid);
                }
                fi.LookupParameter("Depth").Set(_cloudOpening.Depth);
            }

            if (host.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Roofs)
            {
                Reference        reference  = null;
                ExtrusionRoof    eRoof      = host as ExtrusionRoof;
                List <Reference> references = HostObjectUtils.GetTopFaces(eRoof).ToList();
                foreach (Reference r in references)
                {
                    Face face = host.GetGeometryObjectFromReference(r) as Face;
                    //bool test = face.IsInside(new UV(LocationPoint.X, LocationPoint.Y));
                    IntersectionResult intResult = face.Project(LocationPoint);
                    if (intResult == null)
                    {
                        continue;
                    }
                    double distance = intResult.Distance;
                    if (distance < 0.001)
                    {
                        reference = r;
                    }
                }
                if (reference == null)
                {
                    return;
                }

                ElementId      levelId   = host.LevelId;
                FamilyInstance fi        = doc.Create.NewFamilyInstance(reference, LocationPoint, new XYZ(0, 0, 0), familySymbol);
                Parameter      parameter = fi.get_Parameter(BuiltInParameter.INSTANCE_SCHEDULE_ONLY_LEVEL_PARAM);
                if (parameter != null)
                {
                    parameter.Set(levelId);
                }

                if (OpeningType == OpeningType.Round)
                {
                    fi.LookupParameter("D").Set(_cloudOpening.Diameter);
                    fi.LookupParameter("Cut Offset").Set(_cloudOpening.Offset);
                    fi.get_Parameter(new Guid("f417eece-19f0-4253-9820-f876661146e3")).Set(GtbPairGuid);
                }
                if (OpeningType == OpeningType.Rectangular)
                {
                    fi.LookupParameter("b").Set(_cloudOpening.Width);
                    fi.LookupParameter("h").Set(_cloudOpening.Height);
                    fi.LookupParameter("Cut Offset").Set(_cloudOpening.Offset);
                    fi.get_Parameter(new Guid("f417eece-19f0-4253-9820-f876661146e3")).Set(GtbPairGuid);
                }
                fi.LookupParameter("Depth").Set(_cloudOpening.Depth);
            }
        }