public static List <Line> selectLines(IModel model) { IView view = model.GetActiveView(); IModelData modelData = model.GetModelData(); List <Line> selectedObjects = new List <Line>(); //select objects string selectedObjectsText = ""; view.PickObjects(ToolType.SelectLines, ref selectedObjectsText); if (selectedObjectsText == "") { return(new List <Line>()); } List <int> selectedObjectsNo = ListOperations.objectNumbersToList(selectedObjectsText); try { foreach (int objectNo in selectedObjectsNo) { selectedObjects.Add(modelData.GetLine(objectNo, ItemAt.AtNo).GetData()); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(selectedObjects); }
//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)); }
public static object selectObjects(IModel model, ToolType toolType) { IView view = model.GetActiveView(); IModelData modelData = model.GetModelData(); List <object> selectedObjects = new List <object>(); //select objects string selectedObjectsText = ""; view.PickObjects(toolType, ref selectedObjectsText); List <int> selectedObjectsNo = ListOperations.objectNumbersToList(selectedObjectsText); try { foreach (int objectNo in selectedObjectsNo) { if (toolType == ToolType.SelectSurfaces) { selectedObjects.Add(modelData.GetSurface(objectNo, ItemAt.AtNo).GetData()); } if (toolType == ToolType.SelectLines) { selectedObjects.Add(modelData.GetLine(objectNo, ItemAt.AtNo).GetData()); } if (toolType == ToolType.SelectNodes) { selectedObjects.Add(modelData.GetNode(objectNo, ItemAt.AtNo).GetData()); } if (toolType == ToolType.SelectMembers) { selectedObjects.Add(modelData.GetMember(objectNo, ItemAt.AtNo).GetData()); } if (toolType == ToolType.SelectOpenings) { selectedObjects.Add(modelData.GetOpening(objectNo, ItemAt.AtNo).GetData()); } if (toolType == ToolType.SelectSetsOfMembers) { selectedObjects.Add(modelData.GetSetOfMembers(objectNo, ItemAt.AtNo).GetData()); } if (toolType == ToolType.SelectSolids) { selectedObjects.Add(modelData.GetSolid(objectNo, ItemAt.AtNo).GetData()); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(selectedObjects); }
public void GetAxes(IModelData data) { Point3D pt = new Point3D(); pt.X = 0.0; pt.Y = 0.0; pt.Z = 0.0; var cSys = data.GetSurface(No, ItemAt.AtNo).GetLocalCoordinateSystem(pt).GetData(); var origin = Edges[0].ToCurve().PointAtStart; var xAxis = new Vector3d(cSys.AxisX.X, cSys.AxisX.Y, cSys.AxisX.Z); var yAxis = new Vector3d(cSys.AxisY.X, cSys.AxisY.Y, cSys.AxisY.Z); var axes = new Plane(origin, xAxis, yAxis); if (SurfaceAxes != null && SurfaceAxes.SurfaceAxesDirection == SurfaceAxesDirection.SurfaceAngularRotation) { axes.Rotate(SurfaceAxes.Rotation, axes.ZAxis); } else if (SurfaceAxes != null && SurfaceAxes.SurfaceAxesDirection == SurfaceAxesDirection.SurfaceAxisXParallelToLine) { var line = data.GetLine(SurfaceAxes.AxesLineList.ToInt()[0], ItemAt.AtNo).GetData(); var crv = Component_GetData.GetRFLines(new List <Dlubal.RFEM5.Line> { line }, data)[0].ToCurve(); var xAxis2 = new Vector3d(crv.PointAtEnd - crv.PointAtStart); var yAxis2 = Vector3d.CrossProduct(axes.ZAxis, xAxis2); axes = new Plane(origin, xAxis2, yAxis2); } else if (SurfaceAxes != null && SurfaceAxes.SurfaceAxesDirection == SurfaceAxesDirection.SurfaceAxisYParallelToLine) { var line = data.GetLine(SurfaceAxes.AxesLineList.ToInt()[0], ItemAt.AtNo).GetData(); var crv = Component_GetData.GetRFLines(new List <Dlubal.RFEM5.Line> { line }, data)[0].ToCurve(); var yAxis2 = new Vector3d(crv.PointAtEnd - crv.PointAtStart); var xAxis2 = Vector3d.CrossProduct(yAxis2, axes.ZAxis); axes = new Plane(origin, xAxis2, yAxis2); } Axes = axes; }
//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 static Node getLineEndNode(int lineNo, IModelData modelData, NodePostion nodePosition) { //get start and end nodes of the new line Line line = modelData.GetLine(lineNo, ItemAt.AtNo).GetData(); string splitLineNodesListText = line.NodeList; List <int> nodesList = ListOperations.objectNumbersToList(splitLineNodesListText); Node startNode = modelData.GetNode(nodesList[0], ItemAt.AtNo).GetData(); Node endNode = modelData.GetNode(nodesList[nodesList.Count - 1], ItemAt.AtNo).GetData(); if (nodePosition == NodePostion.Start) { return(startNode); } else { return(endNode); } }
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); }
private List <Dlubal.RFEM5.Member> CreateRfemMembers(List <Dlubal.RFEM5.Line> rfemLineMethodIn, string sectionIdMethodIn, string materialIdMethodIn, Dlubal.RFEM5.MemberHinge rfemHingeStartMethodIn, Dlubal.RFEM5.MemberHinge rfemHingeEndMethodIn, double rotationMethodIn, string commentsListMethodIn) { //---- Interface with RFEM, getting available element numbers ---- #region Estabilishing connection 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 , line support numbers int currentNewMemberNo = data.GetLastObjectNo(ModelObjectType.MemberObject) + 1; int currentNewSectionNo = data.GetLastObjectNo(ModelObjectType.CrossSectionObject) + 1; int currentNewMaterialNo = data.GetLastObjectNo(ModelObjectType.MaterialObject) + 1; int currentNewHingeNo = data.GetLastObjectNo(ModelObjectType.MemberHingeObject) + 1; #endregion //---- Defining material, cross section and releases ---- #region Defining material, cross section and releases //define material Dlubal.RFEM5.Material material = new Dlubal.RFEM5.Material(); material.No = currentNewMaterialNo; material.TextID = materialIdMethodIn; material.ModelType = MaterialModelType.IsotropicLinearElasticType; //define cross section CrossSection tempCrossSection = new CrossSection(); tempCrossSection.No = currentNewSectionNo; tempCrossSection.TextID = sectionIdMethodIn; tempCrossSection.MaterialNo = currentNewMaterialNo; //define member hinge numbers if (rfemHingeStartInput.No != -1) { rfemHingeStartInput.No = currentNewHingeNo; } if (rfemHingeEndInput.No != -1) { rfemHingeEndMethodIn.No = currentNewHingeNo + 1; } #endregion //---- Process all lines and create members on those ---- #region Processing all lines, creating RFEM member objects for (int i = 0; i < rfemLineMethodIn.Count; i++) { //test if line exists try { data.GetLine(rfemLineMethodIn[i].No, ItemAt.AtNo); } catch { continue; } //assign member properties Dlubal.RFEM5.Member tempMember = new Dlubal.RFEM5.Member(); tempMember.No = currentNewMemberNo; tempMember.LineNo = rfemLineMethodIn[i].No; tempMember.EndCrossSectionNo = currentNewSectionNo; tempMember.StartCrossSectionNo = currentNewSectionNo; tempMember.TaperShape = TaperShapeType.Linear; tempMember.Rotation.Type = RotationType.Angle; tempMember.Rotation.Angle = rotationMethodIn * (Math.PI / 180); if (rfemHingeStartInput.No != -1) { tempMember.StartHingeNo = currentNewHingeNo; } if (rfemHingeEndInput.No != -1) { tempMember.EndHingeNo = currentNewHingeNo + 1; } tempMember.Comment = commentsListMethodIn; // if -1 is input as section, member is created as rigid, otherwise it is "standard" if (sectionIdInput == "-1") { tempMember.Type = MemberType.Rigid; } else if (sectionIdInput == "0") { tempMember.Type = MemberType.NullMember; } else { tempMember.Type = MemberType.Beam; } RfemMemberList.Add(tempMember); currentNewMemberNo++; } #endregion //---- Writing information in RFEM ---- #region Writing info to RFEM try { // modification - set model in modification mode, new information can be written data.PrepareModification(); //set material, cross section and start&end hinges if (sectionIdInput != "-1") { data.SetMaterial(material); data.SetCrossSection(tempCrossSection); } if (rfemHingeStartInput.No != -1) { data.SetMemberHinge(rfemHingeStartInput); } if (rfemHingeEndInput.No != -1) { data.SetMemberHinge(rfemHingeEndMethodIn); } //This version writes members one-by-one because the data.SetNodes() for array appears not to be working //data.SetMembers(RfemMembers); foreach (Member currentRfemMember in RfemMemberList) { data.SetMember(currentRfemMember); } // finish modification - RFEM regenerates the data data.FinishModification(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error - Member Write", MessageBoxButtons.OK, MessageBoxIcon.Error); } #endregion //---- Releases interface to RFEM model ----- #region Releasing 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 member list writeSuccess = true; return(RfemMemberList); }