Creating the Script to be Run on Solve, MAPDL_S.py

When the user selects “solve” the python script will:

  1. Find out what macro file has been selected

    1. Display a message to the Solver Script Output if more than one attribute group is defined

  2. Obtain selected upstream solution data

    1. Display a message to the Solver Script Output if more than one upstream system is entered

  3. Run the macro with Mechanical APDL

    1. It is assumed that the macro will write data out to a CSV file so it can be read at the evaluate stage

    2. Display the output from running the macro as the Solver Output

import os

DA = DesignAssessment

def runDADemoSolve():
    #1.a - display message
    if DA.AttributeGroupCount != 1:
        print "Only one Attribute Group should be entered"

    #2.a - Display message
    if DA.SolutionSelections()[0].SolutionCount != 1:
        print "Only one upstream solution should be entered"

    #1 - Get the macro path        
    MAPDLMacro = DA.AttributeGroups()[0].Attribute("MAPDL Macro File").ValueAsString

    SolPath = DA.SolutionSelections()[0].SolutionByRow(1).ResultFilePath
    
    #2 - Form the command line strings
    SolPath_Output = "Macro.out"
    SolTime_ARG2 = str(DA.SolutionSelections()[0].SolutionByRow(1).Time)
    BatchArgs = " -par1 file -par2 " + SolTime_ARG2

    #2 - Run the solve with MAPDL
    #Change to the path where the results are kept
    os.chdir(SolPath.rstrip('file.rst'))
    #Run MAPDL
    DA.Helper.RunMAPDL(MAPDLMacro,SolPath_Output,BatchArgs)
    
    #2.b - Display the output
    DA.Helper.ReplaceSolverOutputFile(SolPath_Output)
    
runDADemoSolve()

Release 18.2 - © ANSYS, Inc. All rights reserved.