/***************************************************/ /**** Private methods ****/ /***************************************************/ private bool CreateCollection(IEnumerable <Bar> bars) { if (bars.Count() > 0) { int barIdNum = 0; int lineIdNum = 0; List <Bar> barList = bars.ToList(); rf.Member[] rfBars = new rf.Member[barList.Count()]; for (int i = 0; i < bars.Count(); i++) { barIdNum = GetAdapterId <int>(barList[i]); //create line lineIdNum = modelData.GetLineCount() + 1; rf.Line centreLine = new rf.Line(); int startNodeId = GetAdapterId <int>(barList[i].StartNode); int endNodeId = GetAdapterId <int>(barList[i].EndNode); centreLine.NodeList = String.Join(",", new int[] { startNodeId, endNodeId }); centreLine.Type = rf.LineType.PolylineType; modelData.SetLine(centreLine); rfBars[i] = barList[i].ToRFEM(barIdNum, lineIdNum); modelData.SetMember(rfBars[i]); } //modelData.SetMembers(rfBars); } return(true); }
//Gets all the members in the model and bakes them as breps to the rhino. public static Tuple <Member[], Dlubal.RFEM5.CrossSection[]> GetMembers(string comment) { OpenConnection(); try { IModelData rData = RModel.GetModelData(); Dlubal.RFEM5.Line[] lines = rData.GetLines(); Dlubal.RFEM5.CrossSection[] crossSecs = rData.GetCrossSections(); Member[] members = rData.GetMembers(); members = members.Where(o => o.Comment == comment).ToArray(); List <Member> mList = new List <Member>(); Dictionary <int, Brep> rCrossSecs = new Dictionary <int, Brep>(); foreach (Dlubal.RFEM5.CrossSection crossSec in crossSecs) { rCrossSecs.Add(crossSec.No, GetCrscDBShape(crossSec.TextID)); } foreach (Member member in members) { Dlubal.RFEM5.Line line = rData.GetLine(member.LineNo, ItemAt.AtNo).GetData(); Rhino.Geometry.Line rhLine = lineRfemToRhino(line, rData); Vector3d direction = new Vector3d(rhLine.To - rhLine.From); Plane plane = new Plane(rhLine.From, direction); Brep tempCross = (Brep)rCrossSecs[member.StartCrossSectionNo].Duplicate(); Transform tr = Transform.PlaneToPlane(Plane.WorldXY, plane); tempCross.Transform(tr); Brep extruded = tempCross.Faces[0].CreateExtrusion(rhLine.ToNurbsCurve(), true); ProjectPlugIn.Instance.beamBreps.Add(Tuple.Create(member.No, extruded)); } foreach (Member m in members) { Dlubal.RFEM5.CrossSection c = Array.Find(crossSecs, o => o.No == m.StartCrossSectionNo); if (c.TextID.Split(' ')[0] == "Rechteck" || c.TextID.Split(' ')[0] == "Kreis") { mList.Add(m); } } CloseConnection(); return(Tuple.Create(mList.ToArray(), crossSecs)); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.Source, MessageBoxButtons.OK, MessageBoxIcon.Error); //Cleans Garbage collector for releasing all COM interfaces and objects System.GC.Collect(); System.GC.WaitForPendingFinalizers(); CloseConnection(); } return(Tuple.Create <Member[], Dlubal.RFEM5.CrossSection[]>(null, null)); }
private static Rhino.Geometry.Line lineRfemToRhino(Dlubal.RFEM5.Line line, IModelData rData) { Point3D point1 = line.ControlPoints[0]; Point3D point2 = line.ControlPoints[line.ControlPoints.Length - 1]; Rhino.Geometry.Line rhLine = new Rhino.Geometry.Line(new Point3d(point1.X, point1.Y, point1.Z), new Point3d(point2.X, point2.Y, point2.Z)); return(rhLine); }
/***************************************************/ /**** Private methods ****/ /***************************************************/ private bool CreateCollection(IEnumerable <RigidLink> links) { if (links.Count() > 0) { int linkIdNum = 0; int lineIdNum = 0; List <RigidLink> linkList = links.ToList(); rf.Member[] rfLinks = new rf.Member[linkList.Count()]; for (int i = 0; i < links.Count(); i++) { linkIdNum = GetAdapterId <int>(linkList[i]); //check for multiple secondary nodes if (linkList[i].SecondaryNodes.Count > 1) { Engine.Base.Compute.RecordWarning("Multiple secondary nodes detected! Link no. " + linkIdNum + " was created using only the first secondary node!"); } //create line lineIdNum = modelData.GetLineCount() + 1; rf.Line centreLine = new rf.Line(); int startNodeId = GetAdapterId <int>(linkList[i].PrimaryNode); int endNodeId = GetAdapterId <int>(linkList[i].SecondaryNodes[0]); centreLine.NodeList = String.Join(",", new int[] { startNodeId, endNodeId }); centreLine.Type = rf.LineType.PolylineType; modelData.SetLine(centreLine); rf.Member rfLink = new rf.Member(); rfLink.No = linkIdNum; rfLink.LineNo = lineIdNum; rfLink.Type = rf.MemberType.Rigid; LinkConstraint lc = linkList[0].Constraint; if (lc != null) { if (lc.XtoX != true || lc.YtoY != true || lc.ZtoZ != true || lc.XXtoXX != true || lc.YYtoYY != true || lc.ZZtoZZ != true) { Engine.Base.Compute.RecordWarning("Hinges on RigidLinks are not supported. Member no. " + linkIdNum + " created as fixed!"); } } modelData.SetMember(rfLink); } //modelData.SetMembers(rfBars); } return(true); }
/***************************************************/ /**** Private methods ****/ /***************************************************/ private bool CreateCollection(IEnumerable <Edge> edges) { if (edges.Count() > 0) { int edgeIdNum = 0; List <Edge> edgeList = edges.ToList(); rf.Line[] rfLines = new rf.Line[edgeList.Count()]; for (int i = 0; i < edges.Count(); i++) { edgeIdNum = GetAdapterId <int>(edgeList[i]); //create rfem nodes, i.e. bhom points Line edgeAsLine = edgeList[i].Curve as Line; rf.Node rfNode1 = new rf.Node(); rfNode1.No = (int)this.NextFreeId(typeof(Node)); rfNode1.X = edgeAsLine.Start.X; rfNode1.Y = edgeAsLine.Start.Y; rfNode1.Z = edgeAsLine.Start.Z; modelData.SetNode(rfNode1); rf.Node rfNode2 = new rf.Node(); int nodeId1 = (int)this.NextFreeId(typeof(Node)); rfNode2.X = edgeAsLine.End.X; rfNode2.Y = edgeAsLine.End.Y; rfNode2.Z = edgeAsLine.End.Z; modelData.SetNode(rfNode1); //create line rf.Line centreLine = new rf.Line(); centreLine.No = edgeIdNum; centreLine.NodeList = String.Join(",", new int[] { rfNode1.No, rfNode2.No }); centreLine.Type = rf.LineType.PolylineType; modelData.SetLine(centreLine); } //modelData.SetMembers(rfBars); } return(true); }
//This method creates a rhino line from the start and end point of the underlying line of the //rfem member. private Rhino.Geometry.Line getMemberLine(IModelData data, int number, ItemAt itemAt) { Member test = data.GetMember(number, itemAt).GetData(); int lineNo = data.GetMember(number, itemAt).GetData().LineNo; Dlubal.RFEM5.Line line = data.GetLine(lineNo, itemAt).GetData(); int[] nodes = Array.ConvertAll(line.NodeList.Split(','), s => int.Parse(s)); nodes = new int[] { nodes[0], nodes[nodes.Length - 1] }; Node nodeStart = data.GetNode(nodes[0], itemAt).GetData(); Node nodeEnd = data.GetNode(nodes[1], itemAt).GetData(); return(new Rhino.Geometry.Line(new Point3d(nodeStart.X, nodeStart.Y, nodeStart.Z), new Point3d(nodeEnd.X, nodeEnd.Y, nodeEnd.Z))); }
/***************************************************/ /**** Public Methods ****/ /***************************************************/ public static Bar FromRFEM(this rf.Member member, rf.Line line, ISectionProperty sectionProperty) { rf.Point3D sPt = line.ControlPoints.First(); rf.Point3D ePt = line.ControlPoints.Last(); BH.oM.Geometry.Line ln = new oM.Geometry.Line() { Start = new oM.Geometry.Point() { X = sPt.X, Y = sPt.Y, Z = sPt.Z }, End = new oM.Geometry.Point() { X = ePt.X, Y = ePt.Y, Z = ePt.Z } }; Bar bhBar = BH.Engine.Structure.Create.Bar(ln, sectionProperty, member.Rotation.Angle); bhBar.SetAdapterId(typeof(RFEMId), member.No); return(bhBar); }
public RFLine(Dlubal.RFEM5.Line line, Point3d[] controlPoints) { Comment = line.Comment; ID = line.ID; IsGenerated = line.IsGenerated; IsValid = line.IsValid; No = line.No; Tag = line.Tag; Length = line.Length; NodeCount = line.NodeCount; NodeList = line.NodeList; RotationAngle = line.Rotation.Angle; RotationHelpNodeNo = line.Rotation.HelpNodeNo; RotationPlane = line.Rotation.Plane; RotationType = line.Rotation.Type; Type = line.Type; ControlPoints = controlPoints; Order = 2; ToModify = false; ToDelete = false; }
//TODO this method is not ready yet!!! //this method turns karamba beams into RFEM members private static Tuple <Member[], Dlubal.RFEM5.Line[]> Members(List <Karamba.Elements.ModelElement> kElems) { List <Member> rMembers = new List <Member>(); List <Dlubal.RFEM5.Line> rLines = new List <Dlubal.RFEM5.Line>(); foreach (Karamba.Elements.ModelElement kElem in kElems) { if (typeof(Karamba.Elements.ModelBeam) == kElem.GetType()) { Karamba.Elements.ModelBeam kBeam = kElem as Karamba.Elements.ModelBeam; //Creating RFEM line Dlubal.RFEM5.Line rLine = new Dlubal.RFEM5.Line(); rLine.No = kBeam.ind + 1; rLine.NodeList = (kBeam._node_inds[0] + 1).ToString() + "," + (kBeam._node_inds[kBeam._node_inds.Count - 1] + 1).ToString(); rLines.Add(rLine); //Creating RFEM member Member rMember = new Member(); rMember.LineNo = rLine.No; int ind; if (!string.IsNullOrEmpty(kBeam.id) && int.TryParse(kBeam.id.Substring(1), out ind)) { rMember.No = ind; } else { rMember.No = kBeam.ind + 1; } rMember.EndCrossSectionNo = (int)kBeam.crossection.ind + 1; rMember.StartCrossSectionNo = rMember.EndCrossSectionNo; //member hinges if (kBeam.joint != null) { //member start if (Array.FindIndex(kBeam.joint.props, k => k != null) < 5) { rMember.StartHingeNo = 100 + (int)kBeam.joint.ind; } //memberEnd int i = 6; Boolean test = true; while (i < 12) { if (kBeam.joint.props[i] != null) { test = false; } i++; } if (!test) { rMember.EndHingeNo = 200 + (int)kBeam.joint.ind; } } rMember.Rotation = new Rotation { Angle = kBeam.res_alpha * 2 * Math.PI / 360, Type = RotationType.Angle }; rMembers.Add(rMember); } } return(new Tuple <Member[], Dlubal.RFEM5.Line[]>(rMembers.ToArray(), rLines.ToArray())); }
private List <Rhino.Geometry.Curve> CreateRhinoCurves(string selectedLineList) { //defining the list with lines that will have to be returned later on List <Rhino.Geometry.Curve> rhOutputCurves = new List <Rhino.Geometry.Curve>(); // Gets interface to running RFEM application. app = Marshal.GetActiveObject("RFEM5.Application") as IApplication; // Locks RFEM licence app.LockLicense(); // Gets interface to active RFEM model. model = app.GetActiveModel(); // Gets interface to model data. IModelData data = model.GetModelData(); //Create new array for Rhino Curve objects List <Rhino.Geometry.Curve> rhinoLineList = new List <Rhino.Geometry.Curve>(); //Create new array for Rhino point objects List <Rhino.Geometry.Point3d> rhinoPointArray = new List <Rhino.Geometry.Point3d>(); try { for (int index = 0; index < data.GetLineCount(); index++) { Dlubal.RFEM5.Line currentLine = data.GetLine(index, ItemAt.AtIndex).GetData(); // the code below converts string describing nodes used in line definition into // list fo all used node numbers. e.g. converts "1,2,4-7,9" into "1,2,4,5,6,7,9" string lineNodes = currentLine.NodeList; List <int> nodesList = new List <int>(); foreach (string tempLineNode in lineNodes.Split(',')) { if (tempLineNode.Contains('-')) { string[] tempLineNodeDashes = new string[2]; tempLineNodeDashes = tempLineNode.Split('-'); int startNumber = Int32.Parse(tempLineNodeDashes[0]); int endNumber = Int32.Parse(tempLineNodeDashes[1]); for (int i = startNumber; i <= endNumber; i++) { nodesList.Add(i); } } else { nodesList.Add(Int32.Parse(tempLineNode)); } } //currently component only reads "polyline" type from RFEM, i.e. straight lines if (currentLine.Type == LineType.PolylineType) { for (int i = 0; i < nodesList.Count - 1; i++) { //getting data for start point and end point from RFEM Dlubal.RFEM5.Node rfemStartPoint = data.GetNode(nodesList[i], ItemAt.AtNo).GetData(); Dlubal.RFEM5.Node rfemEndPoint = data.GetNode(nodesList[i + 1], ItemAt.AtNo).GetData(); //creating Rhino Objects Point3d rhinoStartPoint = new Point3d(rfemStartPoint.X, rfemStartPoint.Y, rfemStartPoint.Z); Point3d rhinoEndPoint = new Point3d(rfemEndPoint.X, rfemEndPoint.Y, rfemEndPoint.Z); Rhino.Geometry.LineCurve currentRhinoCurve = new Rhino.Geometry.LineCurve(rhinoStartPoint, rhinoEndPoint); rhOutputCurves.Add(currentRhinoCurve); } } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } // Releases interface to RFEM model. model = null; // Unlocks licence and releases interface to RFEM application. if (app != null) { app.UnlockLicense(); app = null; } // Cleans Garbage Collector and releases all cached COM interfaces. System.GC.Collect(); System.GC.WaitForPendingFinalizers(); //list with all Rhino Curves is prepared for output return(rhOutputCurves); }
public RFLine(Dlubal.RFEM5.Line line) : this(line, null) { }
public RFLine(Dlubal.RFEM5.Line line, Point3d[] controlPoints, int order, double[] weights, double[] knots) : this(line, controlPoints) { Order = order; Weights = weights; Knots = knots; }
private List <Dlubal.RFEM5.Surface> CreateRfemSurfaces(List <Rhino.Geometry.Brep> Rh_Srf, double srfThicknessInMethod, string srfMaterialTextDescription, string srfCommentMethodIn) { //cycling through all Surfaces and creating RFEM objects; int nodeCount = 1; int lineCount = 1; int surfaceCount = 1; //list for curves describing surface edges List <Rhino.Geometry.Curve> RhSimpleLines = new List <Rhino.Geometry.Curve>(); //lists for nodes, lines and surfaces to be created List <Dlubal.RFEM5.Node> RfemNodeList = new List <Dlubal.RFEM5.Node>(); List <Dlubal.RFEM5.Line> RfemLineList = new List <Dlubal.RFEM5.Line>(); List <Dlubal.RFEM5.Surface> RfemSurfaceList = new List <Dlubal.RFEM5.Surface>(); //---- Interface with RFEM, getting available element numbers ---- #region Interface with RFEM, getting available element numbers // Gets interface to running RFEM application. IApplication app = Marshal.GetActiveObject("RFEM5.Application") as IApplication; // Locks RFEM licence app.LockLicense(); // Gets interface to active RFEM model. IModel model = app.GetActiveModel(); // Gets interface to model data. IModelData data = model.GetModelData(); // Gets Max node, line , surface support numbers int currentNewNodeNo = data.GetLastObjectNo(ModelObjectType.NodeObject) + 1; int currentNewLineNo = data.GetLastObjectNo(ModelObjectType.LineObject) + 1; int currentNewSurfaceNo = data.GetLastObjectNo(ModelObjectType.SurfaceObject) + 1; int currentNewMaterialNo = data.GetLastObjectNo(ModelObjectType.MaterialObject) + 1; #endregion // Defines material used for all surfaces Dlubal.RFEM5.Material material = new Dlubal.RFEM5.Material(); material.No = currentNewMaterialNo; material.TextID = srfMaterialTextDescription; material.ModelType = MaterialModelType.IsotropicLinearElasticType; //start cycling through all surfaces foreach (Rhino.Geometry.Brep RhSingleSurface in Rh_Srf) { #region simplification of perimeter edges // clearing previous surface data before starting to work on new surface: RhSimpleLines.Clear(); //simplifying edges - adding to array; Rhino.Geometry.Curve[] curves = RhSingleSurface.DuplicateEdgeCurves(true); curves = Rhino.Geometry.Curve.JoinCurves(curves); foreach (Rhino.Geometry.Curve RhSingleCurve in curves) { if (RhSingleCurve.IsPolyline()) { if (RhSingleCurve.SpanCount == 1) { //if this is simple linear line RhSimpleLines.Add(RhSingleCurve); } else { foreach (Rhino.Geometry.Curve explodedSurface in RhSingleCurve.DuplicateSegments()) { //if this is polyline RhSimpleLines.Add(explodedSurface); } } } else { foreach (Rhino.Geometry.Curve explodedLine in RhSingleCurve.ToPolyline(0, 0, 3.14, 1, 0, 0, 0, segmentLength, true).DuplicateSegments()) { //if this is curved lines RhSimpleLines.Add(explodedLine); } } #endregion int surfaceNodeCounter = 0; //counts nodes witin one surface. nodeCount counts overall nodes in model int surfaceLineCounter = 0; // counts lines (edges) for one surface, lineCount counts overall lines in model //cycling through perimeter of the surface and defining lines surface #region Defining nodes and lines for one surface for (int i = 0; i < RhSimpleLines.Count; i++) { //defining variables needed to store geometry and RFEM info Rhino.Geometry.Point3d startPoint = RhSimpleLines[i].PointAtStart; Rhino.Geometry.Point3d endPoint = RhSimpleLines[i].PointAtEnd; //if this is the first line for the surface if (i == 0) { // defining start and end nodes of the line Dlubal.RFEM5.Node tempCurrentStartNode = new Dlubal.RFEM5.Node(); Dlubal.RFEM5.Node tempCurrentEndNode = new Dlubal.RFEM5.Node(); tempCurrentStartNode.No = currentNewNodeNo; tempCurrentStartNode.X = Math.Round(startPoint.X, 5); tempCurrentStartNode.Y = Math.Round(startPoint.Y, 5); tempCurrentStartNode.Z = Math.Round(startPoint.Z, 5); tempCurrentEndNode.No = currentNewNodeNo + 1; tempCurrentEndNode.X = Math.Round(endPoint.X, 5); tempCurrentEndNode.Y = Math.Round(endPoint.Y, 5); tempCurrentEndNode.Z = Math.Round(endPoint.Z, 5); RfemNodeList.Add(tempCurrentStartNode); RfemNodeList.Add(tempCurrentEndNode); // defining line Dlubal.RFEM5.Line tempCurrentLine = new Dlubal.RFEM5.Line(); tempCurrentLine.No = currentNewLineNo; tempCurrentLine.Type = LineType.PolylineType; tempCurrentLine.NodeList = $"{tempCurrentStartNode.No}, {tempCurrentEndNode.No}"; RfemLineList.Add(tempCurrentLine); nodeCount = nodeCount + 2; surfaceNodeCounter = surfaceNodeCounter + 2; lineCount++; surfaceLineCounter++; currentNewNodeNo = currentNewNodeNo + 2; currentNewLineNo++; } //if this is the last node for the surface else if (i == RhSimpleLines.Count - 1) { //no need to define new node as these are both already defined //create line connecting previous node with first node for surface // defining start and end nodes of the line Dlubal.RFEM5.Line tempCurrentLine = new Dlubal.RFEM5.Line(); tempCurrentLine.No = currentNewLineNo; tempCurrentLine.Type = LineType.PolylineType; tempCurrentLine.NodeList = $"{RfemNodeList[RfemNodeList.Count - 1].No}, {RfemNodeList[RfemNodeList.Count - surfaceNodeCounter].No}"; RfemLineList.Add(tempCurrentLine); lineCount++; surfaceLineCounter++; currentNewLineNo++; } else { //if this is just a node somewhere on edges //defining end node of line Dlubal.RFEM5.Node tempCurrentEndNode = new Dlubal.RFEM5.Node(); // defining start and end nodes of the line Dlubal.RFEM5.Line tempCurrentLine = new Dlubal.RFEM5.Line(); tempCurrentEndNode.No = currentNewNodeNo; tempCurrentEndNode.X = Math.Round(endPoint.X, 5); tempCurrentEndNode.Y = Math.Round(endPoint.Y, 5); tempCurrentEndNode.Z = Math.Round(endPoint.Z, 5); RfemNodeList.Add(tempCurrentEndNode); tempCurrentLine.No = currentNewLineNo; tempCurrentLine.Type = LineType.PolylineType; tempCurrentLine.NodeList = $"{RfemNodeList[RfemNodeList.Count - 2].No}, {RfemNodeList[RfemNodeList.Count - 1].No}"; RfemLineList.Add(tempCurrentLine); nodeCount++; surfaceNodeCounter++; lineCount++; surfaceLineCounter++; currentNewNodeNo++; currentNewLineNo++; } } #endregion //defines surface data #region Defining data of the surface to be written // start with making a string with "list" of lines forming the surface int surfaceFirstLine = currentNewLineNo - RhSimpleLines.Count; int surfaceLastLine = surfaceFirstLine + RhSimpleLines.Count - 1; string surfaceLineList = ""; for (int i = surfaceFirstLine; i < surfaceLastLine; i++) { surfaceLineList = surfaceLineList + i.ToString() + ","; } surfaceLineList = surfaceLineList + surfaceLastLine.ToString(); // defining RFEM parameter of surface Dlubal.RFEM5.Surface surfaceData = new Dlubal.RFEM5.Surface(); surfaceData.No = currentNewSurfaceNo; surfaceData.MaterialNo = material.No; surfaceData.GeometryType = SurfaceGeometryType.PlaneSurfaceType; surfaceData.BoundaryLineList = surfaceLineList; surfaceData.Comment = srfCommentMethodIn; // if -1 is input as thickness, surface is created as rigid, otherwise it is "standard" if (srfThicknessInMethod == -1) { surfaceData.StiffnessType = SurfaceStiffnessType.RigidStiffnessType; } else if (srfThicknessInMethod == 0) { surfaceData.StiffnessType = SurfaceStiffnessType.NullStiffnessType; } else { surfaceData.StiffnessType = SurfaceStiffnessType.StandardStiffnessType; surfaceData.Thickness.Constant = srfThicknessInMethod; } //adding surface to elements to be written RfemSurfaceList.Add(surfaceData); surfaceCount++; currentNewSurfaceNo++; #endregion } } //try writing the surface; #region Writing the surface and releasing RFEM model try { //prepares model for modification. data.PrepareModification(); data.SetMaterial(material); //This version writes nodes one-by-one because the data.SetNodes() for array appears not to be working foreach (Node currentRfemNode in RfemNodeList) { data.SetNode(currentRfemNode); } //This version writes lines one-by-one because the data.SetLines() for array appears not to be working foreach (Dlubal.RFEM5.Line currentRfemLine in RfemLineList) { data.SetLine(currentRfemLine); } //This version writes lines one-by-one because the data.SetLines() for array appears not to be working foreach (Dlubal.RFEM5.Surface currentRfemSurface in RfemSurfaceList) { data.SetSurface(currentRfemSurface); } //finishes modifications - regenerates numbering etc. data.FinishModification(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error - Surface Write", MessageBoxButtons.OK, MessageBoxIcon.Error); } //resetting counters; nodeCount = 1; lineCount = 1; surfaceCount = 1; // Releases interface to RFEM model. model = null; // Unlocks licence and releases interface to RFEM application. if (app != null) { app.UnlockLicense(); app = null; } // Cleans Garbage Collector and releases all cached COM interfaces. System.GC.Collect(); System.GC.WaitForPendingFinalizers(); #endregion //output 'success' as true writeSuccess = true; ///the Surfaces below outputs created RFEM surfaces in output parameter ///current funcionality does not use this return(RfemSurfaceList); }
private List <Dlubal.RFEM5.Line> CreateRfemLines(List <Rhino.Geometry.Curve> Rh_Crv, Dlubal.RFEM5.LineSupport rfemLineSupportMethodIn, string commentsListMethodIn) { //defining variables needed to store geometry and RFEM info Rhino.Geometry.Point3d startPoint; Rhino.Geometry.Point3d endPoint; List <Dlubal.RFEM5.Node> RfemNodeList = new List <Dlubal.RFEM5.Node>(); List <Dlubal.RFEM5.Line> RfemLineList = new List <Dlubal.RFEM5.Line>(); string createdLinesList = ""; //---- Rhino geometry simplification and creating a list of simple straight lines ---- #region Rhino geometry processing //start by reducing the input curves to simple lines with start/end points List <Rhino.Geometry.Curve> RhSimpleLines = new List <Rhino.Geometry.Curve>(); foreach (Rhino.Geometry.Curve RhSingleCurve in Rh_Crv) { if (RhSingleCurve.IsPolyline()) { if (RhSingleCurve.SpanCount == 1) { // if line is a simple straight line RhSimpleLines.Add(RhSingleCurve); } else { foreach (Rhino.Geometry.Curve explodedLine in RhSingleCurve.DuplicateSegments()) { // if line is polyline, then it gets exploded RhSimpleLines.Add(explodedLine); } } } else { foreach (Rhino.Geometry.Curve explodedLine in RhSingleCurve.ToPolyline(0, 0, 3.14, 1, 0, 0, 0, segmentLengthInput, true).DuplicateSegments()) { // if line is a an arc or nurbs or have any curvature, it gets simplified RhSimpleLines.Add(explodedLine); } } } #endregion //---- Interface with RFEM, getting available element numbers ---- #region Gets interface with RFEM and currently available element numbers // Gets interface to running RFEM application. IApplication app = Marshal.GetActiveObject("RFEM5.Application") as IApplication; // Locks RFEM licence app.LockLicense(); // Gets interface to active RFEM model. IModel model = app.GetActiveModel(); // Gets interface to model data. IModelData data = model.GetModelData(); // Gets Max node, line , line support numbers int currentNewNodeNo = data.GetLastObjectNo(ModelObjectType.NodeObject) + 1; int currentNewLineNo = data.GetLastObjectNo(ModelObjectType.LineObject) + 1; int currentNewLineSupportNo = data.GetLastObjectNo(ModelObjectType.LineSupportObject) + 1; #endregion //----- cycling through all lines and creating RFEM objects ---- #region Creates RFEM node and line elements for (int i = 0; i < RhSimpleLines.Count; i++) { // defining start and end nodes of the line Dlubal.RFEM5.Node tempCurrentStartNode = new Dlubal.RFEM5.Node(); Dlubal.RFEM5.Node tempCurrentEndNode = new Dlubal.RFEM5.Node(); startPoint = RhSimpleLines[i].PointAtStart; endPoint = RhSimpleLines[i].PointAtEnd; tempCurrentStartNode.No = currentNewNodeNo; tempCurrentStartNode.X = startPoint.X; tempCurrentStartNode.Y = startPoint.Y; tempCurrentStartNode.Z = startPoint.Z; tempCurrentEndNode.No = currentNewNodeNo + 1; tempCurrentEndNode.X = endPoint.X; tempCurrentEndNode.Y = endPoint.Y; tempCurrentEndNode.Z = endPoint.Z; RfemNodeList.Add(tempCurrentStartNode); RfemNodeList.Add(tempCurrentEndNode); // defining line Dlubal.RFEM5.Line tempCurrentLine = new Dlubal.RFEM5.Line(); tempCurrentLine.No = currentNewLineNo; tempCurrentLine.Type = LineType.PolylineType; tempCurrentLine.Comment = commentsListMethodIn; tempCurrentLine.NodeList = $"{tempCurrentStartNode.No}, {tempCurrentEndNode.No}"; RfemLineList.Add(tempCurrentLine); // adding line numbers to list with all lines if (i == RhSimpleLines.Count) { createdLinesList = createdLinesList + currentNewLineNo.ToString(); } else { createdLinesList = createdLinesList + currentNewLineNo.ToString() + ","; } // increasing counters for numbering currentNewLineNo++; currentNewNodeNo = currentNewNodeNo + 2; } #endregion //----- Writing nodes and lines to RFEM ---- #region Write nodes, lines and supports to RFEM try { // modification - set model in modification mode, new information can be written data.PrepareModification(); //This version writes lines one-by-one because the data.SetNodes() for array appears not to be working //data.SetNodes(RfemNodeArray); foreach (Node currentRfemNode in RfemNodeList) { data.SetNode(currentRfemNode); } //This version writes lines one-by-one because the data.SetLines() for array appears not to be working foreach (Dlubal.RFEM5.Line currentRfemLine in RfemLineList) { data.SetLine(currentRfemLine); } //Definition of line supports - only is there is input for support: if (rfemLineSupportInput.No != -1) { rfemLineSupportMethodIn.No = currentNewLineSupportNo; rfemLineSupportMethodIn.LineList = createdLinesList; data.SetLineSupport(ref rfemLineSupportMethodIn); } // finish modification - RFEM regenerates the data data.FinishModification(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error - Line Write", MessageBoxButtons.OK, MessageBoxIcon.Error); } #endregion // Releases interface to RFEM model. #region Releases interface to RFEM model = null; // Unlocks licence and releases interface to RFEM application. if (app != null) { app.UnlockLicense(); app = null; } // Cleans Garbage Collector and releases all cached COM interfaces. System.GC.Collect(); System.GC.WaitForPendingFinalizers(); #endregion //output 'success' as true and return the list of the lines; writeSuccess = true; return(RfemLineList); }
/***************************************************/ /**** Private methods ****/ /***************************************************/ private bool CreateCollection(IEnumerable <Panel> panels) { if (panels.Count() > 0) { int panelIdNum = 0; List <Panel> panelList = panels.ToList(); rf.Surface[] rfSurfaces = new rf.Surface[panelList.Count()]; for (int i = 0; i < panels.Count(); i++) { panelIdNum = GetAdapterId <int>(panelList[i]); //get ids outside of BHoM process - might need to be changed int lastLineId = modelData.GetLastObjectNo(rf.ModelObjectType.LineObject); int[] boundaryIdArr = new int[panelList[i].ExternalEdges.Count()]; //create outline List <string> outlineNodeList = new List <string>(); foreach (Edge e in panelList[i].ExternalEdges) { //create rfem nodes, i.e. bhom points - NOTE: RFEM will remove the coincident points itself leaving jumps in node numbering ! 1,2,4,6,8,10,... Line edgeAsLine = e.Curve as Line; rf.Node rfNode1 = new rf.Node { No = (int)this.NextFreeId(typeof(Node)), X = edgeAsLine.Start.X, Y = edgeAsLine.Start.Y, Z = edgeAsLine.Start.Z }; modelData.SetNode(rfNode1); outlineNodeList.Add(rfNode1.No.ToString()); } outlineNodeList.Add(outlineNodeList[0]); rf.Line outline = new rf.Line() { No = lastLineId + 1, Type = rf.LineType.PolylineType, NodeList = String.Join(",", outlineNodeList) }; modelData.SetLine(outline); rfSurfaces[i] = panelList[i].ToRFEM(panelIdNum, new int[] { outline.No }); if (rfSurfaces[i].StiffnessType == rf.SurfaceStiffnessType.StandardStiffnessType) { modelData.SetSurface(rfSurfaces[i]); } else { rf.SurfaceStiffness stiffness = panelList[i].Property.ToRFEM(); rfSurfaces[i].Thickness.Constant = stiffness.Thickness; rf.ISurface srf = modelData.SetSurface(rfSurfaces[i]); rf.IOrthotropicThickness ortho = srf.GetOrthotropicThickness(); ortho.SetData(stiffness); } } } return(true); }