Description
Class for a Python parser.
This is an interpreter that can parse Python programs, from a single formula up to large programs.
#include <ChPython.h>
Public Member Functions | |
ChPythonEngine () | |
Create a Python parser: an interpreter that can parse Python programs, from a single formula up to large programs. More... | |
void | Run (const char *program) |
Execute a program. More... | |
bool | GetFloat (const char *variable, double &return_val) |
Retrieve a value of an existing floating point variable. More... | |
void | SetFloat (const char *variable, const double val) |
Set a value of a floating point variable. More... | |
bool | GetInteger (const char *variable, int &return_val) |
Retrieve a value of an existing integer variable. More... | |
void | SetInteger (const char *variable, const int val) |
Set a value of a integer variable. More... | |
bool | GetBool (const char *variable, bool &return_val) |
Retrieve a value of an existing bool variable. More... | |
void | SetBool (const char *variable, const bool val) |
Set a value of a bool variable. More... | |
bool | GetString (const char *variable, std::string &return_val) |
Retrieve a value of an existing string variable. More... | |
void | SetString (const char *variable, std::string &val) |
Set a value of a string variable. More... | |
void | ImportSolidWorksSystem (const char *solidworks_py_file, ChSystemNSC &msystem) |
Load a .py file as it is saved by the SolidWorks add-in exporter. More... | |
Constructor & Destructor Documentation
◆ ChPythonEngine()
chrono::ChPythonEngine::ChPythonEngine | ( | ) |
Create a Python parser: an interpreter that can parse Python programs, from a single formula up to large programs.
NOTE!!! currently only one instance at a time can be created.
Member Function Documentation
◆ GetBool()
bool chrono::ChPythonEngine::GetBool | ( | const char * | variable, |
bool & | return_val | ||
) |
Retrieve a value of an existing bool variable.
Returns false if unsuccesfull.
◆ GetFloat()
bool chrono::ChPythonEngine::GetFloat | ( | const char * | variable, |
double & | return_val | ||
) |
Retrieve a value of an existing floating point variable.
Returns false if unsuccesfull.
◆ GetInteger()
bool chrono::ChPythonEngine::GetInteger | ( | const char * | variable, |
int & | return_val | ||
) |
Retrieve a value of an existing integer variable.
Returns false if unsuccesfull.
◆ GetString()
bool chrono::ChPythonEngine::GetString | ( | const char * | variable, |
std::string & | return_val | ||
) |
Retrieve a value of an existing string variable.
Returns false if unsuccesfull.
◆ ImportSolidWorksSystem()
void chrono::ChPythonEngine::ImportSolidWorksSystem | ( | const char * | solidworks_py_file, |
ChSystemNSC & | msystem | ||
) |
Load a .py file as it is saved by the SolidWorks add-in exporter.
You can pass a path too, ex "mydir/myotherdir/mysystem", but do NOT add .py at the end! That .py file, created when pressing the add-in button in SolidWorks CAD, contains a python program that creates an equivalent mechanism in Chrono: so it contains a sequce of creations of ChPhysicsItem objects (bodies, links, etc.). If you want to add these python C::E objects to your ChSystem that you created in a C++ program, call this function: it will parse the .py textblock and add the created items to the ChSystem. If fails, it throws an exception, so it is wise to put it inside try..catch blocks.
Add the ChPhysicsItem to the ChSystem
◆ Run()
void chrono::ChPythonEngine::Run | ( | const char * | program | ) |
Execute a program.
If fails, it throws an exception, so it is wise to put it inside try..catch blocks.
◆ SetBool()
void chrono::ChPythonEngine::SetBool | ( | const char * | 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::ChPythonEngine::SetFloat | ( | const char * | 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::ChPythonEngine::SetInteger | ( | const char * | 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)
◆ SetString()
void chrono::ChPythonEngine::SetString | ( | const char * | 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_python/ChPython.h
- /builds/uwsbel/chrono/src/chrono_python/ChPython.cpp