//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)));
        }
        private Tuple <DataTree <float>[], List <Rhino.Geometry.Line> > runRFEMapp(int LCase)
        {
            IApplication app   = null;
            IModel       model = null;
            List <Rhino.Geometry.Line> lines    = new List <Rhino.Geometry.Line>();
            DataTree <float>           location = new DataTree <float>();
            DataTree <float>           Nx       = new DataTree <float>();
            DataTree <float>           Vy       = new DataTree <float>();
            DataTree <float>           Vz       = new DataTree <float>();
            DataTree <float>           Mx       = new DataTree <float>();
            DataTree <float>           My       = new DataTree <float>();
            DataTree <float>           Mz       = new DataTree <float>();
            ItemAt itemAt = ItemAt.AtNo;

            try
            {
                //Get active RFEM5 application
                app = Marshal.GetActiveObject("RFEM5.Application") as IApplication;
                app.LockLicense();
                model = app.GetActiveModel();

                IModelData     data   = model.GetModelData();
                ICalculation   calc   = model.GetCalculation();
                IResults       res    = calc.GetResultsInFeNodes(LoadingType.LoadCaseType, LCase);
                MemberForces[] forces = res.GetMembersInternalForces(true);

                try
                {
                    int     i    = 0;
                    int     k    = 0;
                    GH_Path path = new GH_Path(forces[0].MemberNo);
                    lines.Add(getMemberLine(data, forces[0].MemberNo, itemAt));
                    while (i < forces.Length)
                    {
                        if (i > 0 && forces[i].MemberNo != forces[i - 1].MemberNo)
                        {
                            path = new GH_Path(forces[i].MemberNo);
                            lines.Add(getMemberLine(data, forces[i].MemberNo, itemAt));
                            k = 0;
                        }
                        location.Insert((float)forces[i].Location, path, k);
                        Nx.Insert((float)forces[i].Forces.X, path, k);
                        Vy.Insert((float)forces[i].Forces.Y, path, k);
                        Vz.Insert((float)forces[i].Forces.Z, path, k);
                        Mx.Insert((float)forces[i].Moments.X, path, k);
                        My.Insert((float)forces[i].Moments.Y, path, k);
                        Mz.Insert((float)forces[i].Moments.Z, path, k);
                        i += 1;
                        k += 1;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, ex.Source, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.Source, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                //Release COM object
                if (app != null)
                {
                    app.UnlockLicense();
                    app = null;
                }

                //Cleans Garbage collector for releasing all COM interfaces and objects
                System.GC.Collect();
                System.GC.WaitForPendingFinalizers();
            }
            DataTree <float>[] values = new DataTree <float>[] { location, Nx, Vy, Vz, Mx, My, Mz };
            return(new Tuple <DataTree <float>[], List <Rhino.Geometry.Line> >(values, lines));
        }