chrono::parsers::ChPythonEngine Class Reference

Description

Class for a Python parser.

This is an interpreter that can parse Python programs, from a single formula up to large programs.

#include <ChParserPython.h>

Public Member Functions

 ChPythonEngine ()
 Create a Python parser, an interpreter that can parse Python programs. More...
 
void Run (const std::string &program)
 Execute a program. More...
 
void SetFloat (const std::string &variable, const double val)
 Set a value of a floating point variable. More...
 
bool GetFloat (const std::string &variable, double &return_val)
 Retrieve a value of an existing floating point variable. More...
 
void SetInteger (const std::string &variable, const int val)
 Set a value of a integer variable. More...
 
bool GetInteger (const std::string &variable, int &return_val)
 Retrieve a value of an existing integer variable. More...
 
void SetBool (const std::string &variable, const bool val)
 Set a value of a bool variable. More...
 
bool GetBool (const std::string &variable, bool &return_val)
 Retrieve a value of an existing bool variable. More...
 
void SetString (const std::string &variable, std::string &val)
 Set a value of a string variable. More...
 
bool GetString (const std::string &variable, std::string &return_val)
 Retrieve a value of an existing string variable. More...
 
void SetList (const std::string &variable, const std::vector< double > &val)
 Set a numeric list variable from a given std::vector. More...
 
bool GetList (const std::string &variable, std::vector< double > &return_val)
 Retrieve an existing numeric list variable and store it in given std::vector. More...
 
void SetList (const std::string &variable, const ChVectorDynamic< double > &val)
 Set a numeric list variable from a given ChVectorDynamic<>. More...
 
bool GetList (const std::string &variable, ChVectorDynamic< double > &return_val)
 Retrieve an existing numeric list variable and store it in given ChVectorDynamic<>. More...
 
void SetMatrix (const std::string &variable, const ChMatrixDynamic< double > &val)
 Set a numeric list variable from a given ChMatrixDynamic<>. More...
 
bool GetMatrix (const std::string &variable, ChMatrixDynamic< double > &return_val)
 Retrieve an existing numeric list variable and store it in given ChMatrixDynamic<>. More...
 
void ImportSolidWorksSystem (const std::string &solidworks_py_file, ChSystem &msystem)
 Load a .py file as it is saved by the SolidWorks add-in exporter. More...
 

Constructor & Destructor Documentation

◆ ChPythonEngine()

chrono::parsers::ChPythonEngine::ChPythonEngine ( )

Create a Python parser, an interpreter that can parse Python programs.

NOTE: currently only one instance at a time can be created.

Member Function Documentation

◆ GetBool()

bool chrono::parsers::ChPythonEngine::GetBool ( const std::string &  variable,
bool &  return_val 
)

Retrieve a value of an existing bool variable.

Returns false if unsuccessful.

◆ GetFloat()

bool chrono::parsers::ChPythonEngine::GetFloat ( const std::string &  variable,
double &  return_val 
)

Retrieve a value of an existing floating point variable.

Returns false if unsuccessful.

◆ GetInteger()

bool chrono::parsers::ChPythonEngine::GetInteger ( const std::string &  variable,
int &  return_val 
)

Retrieve a value of an existing integer variable.

Returns false if unsuccessful.

◆ GetList() [1/2]

bool chrono::parsers::ChPythonEngine::GetList ( const std::string &  variable,
ChVectorDynamic< double > &  return_val 
)

Retrieve an existing numeric list variable and store it in given ChVectorDynamic<>.

Returns false if unsuccessful.

◆ GetList() [2/2]

bool chrono::parsers::ChPythonEngine::GetList ( const std::string &  variable,
std::vector< double > &  return_val 
)

Retrieve an existing numeric list variable and store it in given std::vector.

Returns false if unsuccessful.

◆ GetMatrix()

bool chrono::parsers::ChPythonEngine::GetMatrix ( const std::string &  variable,
ChMatrixDynamic< double > &  return_val 
)

Retrieve an existing numeric list variable and store it in given ChMatrixDynamic<>.

Returns false if unsuccessful.

◆ GetString()

bool chrono::parsers::ChPythonEngine::GetString ( const std::string &  variable,
std::string &  return_val 
)

Retrieve a value of an existing string variable.

Returns false if unsuccessful.

◆ ImportSolidWorksSystem()

void chrono::parsers::ChPythonEngine::ImportSolidWorksSystem ( const std::string &  solidworks_py_file,
ChSystem msystem 
)

Load a .py file as it is saved by the SolidWorks add-in exporter.

Such a .py file is a Python program that creates an equivalent mechanism in Chrono and contains a sequence of Chrono physics item object (bodies, links, etc.). This function populates the specified Chrono system with all these Chrono objects. This function may throw on error, so it should be called in a try-catch block

Add the ChPhysicsItem to the ChSystem

◆ Run()

void chrono::parsers::ChPythonEngine::Run ( const std::string &  program)

Execute a program.

Throws an exception in case of failure, so it recommended to enclose this in a try..catch block.

◆ SetBool()

void chrono::parsers::ChPythonEngine::SetBool ( const std::string &  variable,
const bool  val 
)

Set a value of a bool variable.

If a variable with the same name is existing, it is overwritten, otherwise it is created (in main namespace)

◆ SetFloat()

void chrono::parsers::ChPythonEngine::SetFloat ( const std::string &  variable,
const double  val 
)

Set a value of a floating point variable.

If a variable with the same name is existing, it is overwritten, otherwise it is created (in main namespace)

◆ SetInteger()

void chrono::parsers::ChPythonEngine::SetInteger ( const std::string &  variable,
const int  val 
)

Set a value of a integer variable.

If a variable with the same name is existing, it is overwritten, otherwise it is created (in main namespace)

◆ SetList() [1/2]

void chrono::parsers::ChPythonEngine::SetList ( const std::string &  variable,
const ChVectorDynamic< double > &  val 
)

Set a numeric list variable from a given ChVectorDynamic<>.

If a variable with the same name is existing, it is overwritten, otherwise it is created (in main namespace)

◆ SetList() [2/2]

void chrono::parsers::ChPythonEngine::SetList ( const std::string &  variable,
const std::vector< double > &  val 
)

Set a numeric list variable from a given std::vector.

If a variable with the same name is existing, it is overwritten, otherwise it is created (in main namespace)

◆ SetMatrix()

void chrono::parsers::ChPythonEngine::SetMatrix ( const std::string &  variable,
const ChMatrixDynamic< double > &  val 
)

Set a numeric list variable from a given ChMatrixDynamic<>.

If a variable with the same name is existing, it is overwritten, otherwise it is created (in main namespace)

◆ SetString()

void chrono::parsers::ChPythonEngine::SetString ( const std::string &  variable,
std::string &  val 
)

Set a value of a string variable.

If a variable with the same name is existing, it is overwritten, otherwise it is created (in main namespace)


The documentation for this class was generated from the following files:
  • /builds/uwsbel/chrono/src/chrono_parsers/ChParserPython.h
  • /builds/uwsbel/chrono/src/chrono_parsers/ChParserPython.cpp