public static Level ToSAM(this Autodesk.Revit.DB.Level level, Core.Revit.ConvertSettings convertSettings) { if (level == null) { return(null); } Document document = level.Document; Level result = convertSettings?.GetObject <Level>(level.Id); if (result != null) { return(result); } double elevation = Query.Elevation(level); result = new Level(level.Name, elevation); result.UpdateParameterSets(level, ActiveSetting.Setting.GetValue <Core.TypeMap>(ActiveSetting.Name.ParameterMap)); //result.Add(Core.Revit.Query.ParameterSet(level)); convertSettings?.Add(level.Id, result); return(result); }
public static List <Panel> Panels(this SpatialElement spatialElement, Core.Revit.ConvertSettings convertSettings) { if (spatialElement == null) { return(null); } SpatialElementBoundaryOptions spatialElementBoundaryOptions = new SpatialElementBoundaryOptions(); spatialElementBoundaryOptions.SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Center; spatialElementBoundaryOptions.StoreFreeBoundaryFaces = true; return(Panels(spatialElement, spatialElementBoundaryOptions, convertSettings)); }
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 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); }
public static IEnumerable <T> ToSAM <T>(this Document document, Core.Revit.ConvertSettings convertSettings, Transform transform = null) { IEnumerable <Core.SAMObject> sAMObjects = ToSAM(document, typeof(T), convertSettings, transform); if (sAMObjects == null) { return(null); } List <T> result = new List <T>(); foreach (Core.SAMObject sAMObject in sAMObjects) { if (sAMObject is T) { result.Add((T)(object)sAMObject); } } 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); }
public static IEnumerable <Space> ToSAM_Spaces(this RevitLinkInstance revitLinkInstance, Core.Revit.ConvertSettings convertSettings, bool fromRooms = true) { Document document_Source = revitLinkInstance.GetLinkDocument(); BuiltInCategory builtInCategory; if (fromRooms) { builtInCategory = BuiltInCategory.OST_Rooms; } else { builtInCategory = BuiltInCategory.OST_MEPSpaces; } IEnumerable <SpatialElement> spatialElements = new FilteredElementCollector(document_Source).OfCategory(builtInCategory).Cast <SpatialElement>(); List <Space> spaces = new List <Space>(); foreach (SpatialElement spatialElement in spatialElements) { Space space = ToSAM(spatialElement, convertSettings); if (space != null) { spaces.Add(space); } } return(spaces); }
public static HostObjAttributes ToRevit(this Construction construction, Document document, PanelType panelType, Geometry.Spatial.Vector3D normal, Core.Revit.ConvertSettings convertSettings) { if (construction == null && panelType == PanelType.Air && normal != null) { construction = Query.DefaultAirConstruction(normal.PanelType().PanelGroup()); } if (construction == null) { return(null); } HostObjAttributes result = null; if (panelType != PanelType.Shade) { result = convertSettings?.GetObject <HostObjAttributes>(construction.Guid); } else { List <HostObjAttributes> hostObjAttributes = convertSettings?.GetObjects <HostObjAttributes>(construction.Guid); if (hostObjAttributes != null && hostObjAttributes.Count != 0) { if (normal.PanelType().PanelGroup() == PanelGroup.Wall) { result = hostObjAttributes.Find(x => x is Autodesk.Revit.DB.WallType); } else { result = hostObjAttributes.Find(x => !(x is Autodesk.Revit.DB.WallType)); } } } if (result != null) { return(result); } FilteredElementCollector filteredElementCollector = Query.FilteredElementCollector(document, panelType)?.OfClass(typeof(HostObjAttributes)); if (filteredElementCollector == null) { return(null); } if (normal != null) { if (panelType == PanelType.Air || panelType == PanelType.Shade) { BuiltInCategory builtInCategory = normal.BuiltInCategory(); if (builtInCategory == BuiltInCategory.OST_Walls) { filteredElementCollector.OfCategory(builtInCategory); } } } //FilteredElementCollector filteredElementCollector = new FilteredElementCollector(document).OfClass(typeof(HostObjAttributes)); //BuiltInCategory builtInCategory = panelType.BuiltInCategory(); //if (normal != null && (builtInCategory == BuiltInCategory.INVALID || panelType == PanelType.Shade)) // builtInCategory = normal.BuiltInCategory(); //if (builtInCategory != BuiltInCategory.INVALID) // filteredElementCollector.OfCategory(builtInCategory); string familyName_Source = null; string typeName_Source = null; if (!Core.Revit.Query.TryGetFamilyNameAndTypeName(construction.Name, out familyName_Source, out typeName_Source)) { return(null); } foreach (HostObjAttributes hostObjAttributes in filteredElementCollector) { string fullName = Core.Revit.Query.FullName(hostObjAttributes); string familyName = null; string typeName = null; if (!Core.Revit.Query.TryGetFamilyNameAndTypeName(fullName, out familyName, out typeName)) { continue; } if (fullName != null && fullName.Equals(construction.Name)) { return(hostObjAttributes); } if (!string.IsNullOrWhiteSpace(familyName) && !string.IsNullOrWhiteSpace(familyName_Source)) { continue; } if (typeName.Equals(typeName_Source)) { result = hostObjAttributes; } } convertSettings?.Add(construction.Guid, result); return(result); }
public static List <Panel> Panels(this SpatialElement spatialElement, SpatialElementBoundaryOptions spatialElementBoundaryOptions, Core.Revit.ConvertSettings convertSettings) { if (spatialElement == null || spatialElementBoundaryOptions == null) { return(null); } SpatialElementGeometryCalculator spatialElementGeometryCalculator = new SpatialElementGeometryCalculator(spatialElement.Document, spatialElementBoundaryOptions); return(Panels(spatialElement, spatialElementGeometryCalculator, convertSettings)); }
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 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 IEnumerable <Core.SAMObject> ToSAM(this Document document, System.Type type, Core.Revit.ConvertSettings convertSettings, Transform transform = null, Phase phase = null) { if (document == null || type == null) { return(null); } if (transform == null) { transform = Transform.Identity; } FilteredElementCollector filteredElementCollector = Query.FilteredElementCollector(document, type); List <Element> elements = filteredElementCollector?.ToList(); if (elements == null) { return(null); } if (phase != null) { for (int i = elements.Count - 1; i >= 0; i--) { ElementOnPhaseStatus elementOnPhaseStatus = elements[i].GetPhaseStatus(phase.Id); if (elementOnPhaseStatus == ElementOnPhaseStatus.Past || elementOnPhaseStatus == ElementOnPhaseStatus.Demolished || elementOnPhaseStatus == ElementOnPhaseStatus.Future) { elements.RemoveAt(i); } } } List <Core.SAMObject> result = new List <Core.SAMObject>(); for (int i = 0; i < elements.Count; i++) { IEnumerable <Core.SAMObject> sAMObjects = ToSAM(elements[i], convertSettings); if (sAMObjects == null || sAMObjects.Count() == 0) { continue; } foreach (Core.SAMObject sAMObject in sAMObjects) { result.Add(sAMObject); } } ; if (transform != null && transform != Transform.Identity) { Parallel.For(0, result.Count, (int i) => { result[i] = Query.Transform(transform, result[i]); }); } return(result); }
public static IEnumerable <Core.SAMObject> ToSAM(this RevitLinkInstance revitLinkInstance, System.Type type, Core.Revit.ConvertSettings convertSettings) { Document document = null; try { document = revitLinkInstance.GetLinkDocument(); } catch { return(null); } if (document == null) { return(null); } Transform transform = revitLinkInstance.GetTotalTransform(); if (transform == null) { transform = Transform.Identity; } if (!transform.IsIdentity) { transform = transform.Inverse; } return(ToSAM(document, type, convertSettings, transform)); }
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 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 Panel ToSAM(this EnergyAnalysisSurface energyAnalysisSurface, Core.Revit.ConvertSettings convertSettings, Shell shell = null, double silverSpacing = Core.Tolerance.MacroDistance, double tolerance = Core.Tolerance.Distance) { if (energyAnalysisSurface == null) { return(null); } Panel result = convertSettings?.GetObject <Panel>(energyAnalysisSurface.Id); if (result != null) { return(result); } Document document = energyAnalysisSurface.Document; Polygon3D polygon3D = energyAnalysisSurface.GetPolyloop().ToSAM(); if (polygon3D == null) { return(null); } if (shell != null) { Geometry.Spatial.Plane plane = polygon3D.GetPlane(); if (plane != null) { Point3D point3D = polygon3D.InternalPoint3D(); if (point3D != null) { Vector3D normal = shell.Normal(polygon3D.InternalPoint3D(), true, silverSpacing, tolerance); if (!normal.SameHalf(plane.AxisZ)) { plane.FlipZ(); polygon3D = new Polygon3D(plane, polygon3D.GetPoints().ConvertAll(x => plane.Convert(x))); } } } } HostObject hostObject = Core.Revit.Query.Element(document, energyAnalysisSurface.CADObjectUniqueId, energyAnalysisSurface.CADLinkUniqueId) as HostObject; if (hostObject == null) { return(new Panel(null, PanelType.Air, new Face3D(polygon3D))); } ElementId elementId_Type = hostObject.GetTypeId(); if (elementId_Type == null || elementId_Type == ElementId.InvalidElementId) { return(null); } PanelType panelType = Query.PanelType(hostObject); Construction construction = ((HostObjAttributes)hostObject.Document.GetElement(elementId_Type)).ToSAM(convertSettings); if (construction == null) { construction = Analytical.Query.DefaultConstruction(panelType); //Default Construction } PanelType panelType_Temp = Query.PanelType(construction); if (panelType_Temp != PanelType.Undefined) { panelType = panelType_Temp; } Face3D face3D = new Face3D(polygon3D); result = new Panel(construction, panelType, face3D); IEnumerable <EnergyAnalysisOpening> energyAnalysisOpenings = energyAnalysisSurface.GetAnalyticalOpenings(); if (energyAnalysisOpenings != null && energyAnalysisOpenings.Count() != 0) { foreach (EnergyAnalysisOpening energyAnalysisOpening in energyAnalysisOpenings) { Aperture aperture = energyAnalysisOpening.ToSAM(convertSettings); if (aperture != null) { result.AddAperture(aperture); } } } result.UpdateParameterSets(energyAnalysisSurface, ActiveSetting.Setting.GetValue <Core.TypeMap>(Core.Revit.ActiveSetting.Name.ParameterMap)); convertSettings?.Add(energyAnalysisSurface.Id, result); return(result); }
public static FamilyInstance ToRevit(this Aperture aperture, Document document, Core.Revit.ConvertSettings convertSettings) { if (aperture == null || document == null) { return(null); } HostObject hostObject = Query.HostObject(aperture, document); if (hostObject == null) { return(null); } return(ToRevit(aperture, document, hostObject, convertSettings)); }
public static IEnumerable <T> ToSAM <T>(this RevitLinkInstance revitLinkInstance, Core.Revit.ConvertSettings convertSettings) where T : Core.SAMObject { return(ToSAM(revitLinkInstance, typeof(T), convertSettings)?.Cast <T>()); }
public static HostObject ToRevit(this Panel panel, Document document, Core.Revit.ConvertSettings convertSettings) { Geometry.Spatial.Face3D face3D = panel?.GetFace3D(); if (face3D == null) { return(null); } HostObject result = convertSettings?.GetObject <HostObject>(panel.Guid); if (result != null) { return(result); } PanelType panelType = panel.PanelType; Geometry.Spatial.Vector3D normal = panel.Normal; HostObjAttributes hostObjAttributes = panel.Construction.ToRevit(document, panelType, normal, convertSettings); if (hostObjAttributes == null) { hostObjAttributes = Analytical.Query.DefaultConstruction(panelType)?.ToRevit(document, panelType, normal, convertSettings); //Default Construction } BuiltInParameter[] builtInParameters = null; if (hostObjAttributes is Autodesk.Revit.DB.WallType) { double lowElevation = panel.LowElevation(); Level level = document.LowLevel(lowElevation); Autodesk.Revit.DB.Wall wall = ToRevit_Wall(face3D, document, (Autodesk.Revit.DB.WallType)hostObjAttributes, level); if (wall == null) { return(result); } //List<Curve> curveList = new List<Curve>(); //foreach (Geometry.Spatial.IClosedPlanar3D closedPlanar3D in face3D.GetEdge3Ds()) //{ // if (Geometry.Spatial.Query.Clockwise(closedPlanar3D)) // closedPlanar3D.Reverse(); // List<Line> lines = closedPlanar3D.ToRevit(); // if (lines == null) // continue; // curveList.AddRange(lines); //} //if (curveList == null || curveList.Count == 0) // return null; //double lowElevation = panel.LowElevation(); //Level level = document.LowLevel(lowElevation); //if (level == null) // return null; //Wall wall = Wall.Create(document, curveList, hostObjAttributes.Id, level.Id, false, panel.Normal.ToRevit(false)); Parameter parameter = null; parameter = wall.get_Parameter(BuiltInParameter.WALL_HEIGHT_TYPE); if (parameter != null) { parameter.Set(ElementId.InvalidElementId); } parameter = wall.get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM); if (parameter != null) { #if Revit2017 || Revit2018 || Revit2019 || Revit2020 double height = UnitUtils.ConvertToInternalUnits((panel.HighElevation() - lowElevation), DisplayUnitType.DUT_METERS); #else double height = UnitUtils.ConvertToInternalUnits((panel.HighElevation() - lowElevation), UnitTypeId.Meters); #endif parameter.Set(height); } #if Revit2017 || Revit2018 || Revit2019 || Revit2020 double levelElevation = UnitUtils.ConvertFromInternalUnits(level.Elevation, DisplayUnitType.DUT_METERS); #else double levelElevation = UnitUtils.ConvertFromInternalUnits(level.Elevation, UnitTypeId.Meters); #endif if (Math.Abs(lowElevation - levelElevation) > Core.Tolerance.MacroDistance) { parameter = wall.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET); if (parameter != null) { #if Revit2017 || Revit2018 || Revit2019 || Revit2020 parameter.Set(UnitUtils.ConvertToInternalUnits(lowElevation - levelElevation, DisplayUnitType.DUT_METERS)); #else parameter.Set(UnitUtils.ConvertToInternalUnits(lowElevation - levelElevation, UnitTypeId.Meters)); #endif } } builtInParameters = new BuiltInParameter[] { BuiltInParameter.WALL_BASE_CONSTRAINT, BuiltInParameter.WALL_BASE_OFFSET, BuiltInParameter.WALL_HEIGHT_TYPE, BuiltInParameter.WALL_USER_HEIGHT_PARAM, BuiltInParameter.WALL_KEY_REF_PARAM }; result = wall; } else if (hostObjAttributes is Autodesk.Revit.DB.FloorType) { Geometry.Spatial.IClosedPlanar3D closedPlanar3D_External = face3D.GetExternalEdge3D(); if (!(closedPlanar3D_External is Geometry.Spatial.ICurvable3D)) { return(null); } double elevation = panel.LowElevation(); Level level = document.HighLevel(elevation); Geometry.Spatial.Plane plane = new Geometry.Spatial.Plane(new Geometry.Spatial.Point3D(0, 0, elevation), Geometry.Spatial.Vector3D.WorldZ); CurveArray curveArray_Sloped = new CurveArray(); CurveArray curveArray_Plane = new CurveArray(); Geometry.Spatial.IClosedPlanar3D closedPlanar3D = face3D.GetExternalEdge3D(); if (!(closedPlanar3D is Geometry.Spatial.ICurvable3D)) { return(null); } List <Geometry.Spatial.Segment3D> segment3Ds = Geometry.Revit.Query.Segment3Ds(closedPlanar3D); if (segment3Ds == null || segment3Ds.Count == 0) { return(null); } foreach (Geometry.Spatial.Segment3D segment3D in segment3Ds) { curveArray_Sloped.Append(segment3D.ToRevit_Line()); Geometry.Spatial.Segment3D segment3D_Temp = Geometry.Spatial.Query.Project(plane, segment3D); if (segment3D_Temp == null) { continue; } curveArray_Plane.Append(segment3D_Temp.ToRevit_Line()); } #if Revit2017 || Revit2018 || Revit2019 || Revit2020 || Revit2021 Autodesk.Revit.DB.Floor floor = document.Create.NewFloor(curveArray_Plane, hostObjAttributes as Autodesk.Revit.DB.FloorType, level, false); #else CurveLoop curveLoop = new CurveLoop(); foreach (Curve curve in curveArray_Plane) { curveLoop.Append(curve); } Autodesk.Revit.DB.Floor floor = Autodesk.Revit.DB.Floor.Create(document, new CurveLoop[] { curveLoop }, hostObjAttributes.Id, level.Id); #endif if (floor != null) { floor.ChangeTypeId(hostObjAttributes.Id); List <Geometry.Spatial.IClosedPlanar3D> closedPlanar3Ds_Internal = face3D.GetInternalEdge3Ds(); if (closedPlanar3Ds_Internal != null && closedPlanar3Ds_Internal.Count > 0) { //Requires to be regenerated before inserting openings //https://thebuildingcoder.typepad.com/blog/2013/07/create-a-floor-with-an-opening-or-complex-boundary.html document.Regenerate(); foreach (Geometry.Spatial.IClosedPlanar3D closedPlanar3D_Internal in face3D.GetInternalEdge3Ds()) { List <Geometry.Spatial.Segment3D> segment3Ds_Internal = Geometry.Revit.Query.Segment3Ds(closedPlanar3D_Internal); if (segment3Ds_Internal == null || segment3Ds_Internal.Count == 0) { continue; } curveArray_Plane = new CurveArray(); //foreach (Geometry.Spatial.Segment3D segment3D in segment3Ds) foreach (Geometry.Spatial.Segment3D segment3D in segment3Ds_Internal) { curveArray_Sloped.Append(segment3D.ToRevit_Line()); Geometry.Spatial.Segment3D segment3D_Temp = Geometry.Spatial.Query.Project(plane, segment3D); if (segment3D_Temp == null) { continue; } curveArray_Plane.Append(segment3D_Temp.ToRevit_Line()); } Opening opening = document.Create.NewOpening(floor, curveArray_Plane, true); } } } if (floor != null) { document.Regenerate(); SlabShapeEditor slabShapeEditor = floor.SlabShapeEditor; if (slabShapeEditor != null) { slabShapeEditor.ResetSlabShape(); foreach (Curve curve in curveArray_Sloped) { XYZ xYZ = curve.GetEndPoint(0); slabShapeEditor.DrawPoint(xYZ); } } } builtInParameters = new BuiltInParameter[] { BuiltInParameter.LEVEL_PARAM }; result = floor; } else if (hostObjAttributes is Autodesk.Revit.DB.RoofType) { CurveArray curveArray = new CurveArray(); foreach (Geometry.Spatial.IClosedPlanar3D closedPlanar3D in face3D.GetEdge3Ds()) { List <Geometry.Spatial.Segment3D> segment3Ds = Geometry.Revit.Query.Segment3Ds(closedPlanar3D); if (segment3Ds == null || segment3Ds.Count == 0) { return(null); } segment3Ds.ForEach(x => curveArray.Append(x.ToRevit_Line())); } Level level = document.HighLevel(panel.LowElevation()); double levelElevation = level.Elevation; ModelCurveArray modelCurveArray = new ModelCurveArray(); RoofBase roofBase = document.Create.NewFootPrintRoof(curveArray, level, hostObjAttributes as Autodesk.Revit.DB.RoofType, out modelCurveArray); Parameter parameter = roofBase.get_Parameter(BuiltInParameter.ROOF_UPTO_LEVEL_PARAM); if (parameter != null) { parameter.Set(ElementId.InvalidElementId); } SlabShapeEditor slabShapeEditor = roofBase.SlabShapeEditor; if (slabShapeEditor != null) { slabShapeEditor.ResetSlabShape(); foreach (Curve curve in curveArray) { XYZ xYZ = curve.GetEndPoint(0); //if (Math.Abs(xYZ.Z - levelElevation) > Core.Tolerance.MicroDistance) slabShapeEditor.DrawPoint(xYZ); } } builtInParameters = new BuiltInParameter[] { BuiltInParameter.ROOF_LEVEL_OFFSET_PARAM, BuiltInParameter.ROOF_BASE_LEVEL_PARAM, BuiltInParameter.ROOF_UPTO_LEVEL_PARAM }; result = roofBase; } if (result == null) { return(null); } List <Aperture> apertures = panel.Apertures; if (apertures != null) { if (result is Autodesk.Revit.DB.Wall && ((Autodesk.Revit.DB.Wall)result).WallType.Kind == WallKind.Curtain) { } else { foreach (Aperture aperture in apertures) { Geometry.Spatial.Plane plane_Aperture = aperture?.PlanarBoundary3D?.Plane; if (plane_Aperture == null) { continue; } //bool flipHand = !plane_Panel.AxisX.SameHalf(plane_Aperture.AxisX); //bool flipFacing = !plane_Panel.Normal.SameHalf(plane_Aperture.Normal); FamilyInstance failyInstance_Aperture = aperture.ToRevit(document, result, convertSettings); } } } if (convertSettings.ConvertParameters) { Core.Revit.Modify.SetValues(result, panel, builtInParameters); Core.Revit.Modify.SetValues(result, panel, ActiveSetting.Setting); Core.Revit.Modify.SetJson(result, panel.ToJObject()?.ToString()); } //TODO: Implement proper log //System.IO.File.AppendAllText(@"C:\Users\DengusiakM\Desktop\SAM\2020-04-16 floorbug\LOG.txt", string.Format("{0}\t{1}\t{2}\n", DateTime.Now.ToString(), panel.Guid, panel.Name)); convertSettings?.Add(panel.Guid, result); return(result); }
public static HostObjAttributes ToRevit(this HostPartitionType hostPartitionType, Document document, Core.Revit.ConvertSettings convertSettings) { if (hostPartitionType == null) { return(null); } HostObjAttributes result = null; List <HostObjAttributes> hostObjAttributesList = convertSettings?.GetObjects <HostObjAttributes>(hostPartitionType.Guid); if (hostObjAttributesList != null) { if (hostPartitionType is WallType) { result = hostObjAttributesList.Find(x => x is Autodesk.Revit.DB.WallType); } else if (hostPartitionType is FloorType) { result = hostObjAttributesList.Find(x => x is Autodesk.Revit.DB.FloorType); } else if (hostPartitionType is RoofType) { result = hostObjAttributesList.Find(x => x is Autodesk.Revit.DB.RoofType); } } if (result != null) { return(result); } FilteredElementCollector filteredElementCollector = Query.FilteredElementCollector_New(document, hostPartitionType.GetType())?.OfClass(typeof(HostObjAttributes)); if (filteredElementCollector == null) { return(null); } string familyName_Source = null; string typeName_Source = null; if (!Core.Revit.Query.TryGetFamilyNameAndTypeName(hostPartitionType.Name, out familyName_Source, out typeName_Source)) { return(null); } foreach (HostObjAttributes hostObjAttributes in filteredElementCollector) { string fullName = Core.Revit.Query.FullName(hostObjAttributes); string familyName = null; string typeName = null; if (!Core.Revit.Query.TryGetFamilyNameAndTypeName(fullName, out familyName, out typeName)) { continue; } if (fullName != null && fullName.Equals(hostPartitionType.Name)) { result = hostObjAttributes; break; } if (!string.IsNullOrWhiteSpace(familyName) && !string.IsNullOrWhiteSpace(familyName_Source)) { continue; } if (typeName.Equals(typeName_Source)) { result = hostObjAttributes; } } if (result == null) { return(result); } List <Architectural.MaterialLayer> materialLayers = hostPartitionType.MaterialLayers; if (materialLayers != null && materialLayers.Count != 0) { CompoundStructure compoundStructure = result.GetCompoundStructure(); if (compoundStructure != null) { List <Material> materials = new FilteredElementCollector(document).OfClass(typeof(Material)).Cast <Material>().ToList(); List <CompoundStructureLayer> compoundStructureLayers = new List <CompoundStructureLayer>(); foreach (Architectural.MaterialLayer materialLayer in materialLayers) { Material material = materials.Find(x => x.Name == materialLayer.Name); if (material == null) { continue; } double width = double.NaN; #if Revit2017 || Revit2018 || Revit2019 || Revit2020 width = UnitUtils.ConvertToInternalUnits(materialLayer.Thickness, DisplayUnitType.DUT_METERS); #else width = UnitUtils.ConvertToInternalUnits(materialLayer.Thickness, UnitTypeId.Meters); #endif CompoundStructureLayer compoundStructureLayer = new CompoundStructureLayer(width, MaterialFunctionAssignment.Structure, material.Id); if (compoundStructureLayer == null) { continue; } compoundStructureLayers.Add(compoundStructureLayer); } if (compoundStructureLayers != null && compoundStructureLayers.Count != 0) { compoundStructure.SetLayers(compoundStructureLayers); result.SetCompoundStructure(compoundStructure); } } } if (convertSettings.ConvertParameters) { Core.Revit.Modify.SetValues(result, hostPartitionType); Core.Revit.Modify.SetValues(result, hostPartitionType, ActiveSetting.Setting); } convertSettings?.Add(hostPartitionType.Guid, result); return(result); }
/// <summary> /// Gets Wall Panels from Spatial Element base on its Boundary /// </summary> /// <param name="spatialElement">Revit Spatial Element such as Space or Room</param> /// <param name="elevation_Bottom">Bottom Elevation</param> /// <param name="elevation_Top">Top Elevation</param> /// <param name="convertSettings">Convert Settings</param> /// <param name="spatialElementBoundaryOptions">Revit SpactialElementBoundaryOptions. Center Spatial Element Boundary Location will be used when set to null</param> /// <returns>Wall Panels</returns> public static List <Panel> Panels(this SpatialElement spatialElement, double elevation_Bottom, double elevation_Top, Core.Revit.ConvertSettings convertSettings, SpatialElementBoundaryOptions spatialElementBoundaryOptions = null) { if (spatialElement == null || double.IsNaN(elevation_Top) || double.IsNaN(elevation_Bottom)) { return(null); } if (spatialElementBoundaryOptions == null) { spatialElementBoundaryOptions = new SpatialElementBoundaryOptions(); spatialElementBoundaryOptions.SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Center; } Document document = spatialElement.Document; Geometry.Spatial.Plane plane = Geometry.Spatial.Plane.WorldXY; Geometry.Spatial.Plane plane_Top = plane.GetMoved(new Geometry.Spatial.Vector3D(0, 0, elevation_Top)) as Geometry.Spatial.Plane; Geometry.Spatial.Plane plane_Bottom = plane.GetMoved(new Geometry.Spatial.Vector3D(0, 0, elevation_Bottom)) as Geometry.Spatial.Plane; List <Panel> panels = new List <Panel>(); IList <IList <BoundarySegment> > boundaries = spatialElement.GetBoundarySegments(spatialElementBoundaryOptions); foreach (IList <BoundarySegment> boundarySegments in boundaries) { if (boundarySegments == null) { continue; } foreach (BoundarySegment boundarySegment in boundarySegments) { if (boundarySegment == null) { continue; } Curve curve = boundarySegment.GetCurve(); if (curve == null) { continue; } HostObject hostObject = null; if (boundarySegment.ElementId != null && boundarySegment.ElementId != ElementId.InvalidElementId) { if (boundarySegment.LinkElementId == null || boundarySegment.LinkElementId == ElementId.InvalidElementId) { hostObject = document.GetElement(boundarySegment.ElementId) as HostObject; } else { RevitLinkInstance revitLinkInstance = document.GetElement(boundarySegment.LinkElementId) as RevitLinkInstance; if (revitLinkInstance != null) { Document document_Linked = revitLinkInstance.GetLinkDocument(); if (document_Linked != null) { hostObject = document_Linked.GetElement(boundarySegment.ElementId) as HostObject; } } } } Panel panel_Temp = null; if (hostObject != null) { List <Panel> panels_Temp = hostObject.ToSAM(convertSettings); if (panels_Temp != null && panels_Temp.Count > 0) { panel_Temp = panels_Temp[0]; } } List <Geometry.Spatial.Segment3D> segment3Ds = Geometry.Revit.Convert.ToSAM_Segment3Ds(curve); if (segment3Ds == null || segment3Ds.Count == 0) { continue; } foreach (Geometry.Spatial.Segment3D segment3D in segment3Ds) { Geometry.Spatial.Segment3D segment3D_Top = Geometry.Spatial.Query.Project(plane_Top, segment3D); Geometry.Spatial.Segment3D segment3D_Bottom = Geometry.Spatial.Query.Project(plane_Bottom, segment3D); Geometry.Spatial.Polygon3D polygon3D = Geometry.Spatial.Create.Polygon3D(new Geometry.Spatial.Point3D[] { segment3D_Top[0], segment3D_Top[1], segment3D_Bottom[1], segment3D_Bottom[0] }); if (polygon3D == null) { continue; } Geometry.Spatial.Face3D face3D = new Geometry.Spatial.Face3D(polygon3D); Panel panel = null; if (panel_Temp != null) { panel = Analytical.Create.Panel(Guid.NewGuid(), panel_Temp, face3D); } if (panel_Temp != null) { Geometry.Spatial.Vector3D normal = polygon3D.GetPlane()?.Normal; PanelType panelType = Analytical.Query.PanelType(normal); Construction construction = Query.DefaultAirConstruction(panelType.PanelGroup()); panel = Analytical.Create.Panel(construction, panelType, face3D); } if (panel != null) { panels.Add(panel); } } } } return(panels); }
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 List <Panel> Panels(this SpatialElement spatialElement, SpatialElementGeometryCalculator spatialElementGeometryCalculator, Core.Revit.ConvertSettings convertSettings) { if (spatialElement == null || spatialElementGeometryCalculator == null) { return(null); } SpatialElementGeometryResults spatialElementGeometryResults = spatialElementGeometryCalculator.CalculateSpatialElementGeometry(spatialElement); if (spatialElementGeometryResults == null) { return(null); } Solid solid = spatialElementGeometryResults.GetGeometry(); if (solid == null) { return(null); } List <Tuple <Face, LinkElementId, SubfaceType> > tuples = new List <Tuple <Face, LinkElementId, SubfaceType> >(); foreach (Face face in solid.Faces) { IList <SpatialElementBoundarySubface> spatialElementBoundarySubfaces = spatialElementGeometryResults.GetBoundaryFaceInfo(face); if (spatialElementBoundarySubfaces == null || spatialElementBoundarySubfaces.Count == 0) { tuples.Add(new Tuple <Face, LinkElementId, SubfaceType>(face, null, SubfaceType.Side)); continue; } foreach (SpatialElementBoundarySubface spatialElementBoundarySubface in spatialElementBoundarySubfaces) { if (spatialElementBoundarySubface == null) { continue; } Face face_Subface = spatialElementBoundarySubface.GetSubface(); //Face face_Subface = spatialElementBoundarySubface.GetSpatialElementFace(); LinkElementId linkElementId = spatialElementBoundarySubface.SpatialBoundaryElement; tuples.Add(new Tuple <Face, LinkElementId, SubfaceType>(face_Subface, linkElementId, spatialElementBoundarySubface.SubfaceType)); } } List <Panel> result = new List <Panel>(); foreach (Tuple <Face, LinkElementId, SubfaceType> tuple in tuples) { List <Geometry.Spatial.Face3D> face3Ds = Geometry.Revit.Convert.ToSAM(tuple.Item1); if (face3Ds == null || face3Ds.Count == 0) { continue; } foreach (Geometry.Spatial.Face3D face3D in face3Ds) { PanelType panelType = PanelType.Undefined; Construction construction = null; Panel panel = null; if (tuple.Item2 != null) { Element element = Core.Revit.Query.Element(spatialElement.Document, tuple.Item2); if (element != null) { HostObject hostObject = element as HostObject; if (hostObject != null) { List <Panel> panels = hostObject.ToSAM(convertSettings); if (panels != null && panels.Count > 0) { panel = panels[0]; } if (panel != null) { construction = panel.Construction; panelType = Analytical.Query.PanelType(construction?.Name); if (panelType == PanelType.Undefined) { panelType = panel.PanelType; } } if (panelType == PanelType.Undefined) { panelType = Query.PanelType(hostObject); } if (construction == null) { ElementId elementId_Type = hostObject.GetTypeId(); if (elementId_Type != null && elementId_Type != ElementId.InvalidElementId) { construction = ((HostObjAttributes)hostObject.Document.GetElement(elementId_Type)).ToSAM(convertSettings); } } } } } if (panelType == PanelType.Undefined) { panelType = Analytical.Query.PanelType(face3D.GetPlane()?.Normal); } if (panelType == PanelType.Undefined) { switch (tuple.Item3) { case SubfaceType.Bottom: panelType = PanelType.Floor; break; case SubfaceType.Top: panelType = PanelType.Roof; break; case SubfaceType.Side: panelType = PanelType.Wall; break; } } if (construction == null) { construction = Analytical.Query.DefaultConstruction(panelType); //Default Construction } if (panel == null) { panel = Analytical.Create.Panel(construction, panelType, face3D); } else { panel = Analytical.Create.Panel(panel.Guid, panel, face3D); } result.Add(panel); } } return(result); }
public static ApertureConstruction ToSAM_ApertureConstruction(this FamilySymbol familySymbol, Core.Revit.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 HostObjAttributes ToRevit_HostObjAttributes(this Panel panel, Document document, Core.Revit.ConvertSettings convertSettings) { if (panel == null || document == null) { return(null); } return(ToRevit(panel.Construction, document, panel.PanelType, panel.Normal, convertSettings)); }
public static ApertureConstruction ToSAM_ApertureConstruction(this FamilyInstance familyInstance, Core.Revit.ConvertSettings convertSettings) { if (familyInstance == null) { return(null); } FamilySymbol familySymbol = familyInstance.Document.GetElement(familyInstance.GetTypeId()) as FamilySymbol; if (familySymbol == null) { return(null); } return(ToSAM_ApertureConstruction(familySymbol, convertSettings)); }
public static Aperture ToSAM(this EnergyAnalysisOpening energyAnalysisOpening, Core.Revit.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.IJSAMObject <Aperture>(familyInstance); if (result != null) { return(result); } } ApertureConstruction apertureConstruction = ToSAM_ApertureConstruction(familyInstance, convertSettings); Point3D point3D_Location = Geometry.Revit.Query.Location(familyInstance); if (point3D_Location == null) { return(null); } result = new Aperture(apertureConstruction, polygon3D, point3D_Location); 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); }
protected override void TrySolveInstance(IGH_DataAccess dataAccess) { bool run = false; if (!dataAccess.GetData(9, ref run)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data"); dataAccess.SetData(3, false); return; } if (!run) { return; } Document document = RhinoInside.Revit.Revit.ActiveDBDocument; if (document == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data"); return; } List <Panel> panels = new List <Panel>(); if (!dataAccess.GetDataList(0, panels)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data"); return; } ConstructionLibrary constructionLibrary = null; dataAccess.GetData(1, ref constructionLibrary); if (constructionLibrary == null) { constructionLibrary = ActiveSetting.Setting.GetValue <ConstructionLibrary>(AnalyticalSettingParameter.DefaultConstructionLibrary); } ApertureConstructionLibrary apertureConstructionLibrary = null; dataAccess.GetData(2, ref apertureConstructionLibrary); if (apertureConstructionLibrary == null) { apertureConstructionLibrary = ActiveSetting.Setting.GetValue <ApertureConstructionLibrary>(AnalyticalSettingParameter.DefaultApertureConstructionLibrary); } string csvOrPath = null; if (!dataAccess.GetData(3, ref csvOrPath) || string.IsNullOrWhiteSpace(csvOrPath)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data"); return; } string sourceColumn = null; if (!dataAccess.GetData(4, ref sourceColumn) || string.IsNullOrWhiteSpace(sourceColumn)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data"); return; } string templateColumn = null; if (!dataAccess.GetData(5, ref templateColumn) || string.IsNullOrWhiteSpace(templateColumn)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data"); return; } string destinationColumn = null; if (!dataAccess.GetData(6, ref destinationColumn) || string.IsNullOrWhiteSpace(destinationColumn)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data"); return; } string typeColumn = null; if (!dataAccess.GetData(7, ref typeColumn) || string.IsNullOrWhiteSpace(typeColumn)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data"); return; } string thicknessColumn = null; dataAccess.GetData(8, ref thicknessColumn); Core.DelimitedFileTable delimitedFileTable = null; if (Core.Query.ValidFilePath(csvOrPath)) { delimitedFileTable = new Core.DelimitedFileTable(new Core.DelimitedFileReader(Core.DelimitedFileType.Csv, csvOrPath)); } else { string[] lines = csvOrPath.Split('\n'); delimitedFileTable = new Core.DelimitedFileTable(new Core.DelimitedFileReader(Core.DelimitedFileType.Csv, lines)); } if (delimitedFileTable == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data"); return; } int index_Source = delimitedFileTable.GetColumnIndex(sourceColumn); if (index_Source == -1) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data"); return; } int index_Template = delimitedFileTable.GetColumnIndex(templateColumn); if (index_Template == -1) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data"); return; } int index_Destination = delimitedFileTable.GetColumnIndex(destinationColumn); if (index_Destination == -1) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data"); return; } int index_Type = delimitedFileTable.GetColumnIndex(typeColumn); if (index_Type == -1) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data"); return; } int index_Thickness = -1; if (!string.IsNullOrWhiteSpace(thicknessColumn)) { index_Thickness = delimitedFileTable.GetColumnIndex(thicknessColumn); } Core.Revit.ConvertSettings convertSettings = null; if (convertSettings == null) { convertSettings = Core.Revit.Query.ConvertSettings(); } ConstructionLibrary constructionLibrary_Result = new ConstructionLibrary(constructionLibrary.Name); ApertureConstructionLibrary apertureConstructionLibrary_Result = new ApertureConstructionLibrary(apertureConstructionLibrary.Name); List <Panel> panels_Result = new List <Panel>(); List <Aperture> apertures_Result = new List <Aperture>(); List <ElementType> elementTypes_Panels = new List <ElementType>(); List <ElementType> elementTypes_Apertures = new List <ElementType>(); foreach (Panel panel in panels) { Construction construction = panel?.Construction; if (construction == null) { continue; } string name = construction.Name; if (name == null) { //result.Add(construction); 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.TryGetValue(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.TryGetValue(i, index_Source, out 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; } 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); //construction_New.SetValue(ConstructionParameter.DefaultPanelType, panelType.Text()); if (!double.IsNaN(thickness)) { construction_New.SetValue(ConstructionParameter.DefaultThickness, thickness); } constructionLibrary_Result.Add(construction_New); } HostObjAttributes hostObjAttributes = Analytical.Revit.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 = Analytical.Revit.Modify.DuplicateByType(document, name_Template, panelType, construction_New) as HostObjAttributes; if (hostObjAttributes == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, string.Format("Skipped - Could not duplicate construction for panel ({2}). Element Type Name for: {0}, could not be assinged from {1}", name, name_Template, panel.PanelType)); continue; } } Panel panel_New = new Panel(panel, construction_New); if (panel_New.PanelType != panelType) { panel_New = new 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)) { continue; } apertureType = Analytical.Query.ApertureType(typeName); if (apertureType == ApertureType.Undefined) { continue; } if (!delimitedFileTable.TryGetValue(i, index_Source, out 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 = Analytical.Revit.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 = Analytical.Revit.Modify.DuplicateByType(document, name_Template, apertureConstruction_New) as FamilySymbol; if (familySymbol == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, string.Format("Skipped - Could not duplicate construction for panel ({2}). Element Type Name for: {0}, could not be assinged from {1}", name, name_Template, panel.PanelType)); continue; } } 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); } dataAccess.SetDataList(0, elementTypes_Panels); dataAccess.SetDataList(1, elementTypes_Apertures); dataAccess.SetDataList(2, panels_Result.ConvertAll(x => new GooPanel(x))); dataAccess.SetDataList(3, apertures_Result.ConvertAll(x => new GooAperture(x))); dataAccess.SetData(4, new GooConstructionLibrary(constructionLibrary_Result)); dataAccess.SetData(5, new GooApertureConstructionLibrary(apertureConstructionLibrary_Result)); }