How to use CPython for DPF in Mechanical

KristianHansen
KristianHansen Member Posts: 5
First Comment

Hi,
I have been using DPF as a stand-alone tool for some time now, using it in CPython through a Spyder IDE. I recently discovered that the CPython engine could be enabled in Mechanical, and i wanted to start using dpf directly in "Python Result" objects in mechanical using the CPython engine.

When i insert a Python Result object, it auto-generates the following code, which runs fine using the IronPython engine, but throws an error when using the CPython engine.

def post_started(sender, analysis):# Do not edit this line
define_dpf_workflow(analysis)

Uncomment this function to enable retrieving results from the table/chart

def table_retrieve_result(value):# Do not edit this line

# import mech_dpf
# import Ans.DataProcessing as dpf
# wf = dpf.Workflow(this.WorkflowId)
# wf.Connect('contour_selector', value)
# this.Evaluate()

def define_dpf_workflow(analysis):
import mech_dpf
import Ans.DataProcessing as dpf
mech_dpf.setExtAPI(ExtAPI)
dataSource = dpf.DataSources(analysis.ResultFileName)
u = dpf.operators.result.displacement()
nrm = dpf.operators.math.norm_fc()
# timeScop = dpf.Scoping()
# timeScop.Ids = [1]
# u.inputs.time_scoping.Connect(timeScop)
u.inputs.data_sources.Connect(dataSource)
nrm.Connect(u)
dpf_workflow = dpf.Workflow()
dpf_workflow.Add(u)
dpf_workflow.Add(nrm)
# dpf_workflow.SetInputName(u, 0, 'time')
# dpf_workflow.Connect('time', timeScop)
dpf_workflow.SetOutputContour(nrm)
dpf_workflow.Record('wf_id', False)
this.WorkflowId = dpf_workflow.GetRecordedId()

Error(s):

Error when invoking function 'post_started'.Traceback (most recent call last):
StandardError: Exception has been thrown by the target of an invocation.Traceback (most recent call last):
Exception: NameError : name 'this' is not defined

DPF error - unexpected void entity: assertGetDataSources; no data sources