public static Construction ToSAM(this HostObjAttributes hostObjAttributes, Core.Revit.ConvertSettings convertSettings) { if (hostObjAttributes == null) { return(null); } Construction result = convertSettings?.GetObject <Construction>(hostObjAttributes.Id); if (result != null) { return(result); } string name = hostObjAttributes.Name; PanelType panelType = hostObjAttributes.PanelType(); if (panelType == PanelType.Undefined) { panelType = Query.PanelType((BuiltInCategory)hostObjAttributes.Category.Id.IntegerValue); } Construction construction = Analytical.Query.DefaultConstruction(panelType); if (construction != null && (name.Equals(construction.Name) || name.Equals(construction.UniqueName()))) { result = new Construction(construction); } else { result = new Construction(hostObjAttributes.Name); } result.UpdateParameterSets(hostObjAttributes, ActiveSetting.Setting.GetValue <Core.TypeMap>(Core.Revit.ActiveSetting.Name.ParameterMap)); //result.Add(Core.Revit.Query.ParameterSet(hostObjAttributes)); convertSettings?.Add(hostObjAttributes.Id, result); if (panelType != PanelType.Undefined) { result.SetValue(ConstructionParameter.DefaultPanelType, panelType.Text()); } else { result.SetValue(ConstructionParameter.DefaultPanelType, null); } return(result); }
public static Construction ToSAM(this HostObjAttributes hostObjAttributes, ConvertSettings convertSettings) { if (hostObjAttributes == null) { return(null); } Construction result = convertSettings?.GetObject <Construction>(hostObjAttributes.Id); if (result != null) { return(result); } string name = hostObjAttributes.Name; PanelType panelType = hostObjAttributes.PanelType(); if (panelType == PanelType.Undefined) { panelType = Query.PanelType((BuiltInCategory)hostObjAttributes.Category.Id.IntegerValue); } Construction construction = Analytical.Query.DefaultConstruction(panelType); if (construction != null && (name.Equals(construction.Name) || name.Equals(construction.UniqueName()))) { result = new Construction(construction); } else { result = new Construction(hostObjAttributes.Name); } result.UpdateParameterSets(hostObjAttributes, ActiveSetting.Setting.GetValue <Core.TypeMap>(Core.Revit.ActiveSetting.Name.ParameterMap)); //result.Add(Core.Revit.Query.ParameterSet(hostObjAttributes)); convertSettings?.Add(hostObjAttributes.Id, result); if (panelType != PanelType.Undefined) { result.SetValue(ConstructionParameter.DefaultPanelType, panelType.Text()); } else { result.SetValue(ConstructionParameter.DefaultPanelType, null); } List <ConstructionLayer> constructionLayers = result.ConstructionLayers; if (constructionLayers != null && constructionLayers.Count != 0) { result.SetValue(ConstructionParameter.DefaultThickness, constructionLayers.ConvertAll(x => x.Thickness).Sum()); } else { CompoundStructure compoundStructure = hostObjAttributes.GetCompoundStructure(); if (compoundStructure != null) { #if Revit2017 || Revit2018 || Revit2019 || Revit2020 double thickness = UnitUtils.ConvertFromInternalUnits(compoundStructure.GetWidth(), DisplayUnitType.DUT_METERS); #else double thickness = UnitUtils.ConvertFromInternalUnits(compoundStructure.GetWidth(), UnitTypeId.Meters); #endif result.SetValue(ConstructionParameter.DefaultThickness, thickness); } } return(result); }
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); }
public static Aperture ToSAM_Aperture(this FamilyInstance familyInstance, Core.Revit.ConvertSettings convertSettings) { if (familyInstance == null) { return(null); } Aperture result = convertSettings?.GetObject <Aperture>(familyInstance.Id); if (result != null) { return(result); } if (Core.Revit.Query.Simplified(familyInstance)) { result = Core.Revit.Query.IJSAMObject <Aperture>(familyInstance); if (result != null) { convertSettings?.Add(familyInstance.Id, result); return(result); } } Point3D point3D_Location = Geometry.Revit.Query.Location(familyInstance); if (point3D_Location == null) { return(null); } PanelType panelType_Host = PanelType.Undefined; BuiltInCategory builtInCategory_Host = BuiltInCategory.INVALID; if (familyInstance.Host != null) { HostObject hostObject = familyInstance.Host as HostObject; if (hostObject != null) { builtInCategory_Host = (BuiltInCategory)hostObject.Category.Id.IntegerValue; List <Face3D> face3Ds_Temp = hostObject.Profiles(); if (face3Ds_Temp != null && face3Ds_Temp.Count != 0) { Geometry.Spatial.Plane plane_Host = face3Ds_Temp.Closest(point3D_Location)?.GetPlane(); if (plane_Host != null) { 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(); } } } ApertureConstruction apertureConstruction = ToSAM_ApertureConstruction(familyInstance, convertSettings); if (apertureConstruction == null && panelType_Host != PanelType.Undefined) { apertureConstruction = Analytical.Query.DefaultApertureConstruction(panelType_Host, familyInstance.ApertureType()); //Default Aperture Construction } 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 <Face3D> face3Ds = Geometry.Revit.Convert.ToSAM_Face3Ds(familyInstance); if (face3Ds == null || face3Ds.Count == 0) { return(null); } List <Point2D> point2Ds = new List <Point2D>(); foreach (Face3D face3D_Temp in face3Ds) { IClosedPlanar3D closedPlanar3D = face3D_Temp.GetExternalEdge3D(); if (closedPlanar3D is ICurvable3D) { List <ICurve3D> curve3Ds = ((ICurvable3D)closedPlanar3D).GetCurves(); foreach (ICurve3D curve3D in curve3Ds) { ICurve3D curve3D_Temp = plane.Project(curve3D); point2Ds.Add(plane.Convert(curve3D_Temp.GetStart())); } } } if (point2Ds == null || point2Ds.Count == 0) { return(null); } //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) { double height = UnitUtils.ConvertFromInternalUnits(parameter_Height.AsDouble(), DisplayUnitType.DUT_METERS); double width = UnitUtils.ConvertFromInternalUnits(parameter_Width.AsDouble(), DisplayUnitType.DUT_METERS); BoundingBox2D boundingBox2D = new BoundingBox2D(point2Ds); double factor_Height = height / boundingBox2D.Height; double factor_Width = width / boundingBox2D.Width; point2Ds = point2Ds.ConvertAll(x => new Point2D(x.X * factor_Width, x.Y * factor_Height)); } } Rectangle2D rectangle2D = Geometry.Planar.Create.Rectangle2D(point2Ds); result = new Aperture(apertureConstruction, new Face3D(plane, rectangle2D)); result.UpdateParameterSets(familyInstance, ActiveSetting.Setting.GetValue <Core.TypeMap>(Core.Revit.ActiveSetting.Name.ParameterMap)); convertSettings?.Add(familyInstance.Id, result); return(result); }