ANSYS Mechanical Workbench Scripting - Accessing Parameters

1.6k Views Asked by At

Ansys gurus,

My project is a static structural analysis using ANSYS workbench mechanical. I have created the parametrized geometry (via Design modeler) and material property in workbench, and used ACT scripting to configure the model. However, I don't find too much information on how to access the parameters via ACT scripting.

I have confirmed that the geometric parameters are successfully created in the workbench, e.g.

ID Paramater Name Value Unit
P1 diameter 50 um

The documentation LINK suggests that I can obtain parameter ID using Analysis.GetParameter(), however, the following code didn't work for me and resulted in the error as below.

Code:

STATIC_STRUCTURAL = ExtAPI.DataModel.AnalysisByName("Static Structural")

HEIGHT = STATIC_STRUCTURAL.GetParameter('height')

Error: Property not found.

Do you have any suggestions on the cause of such error, is it because the Parameters were not imported from workbench "project schematic" to "Model", or the code I tried to retrieve the parameters was incorrect. In either cases, could you advise the correct method to access the parameters? Thank you!

hawkoli1987

1

There are 1 best solutions below

2
meshWorker On

If you want to access a parameter from the "project schematic" page you can create a list. If you than want to do something with this inside of mechanical, you have to send the commands to your model:

# Access the geometric parameters
allParameters = Parameters.GetAllParameters()
for parameter in allParameters:
    print parameter.DisplayText
    if parameter.DisplayText == 'height':
        heigthParameter = parameter

# Loop over all systems in the project
for system in GetAllSystems():
    # Get Model Container
    model = system.GetContainer(ComponentName="Model")
    # edit model component in batch mode
    system.Refresh()
    model.Edit(Interactive=True)
    # code to be sent to ansys mechanical
    cmd ='''
here goes your ACT script as string. You have to make sure, that there are no leading spaces or tabs.
    '''
    # send code and exit mechanical
    model.SendCommand(Language='Python',Command=cmd)
    model.Exit()
print "Finished script execution."