Beispiel #1
0
        public static object Wrap(Autodesk.Revit.DB.Panel ele, bool isRevitOwned)
        {
            if (AdaptiveComponentInstanceUtils.IsAdaptiveFamilySymbol(ele.Symbol))
            {
                return(AdaptiveComponent.FromExisting(ele, isRevitOwned));
            }

            return(CurtainPanel.FromExisting(ele, isRevitOwned));
        }
        /// <summary>
        /// Construct this type from an existing Revit element.
        /// </summary>
        /// <param name="panel"></param>
        /// <param name="isRevitOwned"></param>
        /// <returns></returns>
        internal static CurtainPanel FromExisting(Autodesk.Revit.DB.Panel panel, bool isRevitOwned)
        {
            if (panel == null)
            {
                throw new ArgumentNullException("panel");
            }

            return(new CurtainPanel(panel)
            {
                IsRevitOwned = true //making panels in Dynamo is not implemented
            });
        }
Beispiel #3
0
        public static List <Autodesk.Revit.DB.Panel> Panels(this Wall wall, Core.Revit.ConvertSettings convertSettings)
        {
            if (wall == null)
            {
                return(null);
            }

            CurtainGrid curtainGrid = wall.CurtainGrid;

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

            IEnumerable <ElementId> elementIds = curtainGrid.GetPanelIds();

            if (elementIds == null || elementIds.Count() == 0)
            {
                return(null);
            }

            List <Autodesk.Revit.DB.Panel> result = new List <Autodesk.Revit.DB.Panel>();

            foreach (ElementId elementId in elementIds)
            {
                Autodesk.Revit.DB.Panel panel = wall.Document.GetElement(elementId) as Autodesk.Revit.DB.Panel;
                if (panel == null)
                {
                    continue;
                }

                ElementId elementId_Host = panel.FindHostPanel();
                if (elementId_Host == null || elementId_Host == ElementId.InvalidElementId)
                {
                    result.Add(panel);
                    continue;
                }

                List <Autodesk.Revit.DB.Panel> panels = Panels(wall.Document.GetElement(elementId_Host) as Wall, convertSettings);
                if (panels != null && panels.Count > 0)
                {
                    result.AddRange(panels);
                }
            }

            return(result);
        }
 /// <summary>
 /// Initialize a CurtainPanel element
 /// </summary>
 /// <param name="panelElement"></param>
 private void InitCurtainPanel(Autodesk.Revit.DB.Panel panelElement)
 {
     InternalSetFamilyInstance(panelElement);
     boundsCache = null;
 }
 /// <summary>
 /// Create from an existing Revit Element
 /// </summary>
 /// <param name="panelElement"></param>
 protected CurtainPanel(Autodesk.Revit.DB.Panel panelElement)
 {
     SafeInit(() => InitCurtainPanel(panelElement));
 }
Beispiel #6
0
 /// <summary>
 /// Create from an existing Revit Element
 /// </summary>
 /// <param name="panelElement"></param>
 protected CurtainPanel(Autodesk.Revit.DB.Panel panelElement)
 {
     InternalSetFamilyInstance(panelElement);
     boundsCache = null;
 }
Beispiel #7
0
        public static List <Aperture> ToSAM_Apertures(this FamilyInstance familyInstance, ConvertSettings convertSettings)
        {
            if (familyInstance == null)
            {
                return(null);
            }

            List <Aperture> result = convertSettings?.GetObjects <Aperture>(familyInstance.Id);

            if (result != null)
            {
                return(result);
            }

            if (Core.Revit.Query.Simplified(familyInstance))
            {
                result = Core.Revit.Query.IJSAMObjects <Aperture>(familyInstance);
                if (result != null)
                {
                    convertSettings?.Add(familyInstance.Id, result);
                    return(result);
                }
            }

            Point3D point3D_Location = Geometry.Revit.Query.LocationPoint3D(familyInstance);

            if (point3D_Location == null)
            {
                List <Solid> solids = Core.Revit.Query.Solids(familyInstance, new Options());
                solids?.RemoveAll(x => x.Volume == 0);
                if (solids == null || solids.Count == 0)
                {
                    return(null);
                }

                if (solids.Count > 1)
                {
                    solids.Sort((x, y) => y.Volume.CompareTo(x.Volume));
                }

                point3D_Location = solids[0].ComputeCentroid()?.ToSAM();
            }

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

            List <Face3D> face3Ds = null;


            PanelType       panelType_Host       = PanelType.Undefined;
            BuiltInCategory builtInCategory_Host = BuiltInCategory.INVALID;
            HostObject      hostObject           = null;

            if (familyInstance.Host != null)
            {
                hostObject = familyInstance.Host as HostObject;

                if (hostObject != null)
                {
                    builtInCategory_Host = (BuiltInCategory)hostObject.Category.Id.IntegerValue;
                }
            }

            //Method 1 of extracting Geometry
            if (face3Ds == null || face3Ds.Count == 0)
            {
                Vector3D axisX  = null;
                Vector3D normal = null;
                Vector3D axisY  = null;
                if (builtInCategory_Host == BuiltInCategory.OST_Roofs)
                {
                    axisX  = familyInstance.HandOrientation.ToSAM_Vector3D(false);
                    axisY  = familyInstance.FacingOrientation.ToSAM_Vector3D(false);
                    normal = Geometry.Spatial.Query.AxisY(axisY, axisX);
                }
                else
                {
                    axisX  = familyInstance.HandOrientation.ToSAM_Vector3D(false);
                    normal = familyInstance.FacingOrientation.ToSAM_Vector3D(false);
                    axisY  = Geometry.Spatial.Query.AxisY(normal, axisX);
                }

                Geometry.Spatial.Plane plane = Geometry.Spatial.Create.Plane(point3D_Location, axisX, axisY);
                if (!plane.Normal.SameHalf(normal))
                {
                    plane.FlipZ(false);
                }

                List <Shell> shells = Geometry.Revit.Convert.ToSAM_Geometries <Shell>(familyInstance);
                if (shells == null || shells.Count == 0)
                {
                    return(null);
                }

                List <Point2D> point2Ds = new List <Point2D>();
                foreach (Shell shell in shells)
                {
                    List <Face3D> face3Ds_Shell = shell?.Face3Ds;
                    if (face3Ds_Shell == null || face3Ds_Shell.Count == 0)
                    {
                        continue;
                    }

                    foreach (Face3D face3D_Temp in face3Ds_Shell)
                    {
                        ISegmentable3D segmentable3D = face3D_Temp.GetExternalEdge3D() as ISegmentable3D;
                        if (segmentable3D == null)
                        {
                            continue;
                        }

                        segmentable3D?.GetPoints()?.ForEach(x => point2Ds.Add(plane.Convert(x)));
                    }
                }

                Face3D face3D = new Face3D(plane, Geometry.Planar.Create.Rectangle2D(point2Ds));
                if (face3D != null && face3D.IsValid() && face3D.GetArea() > Core.Tolerance.MacroDistance)
                {
                    face3Ds = new List <Face3D>()
                    {
                        face3D
                    };
                }
            }

            //Method 2 of extracting Geometry
            if (hostObject != null)
            {
                builtInCategory_Host = (BuiltInCategory)hostObject.Category.Id.IntegerValue;

                Geometry.Spatial.Plane plane_Host = null;
                if (hostObject is CurtainSystem && familyInstance is Autodesk.Revit.DB.Panel)
                {
                    Autodesk.Revit.DB.Panel panel = (Autodesk.Revit.DB.Panel)familyInstance;
                    ElementId uGridLineElementId  = null;
                    ElementId vGridLineElementId  = null;

                    panel.GetRefGridLines(ref uGridLineElementId, ref vGridLineElementId);

                    CurtainSystem curtainSystem = (CurtainSystem)hostObject;

                    List <Polygon3D> polygon3Ds = curtainSystem.CurtainCell(uGridLineElementId, vGridLineElementId)?.Polygon3Ds();
                    if (polygon3Ds != null && polygon3Ds.Count != 0)
                    {
                        polygon3Ds.Sort((x, y) => y.GetArea().CompareTo(x.GetArea()));
                        plane_Host = polygon3Ds[0].GetPlane();
                    }
                }
                else
                {
                    List <Face3D> face3Ds_Temp = hostObject.Profiles();
                    if (face3Ds_Temp != null && face3Ds_Temp.Count != 0)
                    {
                        plane_Host = face3Ds_Temp.Closest(point3D_Location)?.GetPlane();
                    }
                }

                if (plane_Host != null)
                {
                    face3Ds          = face3Ds?.ConvertAll(x => plane_Host.Project(x));
                    point3D_Location = plane_Host.Project(point3D_Location);
                }


                HostObjAttributes hostObjAttributes = familyInstance.Document.GetElement(hostObject.GetTypeId()) as HostObjAttributes;
                if (hostObjAttributes != null)
                {
                    panelType_Host = hostObjAttributes.PanelType();
                }

                if (panelType_Host == PanelType.Undefined)
                {
                    panelType_Host = hostObject.PanelType();
                }

                List <Face3D> face3Ds_Profiles = hostObject.Profiles(familyInstance.Id);
                face3Ds_Profiles?.RemoveAll(x => x == null || !x.IsValid());
                if (face3Ds_Profiles != null && face3Ds_Profiles.Count > 0)
                {
                    if (face3Ds == null || (face3Ds != null && face3Ds_Profiles.ConvertAll(x => x.GetArea()).Sum() <= face3Ds.ConvertAll(x => x.GetArea()).Sum()))
                    {
                        face3Ds = face3Ds_Profiles;
                    }
                }
            }

            ApertureConstruction apertureConstruction = ToSAM_ApertureConstruction(familyInstance, convertSettings);

            if (apertureConstruction == null && panelType_Host != PanelType.Undefined)
            {
                apertureConstruction = Analytical.Query.DefaultApertureConstruction(panelType_Host, familyInstance.ApertureType()); //Default Aperture Construction
            }
            if (face3Ds == null || face3Ds.Count == 0)
            {
                return(result);
            }

            //TODO: Working on SAM Families (requested by Michal)

            string parameterName_Height = Core.Revit.Query.Name(ActiveSetting.Setting, typeof(Aperture), typeof(FamilyInstance), "GetHeight");
            string parameterName_Width  = Core.Revit.Query.Name(ActiveSetting.Setting, typeof(Aperture), typeof(FamilyInstance), "GetWidth");

            if (!string.IsNullOrWhiteSpace(parameterName_Height) && !string.IsNullOrWhiteSpace(parameterName_Width))
            {
                Parameter parameter_Height = familyInstance.LookupParameter(parameterName_Height);
                Parameter parameter_Width  = familyInstance.LookupParameter(parameterName_Width);
                if (parameter_Height != null && parameter_Width != null && parameter_Height.HasValue && parameter_Width.HasValue && parameter_Height.StorageType == StorageType.Double && parameter_Width.StorageType == StorageType.Double)
                {
#if Revit2017 || Revit2018 || Revit2019 || Revit2020
                    double height = UnitUtils.ConvertFromInternalUnits(parameter_Height.AsDouble(), DisplayUnitType.DUT_METERS);
                    double width  = UnitUtils.ConvertFromInternalUnits(parameter_Width.AsDouble(), DisplayUnitType.DUT_METERS);
#else
                    double height = UnitUtils.ConvertFromInternalUnits(parameter_Height.AsDouble(), UnitTypeId.Meters);
                    double width  = UnitUtils.ConvertFromInternalUnits(parameter_Width.AsDouble(), UnitTypeId.Meters);
#endif
                }
            }

            result = new List <Aperture>();
            foreach (Face3D face3D_Temp in face3Ds)
            {
                Aperture aperture = Analytical.Create.Aperture(apertureConstruction, face3D_Temp);
                if (aperture == null)
                {
                    continue;
                }

                aperture.UpdateParameterSets(familyInstance, ActiveSetting.Setting.GetValue <Core.TypeMap>(Core.Revit.ActiveSetting.Name.ParameterMap));
                result.Add(aperture);
            }

            convertSettings?.Add(familyInstance.Id, result);

            return(result);
        }
Beispiel #8
0
 public static CurtainPanel Wrap(Autodesk.Revit.DB.Panel ele, bool isRevitOwned)
 {
     return(CurtainPanel.FromExisting(ele, isRevitOwned));
 }