/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object can be used to retrieve data from input parameters and /// to store data in output parameters.</param> protected override void SolveInstance(IGH_DataAccess DA) { // First, we need to retrieve all data from the input parameters. // Then we need to access the input parameters individually. // When data cannot be extracted from a parameter, we should abort this method. if (!DA.GetDataList <Dlubal.RFEM5.Line>(0, rfemLinesInput)) { return; } DA.GetData(1, ref sectionIdInput); DA.GetData(2, ref materialIdInput); if (!DA.GetData(3, ref rfemHingeStartInput)) { rfemHingeStartInput.No = -1; } if (!DA.GetData(4, ref rfemHingeEndInput)) { rfemHingeEndInput.No = -1; } DA.GetData(5, ref rotationInput); //assignment of rotation angle via Dlubal RFEM API appears not to be working DA.GetData(6, ref commentsInput); DA.GetData(7, ref run); // The actual functionality will be in a method defined below. This is where we run it if (run == true) { //clears and resets all output parameters. // this is done to ensure that if function is repeadedly run, then parameters are re-read and redefined RfemMemberList.Clear(); writeSuccess = false; //runs the method for creating RFEM memebers RfemMemberList = CreateRfemMembers(rfemLinesInput, sectionIdInput, materialIdInput, rfemHingeStartInput, rfemHingeEndInput, rotationInput, commentsInput); DA.SetData(1, writeSuccess); } else { // if "run" is set to false, then also the output parameter "success" is set to false // this ensures that as soon as "run" toogle is set "false", it automatically updates output. DA.SetData(1, false); } // Finally assign the processed data to the output parameter. DA.SetDataList(0, RfemMemberList); //clears and resets all input parameters. // this is done to ensure that if function is repeadedly run, then parameters are re-read and redefined rfemLinesInput.Clear(); sectionIdInput = ""; materialIdInput = ""; rfemHingeStartInput = new Dlubal.RFEM5.MemberHinge(); rfemHingeEndInput = new Dlubal.RFEM5.MemberHinge(); rotationInput = 0; commentsInput = ""; }
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); }