Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions bindings/Sofa/package/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,25 @@ def _select_bin_with_dll(candidates, dll_names):
if sofapython3_file_test and sofapython3_bin_path:
os.environ['PATH'] = sofapython3_bin_path + os.pathsep + os.environ.get('PATH', '')

# Set the Current Working Directory of the process with the path of the scene file.
# (to be consistent with the original runSofa)
def get_entry_script():
# Try the main module's __file__ first (works for -m and normal scripts)
import __main__
if hasattr(__main__, '__file__'):
return os.path.abspath(__main__.__file__)

# Fallback to sys.argv[0] if available
if sys.argv[0]:
return os.path.abspath(sys.argv[0])

# Interactive shell or unknown context
return None

entry_point = get_entry_script()
if entry_point:
os.chdir(os.path.abspath(os.path.dirname(entry_point)))

print("---------------------------------------")
if sys.stdout is not None:
sys.stdout.flush()
Expand Down
Loading