public static List <ApertureConstruction> ToSAM_ApertureConstructions(this ModelEnergyProperties modelEnergyProperties, MaterialLibrary materialLibrary = null) { if (modelEnergyProperties == null) { return(null); } IEnumerable <IConstruction> constructions_Honeybee = modelEnergyProperties.ConstructionList; if (constructions_Honeybee == null) { return(null); } List <ApertureConstruction> result = new List <ApertureConstruction>(); foreach (IConstruction construction_Honeybee in constructions_Honeybee) { ApertureConstruction apertureConstruction = construction_Honeybee?.ToSAM_ApertureConstruction(materialLibrary); if (apertureConstruction != null) { result.Add(apertureConstruction); } } return(result); }
public static HoneybeeSchema.Door ToLadybugTools_Door(this Aperture aperture, MaterialLibrary materialLibrary = null, int index = -1, int index_Adjacent = -1, string adjacentPanelUniqueName = null, string adjacentSpaceUniqueName = null) { if (aperture == null) { return(null); } ApertureConstruction apertureConstruction = aperture.ApertureConstruction; if (apertureConstruction == null) { return(null); } MaterialType materialType = apertureConstruction.PaneConstructionLayers.MaterialType(materialLibrary); if (aperture.ApertureType != ApertureType.Door) { //Opaque Windows to be replaced by Doors if (materialType != MaterialType.Opaque) { return(null); } } PlanarBoundary3D planarBoundary3D = aperture.PlanarBoundary3D; if (planarBoundary3D == null) { return(null); } HoneybeeSchema.AnyOf <Outdoors, Surface> anyOf = new Outdoors(); Face3D face3D = planarBoundary3D.ToLadybugTools(); if (!string.IsNullOrEmpty(adjacentPanelUniqueName) && !string.IsNullOrEmpty(adjacentSpaceUniqueName)) { List <string> uniqueNames = new List <string>(); uniqueNames.Add(Core.LadybugTools.Query.UniqueName(aperture, index_Adjacent)); uniqueNames.Add(adjacentPanelUniqueName); uniqueNames.Add(adjacentSpaceUniqueName); anyOf = new Surface(uniqueNames); } DoorEnergyPropertiesAbridged apertureEnergyPropertiesAbridged = new DoorEnergyPropertiesAbridged(Query.UniqueName(apertureConstruction, !(index_Adjacent != -1 && index <= index_Adjacent))); HoneybeeSchema.Door door = new HoneybeeSchema.Door( identifier: Core.LadybugTools.Query.UniqueName(aperture, index), geometry: face3D, boundaryCondition: anyOf, properties: new DoorPropertiesAbridged(apertureEnergyPropertiesAbridged), displayName: aperture.Name); door.IsGlass = materialType == MaterialType.Transparent; return(door); }
public static string UniqueName(this ApertureConstruction apertureConstruction, bool reverse = true, int index = -1) { if (apertureConstruction == null) { return(null); } return(UniqueName((Core.SAMType)apertureConstruction, reverse, index)); }
public static BuiltInCategory BuiltInCategory(this ApertureConstruction apertureConstruction) { if (apertureConstruction == null) { return(Autodesk.Revit.DB.BuiltInCategory.INVALID); } return(BuiltInCategory(apertureConstruction.ApertureType)); }
public static Aperture ToSAM(this HoneybeeSchema.Aperture aperture, bool @internal, IEnumerable <ApertureConstruction> apertureConstructions = null) { if (aperture == null) { return(null); } Geometry.Spatial.Face3D face3D = Geometry.LadybugTools.Convert.ToSAM(aperture.Geometry); if (face3D == null) { return(null); } ApertureConstruction apertureConstruction = null; if (apertureConstructions != null && aperture.Properties?.Energy?.Construction != null) { foreach (ApertureConstruction apertureConstruction_Temp in apertureConstructions) { if (apertureConstruction_Temp == null) { continue; } if (apertureConstruction_Temp.ApertureType != ApertureType.Window) { continue; } if (aperture.Properties.Energy.Construction == apertureConstruction_Temp.Name) { apertureConstruction = apertureConstruction_Temp; break; } } } if (apertureConstruction == null) { AnyOf <OpaqueConstructionAbridged, WindowConstructionAbridged, ShadeConstruction, AirBoundaryConstructionAbridged> construction_Honeybee = Query.DefaultApertureConstruction(ApertureType.Window, @internal); if (construction_Honeybee != null) { apertureConstruction = construction_Honeybee.ToSAM_ApertureConstruction(); } } if (apertureConstruction == null) { apertureConstruction = new ApertureConstruction(aperture.DisplayName, ApertureType.Window); } Aperture result = new Aperture(apertureConstruction, face3D, Analytical.Query.OpeningLocation(face3D)); return(result); }
public static Aperture ToSAM(this EnergyAnalysisOpening energyAnalysisOpening, ConvertSettings convertSettings) { if (energyAnalysisOpening == null) { return(null); } Aperture result = convertSettings?.GetObject <Aperture>(energyAnalysisOpening.Id); if (result != null) { return(result); } Polygon3D polygon3D = energyAnalysisOpening.GetPolyloop().ToSAM(); if (polygon3D == null) { return(null); } FamilyInstance familyInstance = Core.Revit.Query.Element(energyAnalysisOpening) as FamilyInstance; if (familyInstance == null) { return(new Aperture(null, polygon3D)); } if (Core.Revit.Query.Simplified(familyInstance)) { result = Core.Revit.Query.IJSAMObjects <Aperture>(familyInstance)?.FirstOrDefault(); if (result != null) { return(result); } } ApertureConstruction apertureConstruction = ToSAM_ApertureConstruction(familyInstance, convertSettings); Point3D point3D_Location = Geometry.Revit.Query.LocationPoint3D(familyInstance); if (point3D_Location == null) { return(null); } result = new Aperture(apertureConstruction, polygon3D, point3D_Location); result.UpdateParameterSets(energyAnalysisOpening, ActiveSetting.Setting.GetValue <Core.TypeMap>(Core.Revit.ActiveSetting.Name.ParameterMap)); //result.UpdateParameterSets(familyInstance, ActiveSetting.Setting.GetValue<Core.TypeMap>(Core.Revit.ActiveSetting.Name.ParameterMap)); //result.Add(Core.Revit.Query.ParameterSet(familyInstance)); convertSettings?.Add(energyAnalysisOpening.Id, result); return(result); }
public static ApertureConstruction ToSAM(this WindowConstructionAbridged windowConstructionAbridged, Core.MaterialLibrary materialLibrary = null) { if (windowConstructionAbridged == null) { return(null); } List <ConstructionLayer> constructionLayers = Query.ConstructionLayers(materialLibrary, windowConstructionAbridged.Materials); ApertureConstruction result = new ApertureConstruction(System.Guid.NewGuid(), windowConstructionAbridged.Identifier, ApertureType.Window, constructionLayers); return(result); }
public static gbXMLSerializer.Construction TogbXML(this ApertureConstruction apertureConstruction, double tolerance = Core.Tolerance.MicroDistance) { if (apertureConstruction == null) { return(null); } gbXMLSerializer.Construction construction_gbXML = new gbXMLSerializer.Construction(); construction_gbXML.id = Core.gbXML.Query.Id(apertureConstruction, typeof(gbXMLSerializer.Construction)); construction_gbXML.Name = apertureConstruction.Name; return(construction_gbXML); }
public static Opening TogbXML(this Aperture aperture, int cADObjectIdSufix = -1, double tolerance = Core.Tolerance.MicroDistance) { if (aperture == null) { return(null); } PlanarBoundary3D planarBoundary3D = aperture.PlanarBoundary3D; if (planarBoundary3D == null) { return(null); } ApertureConstruction apertureConstruction = aperture.ApertureConstruction; if (apertureConstruction == null) { return(null); } string name = aperture.Name; if (string.IsNullOrWhiteSpace(name)) { name = aperture.ApertureConstruction.Name; } Opening opening = new Opening(); //opening.constructionIdRef = Core.gbXML.Query.Id(aperture.ApertureConstruction, typeof(gbXMLSerializer.Construction)); opening.Description = name; opening.id = Core.gbXML.Query.Id(aperture, typeof(Opening)); if (cADObjectIdSufix == -1) { opening.Name = string.Format("{0} [{1}]", name, aperture.Guid); } else { opening.Name = string.Format("{0} [{1}]", name, cADObjectIdSufix); } opening.openingType = Query.OpeningTypeEnum(aperture.ApertureConstruction.ApertureType); opening.pg = planarBoundary3D.TogbXML(tolerance); opening.rg = planarBoundary3D.TogbXML_RectangularGeometry(tolerance); opening.CADObjectId = Query.CADObjectId(aperture, cADObjectIdSufix); return(opening); }
public static ElementType DuplicateByName(this Document document, ApertureConstruction apertureConstruction_Old, string name_New, IEnumerable <string> parameterNames = null) { if (apertureConstruction_Old == null || document == null || string.IsNullOrWhiteSpace(name_New)) { return(null); } ElementType result = Core.Revit.Modify.DuplicateByName(document, apertureConstruction_Old, apertureConstruction_Old.BuiltInCategory(), name_New, parameterNames); if (result == null) { return(null); } Core.Revit.Modify.SetValues(result, apertureConstruction_Old, ActiveSetting.Setting, null, parameterNames); return(result); }
public static Log Log(ApertureConstruction apertureConstruction, Document document) { if (apertureConstruction == null || document == null) { return(null); } Log result = new Log(); Core.Modify.AddRange(result, Core.Revit.Create.Log(apertureConstruction, document)); string name = apertureConstruction.Name; if (string.IsNullOrWhiteSpace(name)) { result.Add("ApertureConstruction has invalid name Guid: {0}", LogRecordType.Error, apertureConstruction.Guid); return(result); } BuiltInCategory builtInCategory = apertureConstruction.BuiltInCategory(); if (builtInCategory == BuiltInCategory.INVALID) { result.Add("Could not get BuiltInCategory from ApertureConstruction Guid: {0}, Name: {1}", LogRecordType.Error, apertureConstruction.Guid, apertureConstruction.Name); return(result); } List <FamilySymbol> familySymbols = new FilteredElementCollector(document).OfClass(typeof(FamilySymbol)).OfCategory(builtInCategory).Cast <FamilySymbol>().ToList(); if (familySymbols != null && familySymbols.Count != 0) { foreach (FamilySymbol familySymbol in familySymbols) { string fullName = Core.Revit.Query.FullName(familySymbol); if (apertureConstruction.Name.Equals(fullName) || apertureConstruction.Name.Equals(familySymbol.Name)) { return(result); } } } result.Add("Could not find Revit FamilyType Name: {1} for ApertureConstruction Guid: {0}", LogRecordType.Error, apertureConstruction.Guid, apertureConstruction.Name); return(result); }
public static Aperture ToSAM(this gbXMLSerializer.Opening opening, double tolerance = Tolerance.MicroDistance) { if (opening == null) { return(null); } Polygon3D polygon3D = opening.pg.ToSAM(tolerance); if (polygon3D == null) { return(null); } ApertureType apertureType = Query.ApertureType(opening.openingType); ApertureConstruction apertureConstruction = new ApertureConstruction(opening.Name, apertureType); Aperture result = new Aperture(apertureConstruction, polygon3D); return(result); }
public static Log Log(this Aperture aperture, Document document) { if (aperture == null || document == null) { return(null); } Log result = new Log(); Core.Modify.AddRange(result, Core.Revit.Create.Log(aperture, document)); ApertureConstruction apertureConstruction = aperture.ApertureConstruction; if (apertureConstruction == null) { result.Add("Aperture {0} is missing ApertureConstruction Guid: {1}", LogRecordType.Error, aperture.Name, aperture.Guid); } result.AddRange(Log(apertureConstruction, document)); return(result); }
public static OpaqueConstructionAbridged ToLadybugTools(this ApertureConstruction apertureConstruction, bool reverse = true) { if (apertureConstruction == null) { return(null); } List <ConstructionLayer> constructionLayers = apertureConstruction.PaneConstructionLayers; if (constructionLayers == null || constructionLayers.Count == 0) { return(null); } if (reverse) { constructionLayers.Reverse(); } OpaqueConstructionAbridged result = new OpaqueConstructionAbridged(Query.UniqueName(apertureConstruction, reverse), constructionLayers.ConvertAll(x => x.Name), apertureConstruction.Name); return(result); }
public static ApertureConstruction ToSAM_ApertureConstruction(this FamilySymbol familySymbol, ConvertSettings convertSettings) { if (familySymbol == null) { return(null); } ApertureConstruction result = convertSettings?.GetObject <ApertureConstruction>(familySymbol.Id); if (result != null) { return(result); } string name = familySymbol.FullName(); ApertureType apertureType = familySymbol.ApertureType(); List <ApertureConstruction> apertureConstructions = Analytical.ActiveSetting.Setting.GetValue <ApertureConstructionLibrary>(AnalyticalSettingParameter.DefaultApertureConstructionLibrary).GetApertureConstructions(apertureType); if (apertureConstructions != null) { result = apertureConstructions.Find(x => name.Equals(x.UniqueName()) || name.Equals(x.Name)); } if (result == null) { result = new ApertureConstruction(name, apertureType); } result.UpdateParameterSets(familySymbol, ActiveSetting.Setting.GetValue <Core.TypeMap>(Core.Revit.ActiveSetting.Name.ParameterMap)); convertSettings?.Add(familySymbol.Id, result); return(result); }
public static ElementType DuplicateByType(this Document document, string name_Old, ApertureConstruction apertureConstruction_New) { if (apertureConstruction_New == null || document == null || string.IsNullOrWhiteSpace(name_Old)) { return(null); } BuiltInCategory builtInCategory = apertureConstruction_New.ApertureType.BuiltInCategory(); if (builtInCategory == BuiltInCategory.INVALID) { return(null); } List <ElementType> elementTypes = new FilteredElementCollector(document).OfClass(typeof(ElementType)).OfCategory(builtInCategory).Cast <ElementType>().ToList(); if (elementTypes == null || elementTypes.Count == 0) { return(null); } ElementType elementType = elementTypes.Find(x => x.Name.Equals(apertureConstruction_New.Name)); if (elementType == null) { ElementType elementType_ToBeDuplicated = elementTypes.Find(x => x.Name.Equals(name_Old)); if (elementType_ToBeDuplicated == null) { return(null); } elementType = elementType_ToBeDuplicated.Duplicate(apertureConstruction_New.Name); } if (elementType == null) { return(null); } Core.Revit.Modify.SetValues(elementType, apertureConstruction_New); Core.Revit.Modify.SetValues(elementType, apertureConstruction_New, ActiveSetting.Setting); return(elementType); }
public static gbXMLSerializer.gbXML TogbXML(this AnalyticalModel analyticalModel, double silverSpacing = Core.Tolerance.MacroDistance, double tolerance = Core.Tolerance.MicroDistance) { if (analyticalModel == null) { return(null); } List <gbXMLSerializer.Construction> constructions_gbXML = new List <gbXMLSerializer.Construction>(); List <Panel> panels = analyticalModel.AdjacencyCluster?.GetPanels(); if (panels != null && panels.Count > 0) { HashSet <System.Guid> guids = new HashSet <System.Guid>(); foreach (Panel panel in panels) { Construction construction = panel?.Construction; if (construction != null && !guids.Contains(construction.Guid)) { gbXMLSerializer.Construction construction_gbXML = construction.TogbXML(tolerance); if (construction_gbXML != null) { //constructions_gbXML.Add(construction_gbXML); guids.Add(construction.Guid); } } List <Aperture> apertures = panel?.Apertures; if (apertures != null && apertures.Count > 0) { foreach (Aperture aperture in apertures) { ApertureConstruction apertureConstruction = aperture?.ApertureConstruction; if (apertureConstruction == null) { continue; } gbXMLSerializer.Construction construction_gbXML = apertureConstruction.TogbXML(tolerance); if (construction_gbXML != null) { //constructions_gbXML.Add(construction_gbXML); guids.Add(construction.Guid); } } } } } gbXMLSerializer.gbXML gbXML = new gbXMLSerializer.gbXML(); gbXML.useSIUnitsForResults = "true"; gbXML.temperatureUnit = temperatureUnitEnum.C; gbXML.lengthUnit = lengthUnitEnum.Meters; gbXML.areaUnit = areaUnitEnum.SquareMeters; gbXML.volumeUnit = volumeUnitEnum.CubicMeters; gbXML.version = versionEnum.FiveOneOne; gbXML.Campus = analyticalModel.TogbXML_Campus(silverSpacing, tolerance); gbXML.Constructions = constructions_gbXML.ToArray(); gbXML.DocumentHistory = Core.gbXML.Query.DocumentHistory(analyticalModel.Guid); return(gbXML); }
public static FamilySymbol ToRevit(this ApertureConstruction apertureConstruction, Document document, Core.Revit.ConvertSettings convertSettings) { if (apertureConstruction == null) { return(null); } FamilySymbol result = convertSettings?.GetObject <FamilySymbol>(apertureConstruction.Guid); if (result != null) { return(result); } string fullName = apertureConstruction.Name; string familyName; string familyTypeName; if (!Core.Revit.Query.TryGetFamilyNameAndTypeName(fullName, out familyName, out familyTypeName)) { return(null); } List <BuiltInCategory> builtInCategories = new List <BuiltInCategory>(); BuiltInCategory builtInCategory = apertureConstruction.BuiltInCategory(); if (builtInCategory == BuiltInCategory.INVALID) { builtInCategories.Add(Query.BuiltInCategory(ApertureType.Door)); builtInCategories.Add(Query.BuiltInCategory(ApertureType.Window)); } else { builtInCategories.Add(builtInCategory); } List <FamilySymbol> familySymbols = new FilteredElementCollector(document).OfClass(typeof(FamilySymbol)).WherePasses(new LogicalOrFilter(builtInCategories.ConvertAll(x => new ElementCategoryFilter(x) as ElementFilter))).Cast <FamilySymbol>().ToList(); if (familySymbols == null || familySymbols.Count == 0) { return(null); } familySymbols.RemoveAll(x => string.IsNullOrWhiteSpace(x.Name) || !x.Name.Equals(familyTypeName)); if (!string.IsNullOrWhiteSpace(familyName)) { familySymbols.RemoveAll(x => string.IsNullOrWhiteSpace(x.FamilyName) || !x.FamilyName.Equals(familyName)); } familySymbols.RemoveAll(x => x.Family == null && x.Family.FamilyPlacementType != FamilyPlacementType.OneLevelBasedHosted); if (familySymbols.Count == 0) { return(null); } result = familySymbols.First(); if (result == null) { return(null); } if (!result.IsActive) { result.Activate(); } convertSettings?.Add(apertureConstruction.Guid, result); return(result); }
public static WindowConstructionAbridged ToLadybugTools_WindowConstructionAbridged(this ApertureConstruction apertureConstruction, bool reverse = true) { if (apertureConstruction == null) { return(null); } List <ConstructionLayer> constructionLayers = apertureConstruction.PaneConstructionLayers; if (constructionLayers == null) { return(null); } if (reverse) { constructionLayers.Reverse(); } WindowConstructionAbridged result = new WindowConstructionAbridged( identifier: Query.UniqueName(apertureConstruction, reverse), materials: constructionLayers.ConvertAll(x => x.Name), displayName: apertureConstruction.Name); return(result); }
public static FamilyInstance ToRevit(this Aperture aperture, Document document, HostObject hostObject, Core.Revit.ConvertSettings convertSettings) { if (aperture == null || document == null) { return(null); } FamilyInstance result = convertSettings?.GetObject <FamilyInstance>(aperture.Guid); if (result != null) { return(result); } ApertureConstruction apertureConstruction = aperture.ApertureConstruction; if (apertureConstruction == null) { return(null); } FamilySymbol familySymbol = apertureConstruction.ToRevit(document, convertSettings); if (familySymbol == null) { familySymbol = Analytical.Query.DefaultApertureConstruction(hostObject.PanelType(), apertureConstruction.ApertureType).ToRevit(document, convertSettings); //Default Aperture Construction } if (familySymbol == null) { return(null); } Point3D point3D_Location = aperture.PlanarBoundary3D?.Plane?.Origin; if (point3D_Location == null) { return(null); } Level level = Geometry.Revit.Query.LowLevel(document, point3D_Location.Z); if (level == null) { return(null); } XYZ referenceDirection = new XYZ(0, 0, 0); if (hostObject is RoofBase) { Face3D face3D = aperture.GetFace3D(); Geometry.Spatial.Plane plane = face3D.GetPlane(); bool coplanar = plane.Coplanar(Geometry.Spatial.Plane.WorldXY); //if(coplanar) //{ // referenceDirection = new XYZ(0, 0, 1); //} result = document.Create.NewFamilyInstance(point3D_Location.ToRevit(), familySymbol, referenceDirection, hostObject, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); if (result == null) { return(null); } //List<Geometry.Planar.Point2D> point2Ds = new List<Geometry.Planar.Point2D>(); //IClosedPlanar3D closedPlanar3D = face3D.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())); // } //} //Geometry.Planar.Rectangle2D rectangle2D = Geometry.Planar.Create.Rectangle2D(point2Ds); Geometry.Planar.Rectangle2D rectangle2D = Analytical.Create.Rectangle2D(aperture.PlanarBoundary3D); if (rectangle2D == null) { return(null); } document.Regenerate(); result = document.GetElement(result.Id) as FamilyInstance; Vector3D handOrientation_FamilyInstance = result.HandOrientation.ToSAM_Vector3D(false); Vector3D facingOrientation_FamilyInstance = result.FacingOrientation.ToSAM_Vector3D(false); double factor = 0; Geometry.Planar.Vector2D direction = rectangle2D.WidthDirection; if (!coplanar && Core.Query.Round(direction.Y) < 0) { factor = System.Math.PI / 2; } Vector3D handOrienation_Aperture = plane.Convert(direction); Geometry.Spatial.Plane plane_FamilyInstance = new Geometry.Spatial.Plane(point3D_Location, handOrientation_FamilyInstance, facingOrientation_FamilyInstance); handOrienation_Aperture = plane_FamilyInstance.Project(handOrienation_Aperture); double angle = Geometry.Spatial.Query.SignedAngle(handOrientation_FamilyInstance, handOrienation_Aperture, plane.Normal); result.Location.Rotate(Line.CreateUnbound(point3D_Location.ToRevit(), plane.Normal.ToRevit(false)), angle + factor); //document.Regenerate(); //BoundingBox3D boundingBox3D_familyInstance = familyInstance.BoundingBox3D(); //BoundingBox3D boundingBox3D_Aperture = aperture.GetBoundingBox(); //if(boundingBox3D_familyInstance.Min.Distance(boundingBox3D_Aperture.Min) > SAM.Core.Tolerance.MacroDistance) // familyInstance.Location.Rotate(Line.CreateUnbound(point3D_Location.ToRevit(), plane.Normal.ToRevit(false)), System.Math.PI / 2); //Geometry.Planar.Rectangle2D rectangle2D = Geometry.Planar.Create.Rectangle2D(point2Ds); //Geometry.Planar.Vector2D direction = null; //if (rectangle2D.Height > rectangle2D.Width) // direction = rectangle2D.HeightDirection; //else // direction = rectangle2D.WidthDirection; //double angle = plane.Convert(direction).ToRevit(false).AngleTo(new XYZ(0, 1, 0)); //angle = System.Math.PI - angle; ////if (angle > System.Math.PI) //// angle = -(angle - System.Math.PI); //if (direction.X < 0) // angle = -angle; //familyInstance.Location.Rotate(Line.CreateUnbound(point3D_Location.ToRevit(), plane.Normal.ToRevit(false)), angle); } else { result = document.Create.NewFamilyInstance(point3D_Location.ToRevit(), familySymbol, hostObject, level, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); } if (result == null) { return(null); } if (result.CanFlipHand) { document.Regenerate(); //This is needed to get flip correctly pushed to revit Vector3D axisX = result.HandOrientation.ToSAM_Vector3D(false); if (!axisX.SameHalf(aperture.Plane.AxisX)) { result.flipHand(); } } if (result.CanFlipFacing) { document.Regenerate(); //This is needed to get flip correctly pushed to revit Vector3D normal = result.FacingOrientation.ToSAM_Vector3D(false); if (!normal.SameHalf(aperture.Plane.Normal)) { result.flipFacing(); } } if (convertSettings.ConvertParameters) { Core.Revit.Modify.SetValues(result, aperture, new BuiltInParameter[] { BuiltInParameter.INSTANCE_SILL_HEIGHT_PARAM, BuiltInParameter.INSTANCE_HEAD_HEIGHT_PARAM, BuiltInParameter.FAMILY_LEVEL_PARAM, BuiltInParameter.SCHEDULE_LEVEL_PARAM }); Core.Revit.Modify.SetValues(result, aperture, ActiveSetting.Setting); bool simplified = false; //Check if geometry is simplified if (!Geometry.Planar.Query.Rectangular(aperture.PlanarBoundary3D?.ExternalEdge2DLoop?.GetClosed2D(), Core.Tolerance.MacroDistance)) { simplified = true; } if (!simplified && result.Host is Autodesk.Revit.DB.Wall) { Face3D face3D = aperture.GetFace3D(); Geometry.Spatial.Plane plane = face3D.GetPlane(); Geometry.Planar.Rectangle2D rectangle2D = Analytical.Create.Rectangle2D(aperture.PlanarBoundary3D); if (rectangle2D != null) { Vector3D widthDirection = plane.Convert(rectangle2D.WidthDirection); Vector3D heightDirection = plane.Convert(rectangle2D.HeightDirection); //TODO: Implement code for Tilted Walls Vector3D vector3D_Z = Vector3D.WorldZ; if (!widthDirection.AlmostSimilar(vector3D_Z) && !heightDirection.AlmostSimilar(vector3D_Z)) { simplified = true; } } } Core.Revit.Modify.SetSimplified(result, simplified); Core.Revit.Modify.SetJson(result, aperture.ToJObject()?.ToString()); } convertSettings?.Add(aperture.Guid, result); return(result); }
public static List <IMaterial> AddDefaultMaterials(this MaterialLibrary materialLibrary, ApertureConstruction apertureConstruction) { if (materialLibrary == null || apertureConstruction == null) { return(null); } List <ConstructionLayer> constructionLayers = apertureConstruction.PaneConstructionLayers; if (apertureConstruction.FrameConstructionLayers != null) { if (constructionLayers == null) { constructionLayers = new List <ConstructionLayer>(); } constructionLayers.AddRange(apertureConstruction.FrameConstructionLayers); } return(AddDefaultMaterials(materialLibrary, constructionLayers)); }
private static string ToGEM(this Panel panel, List <Point3D> point3Ds, double tolerance = Core.Tolerance.Distance) { string result = string.Empty; List <Point3D> externalEdge = Query.ExternalEdgePoint3Ds(panel, tolerance)?.ToList(); if (externalEdge == null) { return(result); } Plane plane = null; //Handling Panels with Air PanelType and CurtainWall PanelType if (panel.PanelType == PanelType.Air || panel.PanelType == PanelType.CurtainWall) { plane = panel.ReferencePlane(tolerance); if (plane != null) { List <List <Point2D> > openings = new List <List <Point2D> >(); openings.Add(externalEdge.ConvertAll(x => plane.Convert(x))); result += string.Format("{0} {1}\n", externalEdge.Count, string.Join(" ", externalEdge.ConvertAll(x => point3Ds.IndexOf(x) + 1))); result += string.Format("{0}\n", openings.Count); OpeningType openingType = OpeningType.Undefined; if (panel.PanelType == PanelType.Air) { openingType = OpeningType.Hole; } else { openingType = OpeningType.Window; } foreach (List <Point2D> opening in openings) { result += ToGEM(opening, openingType); } } return(result); } List <List <Point2D> > holes = new List <List <Point2D> >(); List <List <Point3D> > internalEdgesPoint3Ds = Query.InternalEdgesPoint3Ds(panel, tolerance); if (internalEdgesPoint3Ds != null) { plane = panel.ReferencePlane(tolerance); if (plane != null) { foreach (List <Point3D> internalEdge in internalEdgesPoint3Ds) { holes.Add(internalEdge.ConvertAll(x => plane.Convert(x))); } } } List <List <Point2D> > windows = new List <List <Point2D> >(); List <List <Point2D> > doors = new List <List <Point2D> >(); List <Aperture> apertures = panel.Apertures; if (apertures != null && apertures.Count != 0) { foreach (Aperture aperture in apertures) { ApertureConstruction apertureConstruction = aperture?.ApertureConstruction; if (apertureConstruction == null) { continue; } ApertureType apertureType = apertureConstruction.ApertureType; if (apertureType == ApertureType.Undefined) { continue; } List <Point3D> externalEdge_Aperture = aperture.ExternalEdgePoint3Ds(tolerance)?.ToList(); if (externalEdge_Aperture == null || externalEdge_Aperture.Count == 0) { continue; } List <List <Point2D> > point2Ds_Apertures = null; switch (apertureType) { case ApertureType.Door: point2Ds_Apertures = doors; break; case ApertureType.Window: point2Ds_Apertures = windows; break; } if (point2Ds_Apertures == null) { continue; } if (plane == null) { plane = panel.ReferencePlane(tolerance); } if (plane == null) { break; } point2Ds_Apertures.Add(externalEdge_Aperture.ConvertAll(x => plane.Convert(x))); } } result += string.Format("{0} {1}\n", externalEdge.Count, string.Join(" ", externalEdge.ConvertAll(x => point3Ds.IndexOf(x) + 1))); result += string.Format("{0}\n", windows.Count + doors.Count + holes.Count); foreach (List <Point2D> hole in holes) { result += ToGEM(hole, OpeningType.Hole); } foreach (List <Point2D> window in windows) { result += ToGEM(window, OpeningType.Window); } foreach (List <Point2D> door in doors) { result += ToGEM(door, OpeningType.Door); } return(result); }
public static AnalyticalModel ToSAM(this Model model) { if (model == null) { return(null); } MaterialLibrary materialLibrary = null; ProfileLibrary profileLibrary = null; List <Construction> constructions = null; List <ApertureConstruction> apertureConstructions = null; List <InternalCondition> internalConditions = null; ModelEnergyProperties modelEnergyProperties = model.Properties?.Energy; if (modelEnergyProperties != null) { materialLibrary = modelEnergyProperties.ToSAM_MaterialLibrary(); constructions = modelEnergyProperties.ToSAM_Constructions(); apertureConstructions = modelEnergyProperties.ToSAM_ApertureConstructions(); internalConditions = modelEnergyProperties.ToSAM_InternalConditions(); profileLibrary = modelEnergyProperties.ToSAM_ProfileLibrary(); } if (materialLibrary == null) { materialLibrary = new MaterialLibrary(string.Empty); } if (constructions == null) { constructions = new List <Construction>(); } if (apertureConstructions == null) { apertureConstructions = new List <ApertureConstruction>(); } List <Tuple <Panel, Geometry.Spatial.BoundingBox3D> > tuples = new List <Tuple <Panel, Geometry.Spatial.BoundingBox3D> >(); AdjacencyCluster adjacencyCluster = new AdjacencyCluster(); List <Room> rooms = model.Rooms; if (rooms != null) { foreach (Room room in rooms) { room.IndoorShades?.ConvertAll(x => x.ToSAM(constructions))?.ForEach(x => adjacencyCluster.AddObject(x)); room.OutdoorShades?.ConvertAll(x => x.ToSAM(constructions))?.ForEach(x => adjacencyCluster.AddObject(x)); List <Face> faces = room.Faces; if (faces == null) { continue; } List <Panel> panels = new List <Panel>(); foreach (Face face in faces) { Panel panel = face.ToSAM(constructions, apertureConstructions); if (panel == null) { continue; } Geometry.Spatial.Point3D point3D = panel.GetFace3D().GetInternalPoint3D(); if (point3D == null) { continue; } Panel panel_Existing = tuples.FindAll(x => x.Item2.Inside(point3D, true))?.Find(x => x.Item1.GetFace3D().On(point3D))?.Item1; if (panel_Existing != null) { panel = panel_Existing; } else { tuples.Add(new Tuple <Panel, Geometry.Spatial.BoundingBox3D>(panel, panel.GetFace3D().GetBoundingBox())); face.IndoorShades?.ConvertAll(x => x.ToSAM(constructions))?.ForEach(x => adjacencyCluster.AddObject(x)); face.OutdoorShades?.ConvertAll(x => x.ToSAM(constructions))?.ForEach(x => adjacencyCluster.AddObject(x)); Construction construction = panel.Construction; if (construction != null) { if (constructions.Find(x => x.Name.Equals(construction.Name)) == null) { constructions.Add(construction); } materialLibrary.AddDefaultMaterials(construction); } List <Aperture> apertures = panel.Apertures; if (apertures != null) { foreach (Aperture aperture in apertures) { ApertureConstruction apertureConstruction = aperture.ApertureConstruction; if (apertureConstruction != null) { if (apertureConstructions.Find(x => x.Name.Equals(apertureConstruction.Name)) == null) { apertureConstructions.Add(apertureConstruction); } materialLibrary.AddDefaultMaterials(apertureConstruction); } } } List <HoneybeeSchema.Aperture> apertures_HoneybeeSchema = face.Apertures; if (apertures_HoneybeeSchema != null) { foreach (HoneybeeSchema.Aperture aperture_HoneybeeSchema in apertures_HoneybeeSchema) { aperture_HoneybeeSchema.IndoorShades?.ConvertAll(x => x.ToSAM(constructions))?.ForEach(x => adjacencyCluster.AddObject(x)); aperture_HoneybeeSchema.OutdoorShades?.ConvertAll(x => x.ToSAM(constructions))?.ForEach(x => adjacencyCluster.AddObject(x)); } } List <HoneybeeSchema.Door> doors_HoneybeeSchema = face.Doors; if (doors_HoneybeeSchema != null) { foreach (HoneybeeSchema.Door door_HoneybeeSchema in doors_HoneybeeSchema) { door_HoneybeeSchema.IndoorShades?.ConvertAll(x => x.ToSAM(constructions))?.ForEach(x => adjacencyCluster.AddObject(x)); door_HoneybeeSchema.OutdoorShades?.ConvertAll(x => x.ToSAM(constructions))?.ForEach(x => adjacencyCluster.AddObject(x)); } } } panels.Add(panel); } Space space = room.ToSAM(internalConditions); adjacencyCluster.AddObject(space); if (panels != null) { foreach (Panel panel in panels) { adjacencyCluster.AddObject(panel); adjacencyCluster.AddRelation(space, panel); } } } } List <Shade> shades = model.OrphanedShades; if (shades != null && shades.Count != 0) { foreach (Shade shade in shades) { Panel panel = shade?.ToSAM(constructions); if (panel != null) { Construction construction = panel.Construction; if (construction != null) { if (constructions.Find(x => x.Name.Equals(construction.Name)) == null) { constructions.Add(construction); } materialLibrary.AddDefaultMaterials(construction); } List <Aperture> apertures = panel.Apertures; if (apertures != null) { foreach (Aperture aperture in apertures) { ApertureConstruction apertureConstruction = aperture.ApertureConstruction; if (apertureConstruction != null) { if (apertureConstructions.Find(x => x.Name.Equals(apertureConstruction.Name)) == null) { apertureConstructions.Add(apertureConstruction); } materialLibrary.AddDefaultMaterials(apertureConstruction); } } } adjacencyCluster.AddObject(panel); } } } AnalyticalModel result = new AnalyticalModel(model.DisplayName, null, null, null, adjacencyCluster, materialLibrary, profileLibrary); return(result); }
public static IEnumerable <Core.SAMObject> ToSAM(this Element element, Core.Revit.ConvertSettings convertSettings) { IEnumerable <Core.SAMObject> result = null; if (element is WallSweep) { List <Panel> panels = ToSAM_Panels((WallSweep)element, convertSettings); if (panels != null) { result = panels.ConvertAll(x => x as Core.SAMObject); } } else if (element is HostObject) { List <Panel> panels = ToSAM((HostObject)element, convertSettings); if (panels != null) { result = panels.Cast <Core.SAMObject>(); } } else if (element is HostObjAttributes) { Construction construction = ToSAM((HostObjAttributes)element, convertSettings); if (construction != null) { result = new List <Core.SAMObject>() { construction } } ; } else if (element is SpatialElement) { Space space = ToSAM((SpatialElement)element, convertSettings); if (space != null) { result = new List <Core.SAMObject>() { space } } ; } else if (element is FamilyInstance) { FamilyInstance familyInstance = (FamilyInstance)element; if (element.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Windows || element.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Doors) { List <Aperture> apertures = ToSAM_Apertures(familyInstance, convertSettings); if (apertures != null) { result = apertures.Cast <Core.SAMObject>(); } } else { result = familyInstance.ToSAM_Panels(convertSettings); } } else if (element is FamilySymbol) { if (element.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Windows || element.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Doors || element.Category.Id.IntegerValue == (int)BuiltInCategory.OST_CurtainWallPanels) { ApertureConstruction apertureConstruction = ToSAM_ApertureConstruction((FamilySymbol)element, convertSettings); if (apertureConstruction != null) { result = new List <Core.SAMObject>() { apertureConstruction } } ; } } else if (element is ModelCurve) { if (element.Category != null && (element.Category.Id.IntegerValue == (int)BuiltInCategory.OST_MEPSpaceSeparationLines || element.Category.Id.IntegerValue == (int)BuiltInCategory.OST_RoomSeparationLines)) { List <Panel> panels = ToSAM_Panels((ModelCurve)element, convertSettings); if (panels != null) { result = panels.ConvertAll(x => x as Core.SAMObject); } } } 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); }
protected override void TrySolveInstance(IGH_DataAccess dataAccess) { int index = -1; bool run = false; index = Params.IndexOfInputParam("_run"); if (index == -1 || !dataAccess.GetData(index, ref run) || !run) { return; } Document document = RhinoInside.Revit.Revit.ActiveDBDocument; if (document == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data"); return; } string name = null; index = Params.IndexOfInputParam("_name"); if (index == -1 || !dataAccess.GetData(index, ref name) || string.IsNullOrWhiteSpace(name)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data"); return; } bool inverted = false; index = Params.IndexOfInputParam("inverted_"); if (index == -1 || !dataAccess.GetData(index, ref inverted)) { inverted = false; } List <string> parameterNames = new List <string>(); index = Params.IndexOfInputParam("_parameterNames_"); if (index == -1 || !dataAccess.GetDataList(index, parameterNames) || parameterNames.Count == 0) { parameterNames = null; } Core.SAMObject sAMObject = null; index = Params.IndexOfInputParam("_analytical"); if (index == -1 || !dataAccess.GetData(index, ref sAMObject) || sAMObject == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data"); return; } StartTransaction(document); ElementType elementType = null; if (sAMObject is Panel) { Panel panel = (Panel)sAMObject; if (inverted) { elementType = Analytical.Revit.Modify.DuplicateByName(document, name, panel.PanelType, panel.Construction, parameterNames); } else { elementType = Analytical.Revit.Modify.DuplicateByName(document, panel.Construction, panel.PanelType, name, parameterNames); } } else if (sAMObject is ApertureConstruction) { ApertureConstruction apertureConstruction = (ApertureConstruction)sAMObject; if (inverted) { elementType = Analytical.Revit.Modify.DuplicateByName(document, name, apertureConstruction, parameterNames); } else { elementType = Analytical.Revit.Modify.DuplicateByName(document, apertureConstruction, name, parameterNames); } } else if (sAMObject is Construction) { Construction construction = (Construction)sAMObject; if (construction.TryGetValue(ConstructionParameter.DefaultPanelType, out string panelTypeString)) { PanelType panelType = Analytical.Query.PanelType(panelTypeString); if (panelType != PanelType.Undefined) { if (inverted) { elementType = Analytical.Revit.Modify.DuplicateByName(document, name, panelType, construction, parameterNames); } else { elementType = Analytical.Revit.Modify.DuplicateByName(document, construction, panelType, name, parameterNames); } } } } else if (sAMObject is Aperture) { ApertureConstruction apertureConstruction = ((Aperture)sAMObject).ApertureConstruction; if (inverted) { elementType = Analytical.Revit.Modify.DuplicateByName(document, name, apertureConstruction, parameterNames); } else { elementType = Analytical.Revit.Modify.DuplicateByName(document, apertureConstruction, name, parameterNames); } } index = Params.IndexOfOutputParam("elemenType"); if (index != -1) { dataAccess.SetData(index, elementType); } }
public static bool UpdateConstructions( this Document document, IEnumerable <Panel> panels, Core.DelimitedFileTable delimitedFileTable, ConstructionLibrary constructionLibrary, ApertureConstructionLibrary apertureConstructionLibrary, out List <Panel> panels_Result, out List <Aperture> apertures_Result, out List <ElementType> elementTypes_Panels, out List <ElementType> elementTypes_Apertures, out ConstructionLibrary constructionLibrary_Result, out ApertureConstructionLibrary apertureConstructionLibrary_Result, string sourceColumnName, string destinationColumnName, string templateColumnName, string typeColumnName, string thicknessColumnName = null) { panels_Result = null; apertures_Result = null; elementTypes_Panels = null; elementTypes_Apertures = null; constructionLibrary_Result = null; apertureConstructionLibrary_Result = null; if (document == null || panels == null || delimitedFileTable == null || constructionLibrary == null || apertureConstructionLibrary == null) { return(false); } int index_Source = delimitedFileTable.GetColumnIndex(sourceColumnName); if (index_Source == -1) { return(false); } int index_Template = delimitedFileTable.GetColumnIndex(templateColumnName); if (index_Template == -1) { return(false); } int index_Destination = delimitedFileTable.GetColumnIndex(destinationColumnName); if (index_Destination == -1) { return(false); } int index_Type = delimitedFileTable.GetColumnIndex(typeColumnName); if (index_Type == -1) { return(false); } panels_Result = new List <Panel>(); apertures_Result = new List <Aperture>(); elementTypes_Panels = new List <ElementType>(); elementTypes_Apertures = new List <ElementType>(); int index_Thickness = delimitedFileTable.GetColumnIndex(thicknessColumnName); constructionLibrary_Result = new ConstructionLibrary(constructionLibrary.Name); apertureConstructionLibrary_Result = new ApertureConstructionLibrary(apertureConstructionLibrary.Name); Core.Revit.ConvertSettings convertSettings = Core.Revit.Query.ConvertSettings(); foreach (Panel panel in panels) { Construction construction = panel?.Construction; if (construction == null) { continue; } string name = construction.Name; if (name == null) { continue; } string name_Destination = null; string name_Template = null; string name_Source = null; PanelType panelType = PanelType.Undefined; double thickness = double.NaN; for (int i = 0; i < delimitedFileTable.RowCount; i++) { string typeName = null; if (delimitedFileTable.TryConvert(i, index_Type, out typeName)) { ApertureType apertureType = Analytical.Query.ApertureType(typeName); if (apertureType != ApertureType.Undefined) { continue; } panelType = Analytical.Query.PanelType(typeName as object); } if (!delimitedFileTable.TryConvert(i, index_Source, out name_Source)) { continue; } if (!name.Equals(name_Source)) { continue; } if (!delimitedFileTable.TryConvert(i, index_Destination, out name_Destination)) { name_Destination = null; continue; } if (!delimitedFileTable.TryConvert(i, index_Template, out name_Template)) { name_Template = null; } if (index_Thickness != -1) { if (!delimitedFileTable.TryConvert(i, index_Thickness, out thickness)) { thickness = double.NaN; } } break; } if (string.IsNullOrWhiteSpace(name_Destination)) { name_Destination = name_Template; } if (string.IsNullOrWhiteSpace(name_Destination)) { continue; } if (panelType == PanelType.Undefined) { panelType = panel.PanelType; } Construction construction_New = constructionLibrary_Result.GetConstructions(name_Destination)?.FirstOrDefault(); if (construction_New == null) { Construction construction_Temp = constructionLibrary.GetConstructions(name_Template)?.FirstOrDefault(); if (construction_Temp == null) { continue; } if (name_Destination.Equals(name_Template)) { construction_New = construction_Temp; } else { construction_New = new Construction(construction_Temp, name_Destination); } construction_New.SetValue(ConstructionParameter.Description, construction.Name); construction_New.RemoveValue(ConstructionParameter.DefaultPanelType); if (!double.IsNaN(thickness)) { construction_New.SetValue(ConstructionParameter.DefaultThickness, thickness); } constructionLibrary_Result.Add(construction_New); } HostObjAttributes hostObjAttributes = Convert.ToRevit(construction_New, document, panelType, panel.Normal, convertSettings); if (hostObjAttributes == null) { if (string.IsNullOrWhiteSpace(name_Template)) { Construction construction_Default = Analytical.Query.DefaultConstruction(panelType); if (construction_Default != null) { name_Template = construction_Default.Name; } } if (string.IsNullOrWhiteSpace(name_Template)) { continue; } hostObjAttributes = DuplicateByType(document, name_Template, panelType, construction_New) as HostObjAttributes; } Construction construction_New_Temp = new Construction(hostObjAttributes.ToSAM(new Core.Revit.ConvertSettings(false, true, false)), construction_New.Guid); construction_New_Temp = new Construction(construction_New_Temp, construction_New.ConstructionLayers); constructionLibrary_Result.Add(construction_New_Temp); Panel panel_New = Analytical.Create.Panel(panel, construction_New_Temp); if (panel_New.PanelType != panelType) { panel_New = Analytical.Create.Panel(panel_New, panelType); } List <Aperture> apertures = panel_New.Apertures; if (apertures != null && apertures.Count != 0) { foreach (Aperture aperture in apertures) { panel_New.RemoveAperture(aperture.Guid); ApertureConstruction apertureConstruction = aperture?.ApertureConstruction; if (apertureConstruction == null) { continue; } name = apertureConstruction.Name; if (name == null) { continue; } name_Destination = null; name_Template = null; name_Source = null; ApertureType apertureType = ApertureType.Undefined; for (int i = 0; i < delimitedFileTable.RowCount; i++) { string typeName = null; if (!delimitedFileTable.TryGetValue(i, index_Type, out typeName) || string.IsNullOrWhiteSpace(typeName)) { continue; } apertureType = Analytical.Query.ApertureType(typeName); if (apertureType == ApertureType.Undefined) { if (typeName.Trim().Equals("Curtain Panels")) { apertureType = ApertureType.Window; } } if (apertureType == ApertureType.Undefined) { continue; } if (!delimitedFileTable.TryGetValue(i, index_Source, out name_Source) || string.IsNullOrWhiteSpace(name_Source)) { continue; } if (!name.Equals(name_Source)) { continue; } if (!delimitedFileTable.TryGetValue(i, index_Destination, out name_Destination)) { name_Destination = null; continue; } if (!delimitedFileTable.TryGetValue(i, index_Template, out name_Template)) { name_Template = null; } break; } if (string.IsNullOrWhiteSpace(name_Destination)) { name_Destination = name_Template; } if (string.IsNullOrWhiteSpace(name_Destination)) { continue; } if (apertureType == ApertureType.Undefined) { continue; } ApertureConstruction apertureConstruction_New = apertureConstructionLibrary_Result.GetApertureConstructions(name_Destination, Core.TextComparisonType.Equals, true, apertureType)?.FirstOrDefault(); if (apertureConstruction_New == null) { ApertureConstruction apertureConstruction_Temp = apertureConstructionLibrary.GetApertureConstructions(name_Template, Core.TextComparisonType.Equals, true, apertureType)?.FirstOrDefault(); if (apertureConstruction_Temp == null) { continue; } if (name_Destination.Equals(name_Template)) { apertureConstruction_New = apertureConstruction_Temp; } else { apertureConstruction_New = new ApertureConstruction(apertureConstruction_Temp, name_Destination); } apertureConstruction_New.SetValue(ApertureConstructionParameter.Description, apertureConstruction.Name); apertureConstructionLibrary_Result.Add(apertureConstruction_New); } FamilySymbol familySymbol = Convert.ToRevit(apertureConstruction_New, document, convertSettings); if (familySymbol == null) { if (string.IsNullOrWhiteSpace(name_Template)) { ApertureConstruction apertureConstruction_Default = Analytical.Query.DefaultApertureConstruction(panelType, apertureType); if (apertureConstruction_Default != null) { name_Template = apertureConstruction_Default.Name; } } if (string.IsNullOrWhiteSpace(name_Template)) { continue; } familySymbol = DuplicateByType(document, name_Template, apertureConstruction_New) as FamilySymbol; } Aperture aperture_New = new Aperture(aperture, apertureConstruction_New); if (panel_New.AddAperture(aperture_New)) { elementTypes_Apertures.Add(familySymbol); apertures_Result.Add(aperture_New); } } } elementTypes_Panels.Add(hostObjAttributes); panels_Result.Add(panel_New); } return(true); }
public static AnalyticalModel UpdateT3D(this AnalyticalModel analyticalModel, T3DDocument t3DDocument) { if (analyticalModel == null) { return(null); } Building building = t3DDocument?.Building; if (building == null) { return(null); } Modify.RemoveUnsusedZones(building); double northAngle = double.NaN; if (analyticalModel.TryGetValue(AnalyticalModelParameter.NorthAngle, out northAngle)) { building.northAngle = global::System.Math.Round(Units.Convert.ToDegrees(northAngle), 1); } Location location = analyticalModel.Location; if (location != null) { building.longitude = location.Longitude; building.latitude = location.Latitude; if (location.TryGetValue(LocationParameter.TimeZone, out string timeZone)) { double @double = Core.Query.Double(Core.Query.UTC(timeZone)); if (!double.IsNaN(@double)) { building.timeZone = global::System.Convert.ToSingle(@double); } } } AdjacencyCluster adjacencyCluster = analyticalModel?.AdjacencyCluster; if (adjacencyCluster != null) { //Zones -> Spaces Dictionary <string, Space> spaces = adjacencyCluster.SpaceDictionary(); if (spaces != null) { Dictionary <string, TAS3D.Zone> zones = building.ZoneDictionary(); if (zones != null) { foreach (KeyValuePair <string, TAS3D.Zone> keyValuePair in zones) { Space space; if (!spaces.TryGetValue(keyValuePair.Key, out space)) { continue; } if (space == null) { continue; } //TODO: Update Zone Space space_New = space.Clone(); space_New.Add(Create.ParameterSet(ActiveSetting.Setting, keyValuePair.Value)); adjacencyCluster.AddObject(space_New); } } } //Elements -> Constructions List <Construction> constructions = adjacencyCluster.GetConstructions(); if (constructions != null) { List <Element> elements = building.Elements(); if (elements != null) { foreach (Element element in elements) { Construction construction = element.Match(constructions); if (construction == null) { continue; } //Update Element //Thickness double thickness = construction.GetValue <double>(ConstructionParameter.DefaultThickness); if (double.IsNaN(thickness) || thickness == 0) { thickness = construction.GetThickness(); } if (!double.IsNaN(thickness)) { element.width = thickness; } //if (Core.Query.TryGetValue(construction, Analytical.Query.ParameterName_Thickness(), out thickness, true)) // element.width= thickness; //Colour System.Drawing.Color color = global::System.Drawing.Color.Empty; if (construction.TryGetValue(ConstructionParameter.Color, out color)) { element.colour = Core.Convert.ToUint(color); } //Transparent bool transparent = false; MaterialType materialType = Analytical.Query.MaterialType(construction.ConstructionLayers, analyticalModel.MaterialLibrary); if (materialType == MaterialType.Undefined) { materialType = MaterialType.Opaque; if (construction.TryGetValue(ConstructionParameter.Transparent, out transparent)) { element.transparent = transparent; } } else { element.transparent = materialType == MaterialType.Transparent; } //InternalShadows bool internalShadows = false; if (construction.TryGetValue(ConstructionParameter.IsInternalShadow, out internalShadows)) { element.internalShadows = internalShadows; } else { element.internalShadows = element.transparent; } //BEType string string_BEType = null; PanelType panelType = construction.PanelType(); if (panelType != Analytical.PanelType.Undefined) { string_BEType = panelType.Text(); } else { if (!construction.TryGetValue(ConstructionParameter.DefaultPanelType, out string_BEType)) { string_BEType = null; } } if (!string.IsNullOrEmpty(string_BEType)) { int bEType = BEType(string_BEType); if (bEType != -1) { element.BEType = bEType; panelType = PanelType(bEType); } } else { panelType = Analytical.PanelType.Undefined; List <Panel> panels_Construction = adjacencyCluster.GetPanels(construction); if (panels_Construction != null && panels_Construction.Count > 0) { Panel panel = panels_Construction.Find(x => x.PanelType != Analytical.PanelType.Undefined); if (panel != null) { panelType = panel.PanelType; } } } if (panelType == Analytical.PanelType.Undefined) { List <Panel> panels_Construction = adjacencyCluster.GetPanels(construction); if (panels_Construction != null && panels_Construction.Count != 0) { element.zoneFloorArea = panels_Construction.Find(x => x.PanelType.PanelGroup() == PanelGroup.Floor) != null; } } if (panelType.PanelGroup() == PanelGroup.Floor) { element.zoneFloorArea = true; } //Ground bool ground = false; if (construction.TryGetValue(ConstructionParameter.IsGround, out ground)) { element.ground = ground; } //Air bool air = false; if (construction.TryGetValue(ConstructionParameter.IsAir, out air)) { element.ghost = air; } List <Panel> panels = adjacencyCluster.GetPanels(construction); if (panels != null && panels.Count > 0) { ParameterSet parameterSet = Create.ParameterSet(ActiveSetting.Setting, element); construction.Add(parameterSet); foreach (Panel panel in panels) { Panel panel_New = Analytical.Create.Panel(panel, construction); adjacencyCluster.AddObject(panel_New); } } } } } //Windows -> ApertureConstruction List <ApertureConstruction> apertureConstructions = adjacencyCluster.GetApertureConstructions(); if (apertureConstructions != null) { List <window> windows = building.Windows(); if (windows != null) { foreach (window window in windows) { if (window == null) { continue; } ApertureConstruction apertureConstruction = window.Match(apertureConstructions); if (apertureConstruction == null) { continue; } //Colour System.Drawing.Color color = global::System.Drawing.Color.Empty; if (!apertureConstruction.TryGetValue(ApertureConstructionParameter.Color, out color)) { color = Analytical.Query.Color(apertureConstruction.ApertureType); } if (color != global::System.Drawing.Color.Empty) { window.colour = Core.Convert.ToUint(color); } //Transparent List <ConstructionLayer> constructionLayers = null; if (true) { constructionLayers = apertureConstruction.PaneConstructionLayers; } else { constructionLayers = apertureConstruction.FrameConstructionLayers; } window.transparent = false; //Requested by Michal 2021.03.01 bool transparent = false; MaterialType materialType = Analytical.Query.MaterialType(constructionLayers, analyticalModel.MaterialLibrary); if (materialType == MaterialType.Undefined) { materialType = MaterialType.Opaque; if (apertureConstruction.TryGetValue(ApertureConstructionParameter.Transparent, out transparent)) { window.transparent = transparent; } } else { window.transparent = materialType == MaterialType.Transparent; } if (window.transparent) { //InternalShadows window.internalShadows = false; //Requested by Michal 2021.03.01 bool internalShadows = false; if (apertureConstruction.TryGetValue(ApertureConstructionParameter.IsInternalShadow, out internalShadows)) { window.internalShadows = internalShadows; } else { List <Panel> panels = adjacencyCluster.GetPanels(apertureConstruction); if (panels != null && panels.Count != 0) { window.internalShadows = panels.TrueForAll(x => adjacencyCluster.External(x)); } } } //FrameWidth double frameWidth = double.NaN; if (apertureConstruction.TryGetValue(ApertureConstructionParameter.DefaultFrameWidth, out frameWidth)) { window.frameWidth = frameWidth; } } } } } AnalyticalModel result = new AnalyticalModel(analyticalModel, adjacencyCluster); return(result); }
public static IEnumerable <Core.SAMObject> ToSAM(this Element element, Core.Revit.ConvertSettings convertSettings) { IEnumerable <Core.SAMObject> result = null; if (element is Wall || element is Floor || element is RoofBase) { List <Panel> panels = ToSAM((HostObject)element, convertSettings); if (panels != null) { result = panels.Cast <Core.SAMObject>(); } } else if (element is HostObjAttributes) { Construction construction = ToSAM((HostObjAttributes)element, convertSettings); if (construction != null) { result = new List <Core.SAMObject>() { construction } } ; } else if (element is SpatialElement) { Space space = ToSAM((SpatialElement)element, convertSettings); if (space != null) { result = new List <Core.SAMObject>() { space } } ; } else if (element is FamilyInstance) { if (element.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Windows || element.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Doors) { FamilyInstance familyInstance = (FamilyInstance)element; Aperture aperture = ToSAM_Aperture(familyInstance, convertSettings); if (aperture != null) { result = new List <Core.SAMObject>() { aperture } } ; } } else if (element is FamilySymbol) { if (element.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Windows || element.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Doors) { ApertureConstruction apertureConstruction = ToSAM_ApertureConstruction((FamilySymbol)element, convertSettings); if (apertureConstruction != null) { result = new List <Core.SAMObject>() { apertureConstruction } } ; } } 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); }