How can I automate copy pasting values from excel to remote forces tabular data for x,y,z components?
Thanks in advance!
This is a general example of how to interact with Microsoft Excel in mechanical scripting, which is iron python.https://discuss.ansys.com/discussion/2195/how-to-interact-with-excel-from-mechanical-or-other-applications
For PyMechanical, you should be in a typical python environment, and there are a number of general purpose examples/tutorials for how to interact with Excel. Once you have the data from Excel in a python variable, assigning the values Is the same as any tabular data for an object component field.
This post could help too: https://discuss.ansys.com/discussion/2761/combin39-in-mechanical-automatically-using-input-force-vs-deflection-data-from-an-excel-file
RL= DataModel.GetObjectsByType(DataModelObjectCategory.RemoteForce) RL1 = RL[0] RL1.DefineBy = LoadDefineBy.Components RL1.IndependentVariable = LoadVariableVariationType.Step import clr clr.AddReference("Microsoft.Office.Interop.Excel") import Microsoft.Office.Interop.Excel as Excel excel = Excel.ApplicationClass() filename = r"C:\FUN\PREPROCESSING_AUTOMATION\ALL_LOADS_H1.xlsx" workbook = excel.Workbooks.Open(filename) ws=workbook.worksheets("Sheet1") time = [] load1 = [] load2 = [] load3 = [] for i in range(1, 73): cell_value1 = ws.Range["A" + str(i)].Value2 cell_value2= ws.Range["B" + str(i)].Value2 cell_value3= ws.Range["C" + str(i)].Value2 ip_quantity = Quantity(i, "sec") time.append(ip_quantity) op_quantity1 = Quantity(cell_value1, "N") op_quantity2 = Quantity(cell_value2, "N") op_quantity3 = Quantity(cell_value3, "N") load1.append(op_quantity1) load2.append(op_quantity2) load3.append(op_quantity3) RL1.XComponent.Inputs[0].DiscreteValues = time RL1.XComponent.Output.DiscreteValues = load1 RL1.YComponent.Output.DiscreteValues = load2 RL1.ZComponent.Output.DiscreteValues = load3
Iam able to get the solution with the above code it works good. Thanks for all the comments