Hi Vanessa, All Chrono demos, as they are distributed, assume a certain location of the data/ directory, relative to where the demo is located and run from. Running the demo through the Python script does not respect this anymore and as such, the underlying (unmodified) Chrono demo cannot find files in the data/ directory. Whatever demos you say you were able to run from your Python script do not attempt to use any files from the Chrono data/ directory (as is the case with demo_IRR_raycast_test).
The solution is to modify the C++ code to make an explicit call to chrono::SetChronoDataPath() and provide the location of the data/ directory you wish to use. In general, I strongly suggest not to modify demos inside the Chrono distribution. Those are set up the way they are so that they can run from the location where they are built (and only from there), regardless of the particular user setup. What you should do is copy the Chrono demo you are interested in somewhere else and then set it up as an external project. Look at the sample we provide in template_project<https://github.com/projectchrono/chrono/tree/main/template_project> and the additional instructions at https://api.projectchrono.org/tutorial_install_project.html. When you do this, make sure to modify the copied demo so that it makes a call to SetChronoDataPath() before any other calls to Chrono library functions, just as is done in my_example.cpp<https://github.com/projectchrono/chrono/blob/2c254b61fb8cf3111f2430565e2836a32e5e21cd/template_project/my_example.cpp#L30> at line 30 and point it to, say, the data/ directory in the Chjrono source tree. If you set that to an absolute path, you should then be able to invoke the resulting executable from your Python script, regardless of the relative locations of the Chrono executable and the Python script. --Radu From: [email protected] <[email protected]> On Behalf Of Vanessa Hernandez-Cruz Sent: Friday, July 21, 2023 5:45 AM To: ProjectChrono <[email protected]> Subject: [chrono] Error reading .obj files with subprocess.run() Hello, I am trying to run a Chrono executable file from a python script. The .py script works only when the executable is NOT reading an object file in the .cpp code (I have tried other .exe files that involve .obj files). I am able to run the .py script for files such as "demo_IRR_raycast_test", so I know that the code is working as intended. I do not get any error when running the Viper SCM terrain executable through Microsoft Visual Studio, the error only arises when using the .py script. I am attaching one of the .obj files I am using in my Viper SCM code to run a demo of Viper on sloped terrain. "error_message_chrono2" is the error that shows up when running my .py script. "importobjfileinchrono" is the snippet of code in demo_ROBOT_Viper_SCM.cpp that I am using to import my terrain through an object file. "openchronopycode" is my code to start the desired Chrono executable. Please let me know if you have some insight on potential fixes to this bug. Thank you. Best, Vanessa -- You received this message because you are subscribed to the Google Groups "ProjectChrono" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]<mailto:[email protected]>. To view this discussion on the web visit https://groups.google.com/d/msgid/projectchrono/ebe1d031-e02a-4474-bac0-16bdd8558f0bn%40googlegroups.com<https://groups.google.com/d/msgid/projectchrono/ebe1d031-e02a-4474-bac0-16bdd8558f0bn%40googlegroups.com?utm_medium=email&utm_source=footer>. -- You received this message because you are subscribed to the Google Groups "ProjectChrono" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/projectchrono/PH0PR06MB82376993B4BD55C8C91C050DA73FA%40PH0PR06MB8237.namprd06.prod.outlook.com.
