Click here to Skip to main content
15,945,119 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
i am working project where ANAYS WORKBENCH is interfaced with MS EXCEL via python script.

# IronPython imports to enable Excel interop
import clr
import Microsoft.Office.Interop.Excel as Excel

workingDir = AbsUserPathName("C:\Users\shreepal\Downloads\Compressed/")

def updateHandler():

    # Define key ranges in the Workbook
    lenCell = worksheet.Range["B6"]
    ldCell = worksheet.Range["B7"]
    dfCell = worksheet.Range["B8"]

    # Get the Workbench Parameters
    lenParam = Parameters.GetParameter(Name="P1")
    ldParam = Parameters.GetParameter(Name="P2")
    dfParam = Parameters.GetParameter(Name="P3")

    # Assign values to the input parameters
    lenParam.Expression = lenCell.Value2.ToString()
    ldParam.Expression = ldCell.Value2.ToString()

    # Mark the deformation parameter as updating in the workbook

    # Run the project update

    # Update the workbook value from the WB parameter
    dfCell.Value2 = dfParam.Value.Value

# Open the Workbench Project
Open(FilePath = workingDir + "ExcelParameterScripting.wbpj")

# Open Excel and the workbook
ex = Excel.ApplicationClass()
ex.Visible = True
workbook = ex.Workbooks.Open(workingDir + "ParameterExample.xlsm")

#Apply the update handler to the workbook button
OLEbutton = worksheet.OLEObjects("CommandButton1")
OLEbutton.Object.CLICK += updateHandler

This code will launch Excel and Workbench and add the command to execute the update script when we push the button in excel.

**problem is that the action to update the spreadsheet and model is assigned as an OLEObject to the button. Unfortunately this is only active when the script is running. Once it is done the click action is removed, and the button becomes useless. can anyone provide me the code for this button which will able to update the system as many times it is clicked?**
Updated 11-Apr-13 3:20am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900