/***************************************************/ public static Bar ToBHoMObject(IHorizBrace ramHorizBrace, ILayoutHorizBrace ramLayoutHorizBrace, double dElevation) { string sectionName = ramHorizBrace.strSectionLabel; ISectionProperty sectionProperty = ToBHoMSection(ramHorizBrace); // Get the start and end pts of every brace double StartSupportX = new double(); double StartSupportY = new double(); double StartSupportZOffset = new double(); double EndSupportX = new double(); double EndSupportY = new double(); double EndSupportZOffset = new double(); double StoryZ = dElevation; // Get coordinates from ILayout Brace ramLayoutHorizBrace.GetLayoutCoordinates(out StartSupportX, out StartSupportY, out StartSupportZOffset, out EndSupportX, out EndSupportY, out EndSupportZOffset); Node startNode = new Node { Position = new oM.Geometry.Point() { X = StartSupportX.FromInch(), Y = StartSupportY.FromInch(), Z = StoryZ.FromInch() + StartSupportZOffset.FromInch() } }; Node endNode = new Node { Position = new oM.Geometry.Point() { X = EndSupportX.FromInch(), Y = EndSupportY.FromInch(), Z = StoryZ.FromInch() + EndSupportZOffset.FromInch() } }; Bar bhomBar = new Bar { StartNode = startNode, EndNode = endNode, SectionProperty = sectionProperty, Name = sectionName }; bhomBar.OrientationAngle = 0; // Unique RAM ID RAMId RAMId = new RAMId(); RAMId.Id = ramLayoutHorizBrace.lUID; bhomBar.SetAdapterId(RAMId); //Add Frame Data fragment RAMFrameData ramFrameData = new RAMFrameData(); ramFrameData.FrameNumber = ramLayoutHorizBrace.lLabel; ramFrameData.Material = ramLayoutHorizBrace.eMaterial.ToString(); bhomBar.Fragments.Add(ramFrameData); bhomBar.Tags.Add("HorizontalBrace"); return(bhomBar); }
/***************************************************/ public static IStory GetStory(this Bar bar, StructuralUsage1D usage1D, IStories ramStories) { double elev; switch (usage1D) { case StructuralUsage1D.Beam: //Use lowest end elevation elev = Math.Min(bar.StartNode.Position.Z, bar.EndNode.Position.Z).ToInch(); break; case StructuralUsage1D.Column: // Get RAM column data bool isHanging = false; RAMFrameData ramFrameData = bar.FindFragment <RAMFrameData>(typeof(RAMFrameData)); if (ramFrameData != null) { isHanging = ramFrameData.IsHangingColumn; } if (isHanging.Equals("True") || isHanging.Equals("1")) //Hanging Column to be placed on its btm level. { elev = Math.Min(bar.StartNode.Position.Z, bar.EndNode.Position.Z).ToInch(); } else //Column to be placed on the level it supports. { elev = Math.Max(bar.StartNode.Position.Z, bar.EndNode.Position.Z).ToInch(); } break; default: //Use lowest end elevation elev = Math.Min(bar.StartNode.Position.Z, bar.EndNode.Position.Z).ToInch(); break; } //There must be a better way to iterate over IStories List <IStory> storeys = new List <IStory>(); int numStories = ramStories.GetCount(); for (int i = 0; i < numStories; i++) { storeys.Add(ramStories.GetAt(i)); } return(storeys.OrderBy(x => Math.Abs(x.dElevation - elev)).First()); }
/***************************************************/ public static Bar ToBHoMObject(this IVerticalBrace ramVerticalBrace) { // Get the column name string sectionName = ramVerticalBrace.strSectionLabel; ISectionProperty sectionProperty = ToBHoMSection(ramVerticalBrace); // Get the start and end pts of every column SCoordinate startPt = new SCoordinate(); SCoordinate endPt = new SCoordinate(); ramVerticalBrace.GetEndCoordinates(ref startPt, ref endPt); Node startNode = new Node { Position = startPt.PointFromRAM() }; Node endNode = new Node { Position = endPt.PointFromRAM() }; Bar bhomBar = new Bar { StartNode = startNode, EndNode = endNode, SectionProperty = sectionProperty, Name = sectionName }; bhomBar.OrientationAngle = 0; // Unique RAM ID RAMId RAMId = new RAMId(); RAMId.Id = ramVerticalBrace.lUID; bhomBar.SetAdapterId(RAMId); //Add Frame Data fragment RAMFrameData ramFrameData = new RAMFrameData(); ramFrameData.FrameNumber = ramVerticalBrace.lLabel; ramFrameData.FrameType = ramVerticalBrace.eSeismicFrameType.ToString(); ramFrameData.Material = ramVerticalBrace.eMaterial.ToString(); bhomBar.Fragments.Add(ramFrameData); bhomBar.Tags.Add("VerticalBrace"); return(bhomBar); }
/***************************************************/ /**** Private methods ****/ /***************************************************/ private List <Bar> ReadBars(List <string> ids = null) { //Implement code for reading bars List <Bar> bhomBars = new List <Bar>(); // Get stories IStories IStories = m_Model.GetStories(); int numStories = IStories.GetCount(); // Get all elements on each story for (int i = 0; i < numStories; i++) { //Get Columns IColumns IColumns = IStories.GetAt(i).GetColumns(); int numColumns = IColumns.GetCount(); //Get Beams IFloorType IFloorType = IStories.GetAt(i).GetFloorType(); ILayoutBeams ILayoutBeams = IFloorType.GetLayoutBeams(); IBeams IBeams = IStories.GetAt(i).GetBeams(); int numLayoutBeams = ILayoutBeams.GetCount(); int numBeams = IBeams.GetCount(); //Get Vertical Braces IVerticalBraces IVBraces = IStories.GetAt(i).GetVerticalBraces(); int numVBraces = IVBraces.GetCount(); //Get Horizontal Braces ILayoutHorizBraces ILayoutHorizBraces = IStories.GetAt(i).GetFloorType().GetLayoutHorizBraces(); IHorizBraces IHorizBraces = IStories.GetAt(i).GetHorizBraces(); int numHBraces = ILayoutHorizBraces.GetCount(); //Get Elevation double dElevation = IStories.GetAt(i).dElevation; // Convert Columns for (int j = 0; j < numColumns; j++) { IColumn IColumn = IColumns.GetAt(j); Bar bhomBar = BH.Adapter.RAM.Convert.ToBHoMObject(IColumn); RAMFrameData ramFrameData = bhomBar.FindFragment <RAMFrameData>(typeof(RAMFrameData)); if (ramFrameData != null) { ramFrameData.FloorType = IFloorType.strLabel; bhomBar.Fragments.AddOrReplace(ramFrameData); } bhomBars.Add(bhomBar); } // Convert Beams for (int j = 0; j < numBeams; j++) { IBeam IBeam = IBeams.GetAt(j); ILayoutBeam ILayoutBeam = ILayoutBeams.GetAt(j); Bar bhomBar = BH.Adapter.RAM.Convert.ToBHoMObject(IBeam, ILayoutBeam, dElevation); RAMFrameData ramFrameData = bhomBar.FindFragment <RAMFrameData>(typeof(RAMFrameData)); if (ramFrameData != null) { ramFrameData.FloorType = IFloorType.strLabel; bhomBar.Fragments.AddOrReplace(ramFrameData); } bhomBars.Add(bhomBar); } // Convert Vertical Braces for (int j = 0; j < numVBraces; j++) { IVerticalBrace IVerticalBrace = IVBraces.GetAt(j); Bar bhomBar = BH.Adapter.RAM.Convert.ToBHoMObject(IVerticalBrace); RAMFrameData ramFrameData = bhomBar.FindFragment <RAMFrameData>(typeof(RAMFrameData)); if (ramFrameData != null) { ramFrameData.FloorType = IFloorType.strLabel; bhomBar.Fragments.AddOrReplace(ramFrameData); } bhomBars.Add(bhomBar); } // Convert Horizontal Braces for (int j = 0; j < numHBraces; j++) { IHorizBrace IHorizBrace = IHorizBraces.GetAt(j); ILayoutHorizBrace ILayoutHorizBrace = ILayoutHorizBraces.GetAt(j); Bar bhomBar = BH.Adapter.RAM.Convert.ToBHoMObject(IHorizBrace, ILayoutHorizBrace, dElevation); RAMFrameData ramFrameData = bhomBar.FindFragment <RAMFrameData>(typeof(RAMFrameData)); if (ramFrameData != null) { ramFrameData.FloorType = IFloorType.strLabel; bhomBar.Fragments.AddOrReplace(ramFrameData); } bhomBars.Add(bhomBar); } } return(bhomBars); }
/***************************************************/ /**** Private methods ****/ /***************************************************/ private bool CreateCollection(IEnumerable <Bar> bhomBars) { //Code for creating a collection of bars in the software List <Bar> bars = bhomBars.ToList(); //Get the stories in the model IStories ramStories = m_Model.GetStories(); //Cycle through bars, split to beam and col lists, then add to corresponding story. List <Bar> barBeams = new List <Bar>(); List <Bar> barCols = new List <Bar>(); foreach (Bar testBar in bars) { bool isBeam = Math.Abs(testBar.Tangent(true).DotProduct(Vector.ZAxis)) < 0.5; if (isBeam) { barBeams.Add(testBar); } else { barCols.Add(testBar); } } //Create beams per story, flat foreach (Bar bar in barBeams) { string name = bar.Name; ILayoutBeam ramBeam; try { RAMId RAMId = new RAMId(); IStory barStory = bar.GetStory(StructuralUsage1D.Beam, ramStories); IFloorType ramFloorType = barStory.GetFloorType(); ILayoutBeams ramBeams = ramFloorType.GetLayoutBeams(); double zStart = bar.StartNode.Position.Z.ToInch() - barStory.dElevation; double zEnd = bar.EndNode.Position.Z.ToInch() - barStory.dElevation; // Get beam fragment cantilever data double startCant = 0; double endCant = 0; bool isStubCant = false; RAMFrameData ramFrameData = bar.FindFragment <RAMFrameData>(typeof(RAMFrameData)); if (ramFrameData != null) { startCant = ramFrameData.StartCantilever; endCant = ramFrameData.EndCantilever; isStubCant = ramFrameData.IsStubCantilever; } if (isStubCant.Equals("True") || isStubCant.Equals("1")) //Check bool per RAM or GH preferred boolean context { SCoordinate startPt, endPt; if (startCant > 0) // Ensure startPt corresponds with support point { startPt = bar.EndNode.Position.ToRAM(); endPt = bar.StartNode.Position.ToRAM(); } else { startPt = bar.StartNode.Position.ToRAM(); endPt = bar.EndNode.Position.ToRAM(); } ramBeam = ramBeams.AddStubCantilever(bar.SectionProperty.Material.ToRAM(), startPt.dXLoc, startPt.dYLoc, 0, endPt.dXLoc, endPt.dYLoc, 0); // No Z offsets, beams flat on closest story } else { // Get support points Vector barDir = bar.Tangent(true); Point startSupPt = BH.Engine.Geometry.Modify.Translate(bar.StartNode.Position, barDir * startCant); Point endSupPt = BH.Engine.Geometry.Modify.Translate(bar.EndNode.Position, -barDir * endCant); SCoordinate start = startSupPt.ToRAM(); SCoordinate end = endSupPt.ToRAM(); ramBeam = ramBeams.Add(bar.SectionProperty.Material.ToRAM(), start.dXLoc, start.dYLoc, 0, end.dXLoc, end.dYLoc, 0); // No Z offsets, beams flat on closest story if (startSupPt.X < endSupPt.X || (startSupPt.X == endSupPt.X && startSupPt.Y > endSupPt.Y)) { ramBeam.dStartCantilever = startCant.FromInch(); ramBeam.dEndCantilever = endCant.FromInch(); } else { ramBeam.dStartCantilever = endCant.FromInch(); ramBeam.dEndCantilever = startCant.FromInch(); } } // Add warning to report distance of snapping to level as required for RAM if (zStart != 0 || zEnd != 0) { Engine.Base.Compute.RecordWarning("Bar " + name + " snapped to level " + barStory.strLabel + ". Bar moved " + Math.Round(zStart, 2).ToString() + " inches at start and " + Math.Round(zEnd, 2).ToString() + " inches at end."); } IBeams beamsOnStory = barStory.GetBeams(); IBeam beam = beamsOnStory.Get(ramBeam.lUID); beam.strSectionLabel = bar.SectionProperty.Name; // beam.EAnalyzeFlag = EAnalyzeFlag.eAnalyze; deprecated in API RAMId.Id = beam.lUID; bar.SetAdapterId(RAMId); } catch { CreateElementError("bar", name); } } //Create columns at each story with offset per actual height foreach (Bar bar in barCols) { string name = bar.Name; try { RAMId RAMId = new RAMId(); IStory barStory = bar.GetStory(StructuralUsage1D.Column, ramStories); List <Node> colNodes = new List <Node>() { bar.StartNode, bar.EndNode }; colNodes.Sort((x, y) => x.Position.Z.CompareTo(y.Position.Z)); double xBtm = colNodes[0].Position.X.ToInch(); double yBtm = colNodes[0].Position.Y.ToInch(); double zBtm = colNodes[0].Position.Z.ToInch() - barStory.dElevation; double xTop = colNodes[1].Position.X.ToInch(); double yTop = colNodes[1].Position.Y.ToInch(); double zTop = colNodes[1].Position.Z.ToInch() - barStory.dElevation + barStory.dFlrHeight; IFloorType ramFloorType = barStory.GetFloorType(); ILayoutColumns ramColumns = ramFloorType.GetLayoutColumns(); ILayoutColumn ramColumn; // Get RAM column data bool isHanging = false; RAMFrameData ramFrameData = bar.FindFragment <RAMFrameData>(typeof(RAMFrameData)); if (ramFrameData != null) { isHanging = ramFrameData.IsHangingColumn; } if (isHanging.Equals("True") || isHanging.Equals("1")) //Check bool per RAM or GH preferred boolean context { ramColumn = ramColumns.Add3(bar.SectionProperty.Material.ToRAM(), xBtm, yBtm, xTop, yTop, 0, 0, 1); //No Z offsets, cols start and end at stories } else if (bar.IsVertical()) { //Failing if no section property is provided ramColumn = ramColumns.Add(bar.SectionProperty.Material.ToRAM(), xTop, yTop, 0, 0); //No Z offsets, cols start and end at stories } else { ramColumn = ramColumns.Add2(bar.SectionProperty.Material.ToRAM(), xTop, yTop, xBtm, yBtm, 0, 0); //No Z offsets, cols start and end at stories } //Set column properties IColumns colsOnStory = barStory.GetColumns(); IColumn column = colsOnStory.Get(ramColumn.lUID); column.strSectionLabel = bar.SectionProperty.Name; column.EAnalyzeFlag = EAnalyzeFlag.eAnalyze; RAMId.Id = column.lUID; bar.SetAdapterId(RAMId); } catch { CreateElementError("bar", name); } } //Save file m_IDBIO.SaveDatabase(); return(true); }
/***************************************************/ public static Bar ToBHoMObject(this IBeam ramBeam, ILayoutBeam ramLayoutBeam, double dElevation) { // Get coordinates from IBeam SCoordinate startPt = new SCoordinate(); SCoordinate endPt = new SCoordinate(); ramBeam.GetCoordinates(EBeamCoordLoc.eBeamEnds, ref startPt, ref endPt); Node startNode = new Node { Position = startPt.PointFromRAM() }; Node endNode = new Node { Position = endPt.PointFromRAM() }; //Assign section property per bar string sectionName = ramBeam.strSectionLabel; ISectionProperty sectionProperty = ToBHoMSection(ramBeam); // Create bars with section properties Bar bhomBar = new Bar { StartNode = startNode, EndNode = endNode, SectionProperty = sectionProperty, Name = sectionName }; // Set Properties bhomBar.OrientationAngle = 0; // Unique RAM ID RAMId RAMId = new RAMId(); RAMId.Id = ramBeam.lUID; bhomBar.SetAdapterId(RAMId); RAMFrameData ramFrameData = new RAMFrameData(); ramFrameData.FrameNumber = ramBeam.lLabel; ramFrameData.StartCantilever = ramBeam.dStartCantilever.FromInch(); ramFrameData.EndCantilever = ramBeam.dEndCantilever.FromInch(); ramFrameData.IsStubCantilever = (ramLayoutBeam.IsStubCantilever() == 1); ramFrameData.FrameType = ramBeam.eFramingType.ToString(); ramFrameData.Material = ramBeam.eMaterial.ToString(); bhomBar.Tags.Add("Beam"); // Get Steel beam results ISteelBeamDesignResult Result = ramBeam.GetSteelDesignResult(); DAArray ppalNumStuds = Result.GetNumStudsInSegments(); int numStudSegments = new int(); ppalNumStuds.GetSize(ref numStudSegments); double camber = ramBeam.dCamber; int studCount = 0; IAnalyticalResult AnalyticalResult = ramBeam.GetAnalyticalResult(); COMBO_MATERIAL_TYPE Steel_Grav = COMBO_MATERIAL_TYPE.GRAV_STEEL; IMemberForces IMemberForces = AnalyticalResult.GetMaximumComboReactions(Steel_Grav); //Add studs to custom Data by total stud count only for (int i = 0; i < numStudSegments; i++) { var segStudCount = new object(); ppalNumStuds.GetAt(i, ref segStudCount); string segStudStr = segStudCount.ToString(); int segStudNum = System.Convert.ToInt16(segStudStr); studCount += segStudNum; ramFrameData.Studs = studCount; } // Add camber to Custom Data if (camber > Double.MinValue) { ramFrameData.Camber = camber.FromInch(); } // Translate RAM Releases to BHoM Releases (in progress; logic not yet complete since it is difficult map Maj/Min axes to global XYZ axes for every member) // May be better to just do in custom data, although if we can do this mapping it may be useful bhomBar.Release = new BarRelease(); bhomBar.Release.StartRelease = new Constraint6DOF(); bhomBar.Release.EndRelease = new Constraint6DOF(); bhomBar.Release.StartRelease.RotationX = new DOFType(); bhomBar.Release.EndRelease.RotationX = new DOFType(); bhomBar.Release.StartRelease.RotationY = new DOFType(); bhomBar.Release.EndRelease.RotationY = new DOFType(); if (ramBeam.bMajAxisBendFixedStart == 1) { bhomBar.Release.StartRelease.RotationX = DOFType.Fixed; } else { bhomBar.Release.StartRelease.RotationX = DOFType.Free; } if (ramBeam.bMajAxisBendFixedEnd == 1) { bhomBar.Release.EndRelease.RotationX = DOFType.Fixed; } else { bhomBar.Release.EndRelease.RotationX = DOFType.Free; } if (ramBeam.bMinAxisBendFixedStart == 1) { bhomBar.Release.StartRelease.RotationY = DOFType.Fixed; } else { bhomBar.Release.StartRelease.RotationY = DOFType.Free; } if (ramBeam.bMinAxisBendFixedEnd == 1) { bhomBar.Release.EndRelease.RotationY = DOFType.Fixed; } else { bhomBar.Release.EndRelease.RotationY = DOFType.Free; } double DCI = Result.dDesignCapacityInteraction; double CDI = Result.dCriticalDeflectionInteraction; // Add DCI and CDI data ramFrameData.DesignCapacityInteraction = DCI; ramFrameData.CriticalDeflectionInteraction = CDI; bhomBar.Fragments.Add(ramFrameData); return(bhomBar); }
/***************************************************/ public static Bar ToBHoMObject(this IColumn ramColumn) { // Get the column name string section = ramColumn.strSectionLabel; // Get the start and end pts of every column SCoordinate startPt = new SCoordinate(); SCoordinate endPt = new SCoordinate(); ramColumn.GetEndCoordinates(ref startPt, ref endPt); Node startNode = new Node { Position = startPt.PointFromRAM() }; Node endNode = new Node { Position = endPt.PointFromRAM() }; //Assign section property per bar string sectionName = ramColumn.strSectionLabel; ISectionProperty sectionProperty = ToBHoMSection(ramColumn); // Create bars with section properties Bar bhomBar = new Bar { StartNode = startNode, EndNode = endNode, SectionProperty = sectionProperty, Name = sectionName }; // Translate RAM Releases to BHoM Releases (in progress; logic not yet complete since it is difficult map Maj/Min axes to global XYZ axes for every member) // May be better to just do in custom data, although if we can do this mapping it may be useful bhomBar.Release = new BarRelease(); bhomBar.Release.StartRelease = new Constraint6DOF(); bhomBar.Release.EndRelease = new Constraint6DOF(); bhomBar.Release.StartRelease.RotationX = new DOFType(); bhomBar.Release.EndRelease.RotationX = new DOFType(); bhomBar.Release.StartRelease.RotationY = new DOFType(); bhomBar.Release.EndRelease.RotationY = new DOFType(); if (ramColumn.bMajAxisBendFixedTop == 1) { bhomBar.Release.StartRelease.RotationX = DOFType.Fixed; } else { bhomBar.Release.StartRelease.RotationX = DOFType.Free; } if (ramColumn.bMajAxisBendFixedBot == 1) { bhomBar.Release.EndRelease.RotationX = DOFType.Fixed; } else { bhomBar.Release.EndRelease.RotationX = DOFType.Free; } if (ramColumn.bMinAxisBendFixedTop == 1) { bhomBar.Release.StartRelease.RotationY = DOFType.Fixed; } else { bhomBar.Release.StartRelease.RotationY = DOFType.Free; } if (ramColumn.bMinAxisBendFixedBot == 1) { bhomBar.Release.EndRelease.RotationY = DOFType.Fixed; } else { bhomBar.Release.EndRelease.RotationY = DOFType.Free; } bhomBar.OrientationAngle = 0; // Add RAM Unique ID, custom Data RAMId RAMId = new RAMId(); RAMId.Id = ramColumn.lUID; bhomBar.SetAdapterId(RAMId); //Add Frame Data fragment RAMFrameData ramFrameData = new RAMFrameData(); ramFrameData.FrameNumber = ramColumn.lLabel; ramFrameData.FrameType = ramColumn.eFramingType.ToString(); ramFrameData.Material = ramColumn.eMaterial.ToString(); ramFrameData.IsHangingColumn = (ramColumn.bHanger == 1); bhomBar.Fragments.Add(ramFrameData); bhomBar.Tags.Add("Column"); return(bhomBar); }