private List <Dlubal.RFEM5.Node> CreateRfemNodes(List <Point3d> Rh_pt3d, Dlubal.RFEM5.NodalSupport rfemNodalSupportMethodIn, string commentsListMethodIn)
        {
            //---- Estabish connection with RFEM----
            #region Creating connection with RFEM

            // 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();
            #endregion

            //---- Further lines gets information about available object numbers in model;----
            #region Getting available element numbers

            // Gets Max node Number
            int currentNewNodeNo = data.GetLastObjectNo(ModelObjectType.NodeObject) + 1;
            // Gets Max nodal support number
            int currentNewNodalSupportNo = data.GetLastObjectNo(ModelObjectType.NodalSupportObject) + 1;
            #endregion

            //---- Creating new variables for use within this method----
            List <Dlubal.RFEM5.Node> RfemNodeList = new List <Dlubal.RFEM5.Node>(); //Create new list for RFEM point objects
            string createdNodesList = "";                                           //Create a string for list with nodes

            //---- Assigning node propertiess----
            #region Creating RFEM node elements


            for (int i = 0; i < Rh_pt3d.Count; i++)
            {
                Dlubal.RFEM5.Node tempCurrentNode = new Dlubal.RFEM5.Node();
                tempCurrentNode.No      = currentNewNodeNo;
                tempCurrentNode.CS      = CoordinateSystemType.Cartesian;
                tempCurrentNode.Type    = NodeType.Standard;
                tempCurrentNode.X       = Rh_pt3d[i].X;
                tempCurrentNode.Y       = Rh_pt3d[i].Y;
                tempCurrentNode.Z       = Rh_pt3d[i].Z;
                tempCurrentNode.Comment = commentsListMethodIn;
                RfemNodeList.Add(tempCurrentNode);

                if (i == Rh_pt3d.Count - 1)
                {
                    createdNodesList = createdNodesList + currentNewNodeNo.ToString();
                }
                else
                {
                    createdNodesList = createdNodesList + currentNewNodeNo.ToString() + ",";
                }

                currentNewNodeNo++;
            }

            //create an array of nodes;
            Dlubal.RFEM5.Node[] RfemNodeArray = new Dlubal.RFEM5.Node[RfemNodeList.Count];
            RfemNodeArray = RfemNodeList.ToArray();
            #endregion


            //---- Writing nodes----
            #region Writing RFEM nodes and supports

            try
            {
                // modification - set model in modification mode, new information can be written
                data.PrepareModification();

                ///This version writes nodes one-by-one, because the API method data.SetNodes() for
                ///array appears not to be working
                //data.SetNodes(RfemNodeList.ToArray());
                foreach (Node currentRfemNode in RfemNodeList)
                {
                    data.SetNode(currentRfemNode);
                }

                //addition of nodal supports
                rfemNodalSupportMethodIn.No       = currentNewNodalSupportNo;
                rfemNodalSupportMethodIn.NodeList = createdNodesList;
                data.SetNodalSupport(ref rfemNodalSupportMethodIn);


                // finish modification - RFEM regenerates the data (this operation takes some time)
                data.FinishModification();
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error - Writing nodes", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            #endregion


            //---- Releasing RFEM model----
            #region Releasing RFEM model

            // 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

            ///the lines below outputs created RFEM nodes in output parameter
            //output 'success' as true
            writeSuccess = true;
            return(RfemNodeList);
        }
        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);
        }
Example #3
0
        /// <summary>
        /// Method for spliting surfaces with line
        /// Takes no arguments, because surface and line is selected in RFEM surface
        /// </summary>
        public static void splitSurfaces()
        {
            IModel     model     = RFEMconnection.getRFEMconnection();
            IModelData modelData = model.GetModelData();

            IView view = model.GetActiveView();

            //select surface - cast to be used because selectObjects returns generic "object"
            Common.IO.Log("Select one surface to split!");
            List <Surface> selectedSurfaces = RFEMselectOps.selectSurfaces(model);

            if (selectedSurfaces.Count == 0)
            {
                Common.IO.Log("");
                return;
            }

            Surface selectedSurface   = selectedSurfaces[0];
            int     selectedSurfaceNo = selectedSurface.No;

            //select line - cast to be used because selectObjects returns generic "object"
            Common.IO.Log("Select one line to split with!");
            List <Line> selectedLines = RFEMselectOps.selectLines(model);

            if (selectedLines.Count == 0)
            {
                Common.IO.Log("");
                return;
            }

            int splitLineNo = selectedLines[0].No;

            //get boundary lines of existing surface
            string     boundaryLinesListString = selectedSurface.BoundaryLineList;
            List <int> boundaryLinesList       = ListOperations.objectNumbersToList(boundaryLinesListString);

            //get boundary lines of split surfaces
            List <List <int> > newSurfacesBoundLines = getBoundaryLinesOfSplitSurfaces(modelData, boundaryLinesList, splitLineNo);

            //Define new surfaces using existing surface data as a template
            Surface newSplitSurface1 = new Surface();
            Surface newSplitSurface2 = new Surface();


            //first surface will keep the number or original surface
            RFEMobjectOps.MatchSurfacePropertiesSettings surfMatchPropsSurf1 = new RFEMobjectOps.MatchSurfacePropertiesSettings();
            surfMatchPropsSurf1.No = true;
            //for second one, new number will be assigned
            RFEMobjectOps.MatchSurfacePropertiesSettings surfMatchPropsSurf2 = new RFEMobjectOps.MatchSurfacePropertiesSettings();
            int nextAvailableSurfaceNo = modelData.GetLastObjectNo(ModelObjectType.SurfaceObject) + 1;

            newSplitSurface2.No = nextAvailableSurfaceNo;

            //match properties
            RFEMobjectOps.MatchSurfaceProperties(selectedSurface, ref newSplitSurface1, surfMatchPropsSurf1);
            RFEMobjectOps.MatchSurfaceProperties(selectedSurface, ref newSplitSurface2, surfMatchPropsSurf2);

            //convert list of integers to RFEM text, assign these to newly created surfaces
            newSplitSurface1.BoundaryLineList = ListOperations.objectNumbersToSting(newSurfacesBoundLines[0]);
            newSplitSurface2.BoundaryLineList = ListOperations.objectNumbersToSting(newSurfacesBoundLines[1]);


            try
            {
                //prepares model for modification and writes data
                modelData.PrepareModification();
                modelData.SetSurface(newSplitSurface1);
                modelData.SetSurface(newSplitSurface2);

                //finishes modifications - regenerates numbering etc.
                modelData.FinishModification();
                Common.IO.Log("Surface has been split in two");
            }
            catch (Exception ex)
            {
                Common.IO.Log("Error in splitting the surface");
                MessageBox.Show(ex.Message, "Error - Surface Write", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                //closing the connection with RFEM
                RFEMconnection.closeRFEMconnection(model);
            }
        }
        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 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);
        }