/***************************************************/ /**** Private methods ****/ /***************************************************/ private bool CreateCollection(IEnumerable <Node> nodes) { if (nodes.Count() > 0) { int nodeIdNum = 0; int consIdNum = 0; List <Node> nodeList = nodes.ToList(); rf.Node[] rfNodes = new rf.Node[nodeList.Count()]; for (int i = 0; i < nodes.Count(); i++) { nodeIdNum = GetAdapterId <int>(nodeList[i]);//(NextId(nodeList[i].GetType())); rfNodes[i] = nodeList[i].ToRFEM(nodeIdNum); modelData.SetNode(rfNodes[i]); //set support here if the node contains one ! ! ! ! ! if (nodeList[i].Support != null) { consIdNum = System.Convert.ToInt32(NextFreeId(nodeList[i].Support.GetType())); rf.NodalSupport rfConstraint = nodeList[i].Support.ToRFEM(consIdNum, nodeIdNum); modelData.SetNodalSupport(rfConstraint); } } //modelData.SetNodes(rfemNodes); } return(true); }
/// <summary> /// Further 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. // When data cannot be extracted from a parameter, we should abort this method. if (!DA.GetDataList <Rhino.Geometry.Point3d>(0, rhinoPointsInput)) { return; } DA.GetData(1, ref rfemNodalSupportInput); DA.GetData(2, ref commentsInput); DA.GetData(3, 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 RfemNodes.Clear(); writeSuccess = false; //runs the method for creating RFEM nodes RfemNodes = CreateRfemNodes(rhinoPointsInput, rfemNodalSupportInput, 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, RfemNodes); // clear and reset all input parameters // this is done to ensure that if function is repeadedly run, then parameters are re-read and redefined rhinoPointsInput.Clear(); commentsInput = ""; rfemNodalSupportInput = new Dlubal.RFEM5.NodalSupport(); }
/***************************************************/ /**** Public Methods ****/ /***************************************************/ //Add methods for converting to BHoM from the specific software types. //Only do this if possible to do without any com-calls or similar to the adapter public static Constraint6DOF FromRFEM(this rf.NodalSupport rfConstraint) { Constraint6DOF bhConstraint = new Constraint6DOF(); //Translation if (rfConstraint.SupportConstantX == 0) { bhConstraint.TranslationX = DOFType.Free; } if (rfConstraint.SupportConstantX == -1) { bhConstraint.TranslationX = DOFType.Fixed; } else { bhConstraint.TranslationalStiffnessX = rfConstraint.SupportConstantX; } if (rfConstraint.SupportConstantY == 0) { bhConstraint.TranslationY = DOFType.Free; } if (rfConstraint.SupportConstantY == -1) { bhConstraint.TranslationY = DOFType.Fixed; } else { bhConstraint.TranslationalStiffnessY = rfConstraint.SupportConstantY; } if (rfConstraint.SupportConstantZ == 0) { bhConstraint.TranslationZ = DOFType.Free; } if (rfConstraint.SupportConstantZ == -1) { bhConstraint.TranslationZ = DOFType.Fixed; } else { bhConstraint.TranslationalStiffnessZ = rfConstraint.SupportConstantZ; } //Rotation if (rfConstraint.RestraintConstantX == 0) { bhConstraint.RotationX = DOFType.Free; } if (rfConstraint.RestraintConstantX == -1) { bhConstraint.RotationX = DOFType.Fixed; } else { bhConstraint.RotationalStiffnessX = rfConstraint.RestraintConstantX; } if (rfConstraint.RestraintConstantY == 0) { bhConstraint.RotationY = DOFType.Free; } if (rfConstraint.RestraintConstantY == -1) { bhConstraint.RotationY = DOFType.Fixed; } else { bhConstraint.RotationalStiffnessY = rfConstraint.RestraintConstantY; } if (rfConstraint.RestraintConstantZ == 0) { bhConstraint.RotationZ = DOFType.Free; } if (rfConstraint.RestraintConstantZ == -1) { bhConstraint.RotationZ = DOFType.Fixed; } else { bhConstraint.RotationalStiffnessZ = rfConstraint.RestraintConstantZ; } bhConstraint.SetAdapterId(typeof(RFEMId), rfConstraint.No); return(bhConstraint); }
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); }
/***************************************************/ /**** Public Methods ****/ /***************************************************/ public static rf.NodalSupport ToRFEM(this Constraint6DOF constraint, int constraintId, int nodeId) { rf.NodalSupport rfConstraint = new rf.NodalSupport(); rfConstraint.No = constraintId; rfConstraint.NodeList = nodeId.ToString();//<-- id reference to node(s) required for writing constraint to RFEM //Translation - RFEM unit is N/m if (constraint.TranslationX == DOFType.Free) { rfConstraint.SupportConstantX = 0; } else if (constraint.TranslationX == DOFType.Fixed) { rfConstraint.SupportConstantX = -1; } else { rfConstraint.SupportConstantX = constraint.TranslationalStiffnessX; } if (constraint.TranslationY == DOFType.Free) { rfConstraint.SupportConstantY = 0; } else if (constraint.TranslationY == DOFType.Fixed) { rfConstraint.SupportConstantY = -1; } else { rfConstraint.SupportConstantY = constraint.TranslationalStiffnessY; } if (constraint.TranslationZ == DOFType.Free) { rfConstraint.SupportConstantZ = 0; } else if (constraint.TranslationZ == DOFType.Fixed) { rfConstraint.SupportConstantZ = -1; } else { rfConstraint.SupportConstantZ = constraint.TranslationalStiffnessZ; } //Rotation - RFEM unit is Nm/Rad if (constraint.RotationX == DOFType.Free) { rfConstraint.RestraintConstantX = 0; } else if (constraint.RotationX == DOFType.Fixed) { rfConstraint.RestraintConstantX = -1; } else { rfConstraint.RestraintConstantX = constraint.RotationalStiffnessX; } if (constraint.RotationY == DOFType.Free) { rfConstraint.RestraintConstantY = 0; } else if (constraint.RotationY == DOFType.Fixed) { rfConstraint.RestraintConstantY = -1; } else { rfConstraint.RestraintConstantY = constraint.RotationalStiffnessY; } if (constraint.RotationZ == DOFType.Free) { rfConstraint.RestraintConstantZ = 0; } else if (constraint.RotationZ == DOFType.Fixed) { rfConstraint.RestraintConstantZ = -1; } else { rfConstraint.RestraintConstantZ = constraint.RotationalStiffnessZ; } return(rfConstraint); }