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);
        }