The following topic describes the Programming Reference by exploring the cut_plane.py example script. (This script is included in the API Programming Reference.)
Each line (or block of lines) is described in detail and related back to the applicable section of the Programming Reference.
from CFD import Setup
from CFD import Results
from CFD import DSE
study = Setup.DesignStudy.Create()
scenario = study.getActiveScenario()
results = scenario.results()
results.activate()
params = Results.CutPlaneParameters()
location = Setup.Vector(0, 0.02, 0)
normal = Setup.Vector(0, 1, 0)
params.scalarResType = Results.VELOCITY_MAG
cp = Results.CutPlane.Create(results, "Cutplane1", location, normal, params)
DSE.UI.ShowMessage("Cutplane created!")
from CFD import Setup
from CFD import Results
from CFD import DSE
>>> In the header section, each module to be referenced in the script must be declared. All are from the CFD project. Click Modules in the Programming Reference for the list of modules:
study = Setup.DesignStudy.Create()
>>>This line declares the variable called study. It is in the Setup module, the DesignStudy class, and the Create method. This is also how to get the handle on the design study. It is not necessary to specify the design study name because there is only one open during an Autodesk Simulation CFD session.
Click Setup on the Modules page. The following page opens:
scenario = study.getActiveScenario()
>>> This line gets the active scenario in the study. Because there is only one active scenario at any given time, it is not necessary to specify the scenario name. The exception is if the intent is to reference a scenario other than the open one.
results = scenario.results()
>>> This gets the results of the scenario.
results.activate()
>>> This command activates the current results.
params = Results.CutPlaneParameters()
>>> Initialize the parameters needed for the results plane. Click Results on the Module page to access the CutPlaneParameters class:
location = Setup.Vector(0, 0.02, 0)
>>> Define a variable called "location," and prescribe the location of the plane at the Y = 0.02 plane. Vector is a class within the Setup module.
normal = Setup.Vector(0, 1, 0)
>>> Define a variable called "normal," and prescribe the orientation of the plane to be normal to the Y axis.
params.scalarResType = Results.VELOCITY_MAG
>>> Set the displayed scalar type on the results plane to be velocity magnitude. ScalarResType is a class under CutPlaneParameters:
To see the list of available enumerators, click the ScalarResType link. VELOCITY_MAG is enum for the velocity magnitude scalar:
cp = Results.CutPlane.Create(results, "Cutplane1", location, normal, params)
>>> Create the results plane using the arguments defined above. The command is formed from the Results module, CutPlane class, and Create method:
DSE.UI.ShowMessage("Cutplane created!")
>>> Display the message "Cutplane created" in the Output bar of the user interface. This command is formed from the DSE module, UI class, and the ShowMessage method:
Related Topics