Accessing Results by Python Script

Accessing Results by Python Script

h.schlichter
Advocate Advocate
1,689 Views
4 Replies
Message 1 of 5

Accessing Results by Python Script

h.schlichter
Advocate
Advocate

Hi everyone,

 

how can I access pressure coefficient on a wall by Python script. The pressure is accessed by

 

WallResults().pressure(ID)

 

but what is the variable name for the pressure coefficient? Is there any list of all result variabales?

 

Best regards

 

H. Schlichter

 

0 Likes
Accepted solutions (1)
1,690 Views
4 Replies
Replies (4)
Message 2 of 5

Royce_adsk
Community Manager
Community Manager

Hi @h.schlichter!

 

Working with the API can be tricky at times.  I pulled the example code around the wall results.  Do you understand the variables available now with the wall results?  As a hint in the future.  Most of the naming convention in the UI is the same in the API.

 

Here is some example code.

    1 from CFD import Setup
    2 from CFD import Results
    3 from CFD import DSE
    4 
    5 def WallResults():
    6  # Get current scenario & activate results
    7  study = Setup.DesignStudy.Create()
    8  scenario = study.getActiveScenario()
    9  curr_results = scenario.results()
   10  if curr_results is None:
   11   DSE.UI.ShowMessage( "There are no results !" )
   12   return 
   13  curr_results.activate()
   14 
   15  # Create a WallResults object
   16  wr = Results.WallResults(scenario)
   17 
   18  # Set the id of surface of interest & ask it to calculate
   19  wr.select(15)
   20  wr.select(9)
   21  wr.calculate()
   22  
   23  # Get the results
   24  area = wr.area(15)
   25  pressure = wr.pressure(15)
   26  temp = wr.temperature(15)
   27  fx, fy, fz = 0.0, 0.0, 0.0  # force is a little complicated because it is 3 values
   28  err, fx, fy, fz = wr.force(fx, fy, fz) 
   29 
   30  print("Area  = ", area)
   31  print("Press = ", pressure)
   32  print("Temp  = ", temp)
   33  print("FX    = ", fx)
   34  print("FY    = ", fy)
   35  print("FZ    = ", fz)
   36 
   37  DSE.UI.ShowMessage( "Area  = " + str(area) )
   38  DSE.UI.ShowMessage( "Press = " + str(pressure) )
   39  DSE.UI.ShowMessage( "Temp = " + str(temp) )
   40  DSE.UI.ShowMessage( "FX     = " + str(fx) )
   41  DSE.UI.ShowMessage( "FY     = " + str(fy) )
   42  DSE.UI.ShowMessage( "FZ     = " + str(fz) )
   43 
   44 
   45  # Or you can write all wall results to a file
   46  wr.writeToFile("C:/wr.csv")
   47  print("Wall results are witten to c:/wr.csv")
   48  DSE.UI.ShowMessage( "Wall results are witten to c:/wr.csv" )
   49 
   50 WallResults()

 

You also made a comment about how to find everything for a object?  I wrote this for myself years ago to do just that.  Any questions on this piece of code?  You can play around with the code a bit to pull out different types of objects.

 

import CFD
import sys
import time
import win32com.client as win32
import math
import os
import shlex

from CFD import Setup
from CFD import Results
from CFD import DSE
from CFD import DC

userName = os.environ.get( "USERNAME" )
sys.path.append("C:/Users/" + userName + "/Dropbox/CFdesign/Python Scripts/")


def listProperties():
	study = Setup.DesignStudy.Create()
	scenario = study.getActiveScenario()
	
	CFD.DSE.UI.ShowMessage(str(scenario.numProperties()))

	defList = Setup.PropertyDefinitionList()
	varList = Setup.VariantList()
	scenario.properties(defList,varList)
	CFD.DSE.UI.ShowMessage(" ")
	for a in defList:
		CFD.DSE.UI.ShowMessage(str(a.name()))

	CFD.DSE.UI.ShowMessage(scenario.property("path"))

listProperties()

 



Royce.Abel
Technical Support Manager

0 Likes
Message 3 of 5

h.schlichter
Advocate
Advocate

Hi Royce,

 

thank you for your answer and the second script, it can be very helpful.

 

There are some points to speak about:

 

  • In my installation of CFD (german) there was no help folder, but I found the API documenation in Autodesk's download center
  • the example scripts in the online doc are erroneous, but I could resolve most of the errors
  • the most important point for me is to extract the result quantity "pressure coefficient', but I don't know how to access it

In the CFD 2016 API doc I did not find something about the "pressure coefficient". Can one extend your script to list all result quantities?

 

Regards

 

H. Schlichter

 

0 Likes
Message 4 of 5

Royce_adsk
Community Manager
Community Manager
Accepted solution

Hi @h.schlichter,

 

Glad to hear that my utility script for properties could be useful!  Let me address your three points:

 

  1. There was a decision in the past to remove the API documentation from the installation directly and move it to the download center.  That is the best place to find the most up to date API documentation.  Not much as changed in the API recently so that is why a new version hasn't been released.
  2. Agree that there are some errors in the documentation, but most seem to be minor enough to get around.  Those that you find you can log with us in support and we can pass it onto the developers to improve.
  3. In terms of the pressure coefficient for the wall results.  This result isn't available from the UI when using the wall calculator so it isn't available either when using the API.  Since this is something you would like I suggest posting it to the CFD IdeaStation.  For now, you'll have to use the pressure output and then calculate the pressure coefficient manually.  As you have noticed, there is a pressure coefficient results quantity, but most of the results are not available in the wall calculator tool.

I know that isn't what you were hoping, but that is what we currently have available.



Royce.Abel
Technical Support Manager

Message 5 of 5

h.schlichter
Advocate
Advocate

Hi Royce,

 

thank you very much for your clarification. I will follow your hints.

 

Regards

 

H. Schlichter

 

0 Likes