











# IronPython imports to enable Excel interopimport clrimport osclr.AddReference("Microsoft.office.Interop.Excel")import Microsoft.Office.Interop.Excel as Excel# Define working directoryworkingDir=AbsUserPathName("E:\\2026\\ddd\\aaaaaaaaa\\ANSYS.WORKBENCH\\ex18")def updateHandler():# Update can take long, so disable the Excel warning -# "Excel is waiting for another application to complete an OLE action"ex.Application.DisplayAlerts=False# Define key ranges in the Workbooklengthcell = worksheet,Range["B3"]loadCell =worksheet.Range["C3"]defCell = worksheet.Range["D3"]# Get the Workbench ParameterslengthParam =Parameters.GetParameter (Name="p3")loadParam=Parameters.GetParameter(Name="p1")defParam = Parameters.GetParameter(Name="P2")# Assign values to the input parameterslengthParam.Expression =lengthCeli.Value2.Tostring()+"[mm]"loadParam.Expression=loadCell.Value2.Tostring()+"[N]"# Mark the deformation parameter as updating in the workbookdefCell.Value2="Updating..."# Run the project updateUpdate()# Update the workbook value from the WB parameterdefCell.Value2 = defParam.Value# restore alert settingex.Application.DisplayAlerts = True# Open the Workbench ProjectOpen(FilePath=os.path.join(workingDir,"EX18.0.wbpj"))# Open Excel and the workbookex = Excel.ApplicationClass()ex.Visible=Trueworkbook=ex.Workbooks.Open(os.path.join(workingDir,"EX18.0.xlsx"))worksheet=workbook.ActiveSheet#Apply the update handler to the workbook buttonOLEbutton=worksheet.OLEObjects("CommandButton1")commandButton=OLEbutton.ObjectcommandButton.CLICK += updateHandler


本次案例采用软件是ansys2024r1,感兴趣的道友欢迎后台私信获取案例源文件!祝大家新春快乐!仿的都准算的都稳!下期尝试一下流体的参数化计算。