## How Do I Load scenes using vrep-api-python ?

Typically: "How do I... ", "How can I... " questions
psychemedia
Posts: 11
Joined: 09 Sep 2017, 01:10

### How Do I Load scenes using vrep-api-python ?

I'm new to V-REP, just trying to get to grips with it, and looking to use it from Python (to which end, I put together a VM containing VREP + Jupyter notebooks here: https://github.com/psychemedia/ou-robot ... er/robotVM).

One thing I can't see to do offhand is open a scene into V-REP. Here's script I guessed at:

Code: Select all

from pyrep import VRep
from pyrep.vrep import vrep as v
from pyrep.common import ReturnCommandError

def __init__(self, api: VRep):
self._api = api
self._def_op_mode = v.simx_opmode_oneshot_wait
self.id = api._id

clientID=self.id
res = simxLoadScene(clientID, path, 0xFF, self._def_op_mode)
print(res)

if res != v.simx_return_ok:
raise ReturnCommandError(res)

scene='/vagrant/scenes/Pioneer.ttt'
with VRep.connect("127.0.0.1", 19997) as api:
r.loadScene(scene)
Repost of question on SO: https://stackoverflow.com/questions/461 ... api-python

coppelia
Posts: 7917
Joined: 14 Dec 2012, 00:25

### Re: How Do I Load scenes using vrep-api-python ?

Hello,

what is the returned res? Also, did you try to specify the absolute path the the file. From what I remember, the path can be absolute, but also relative to the V-REP's installation folder.

Cheers

psychemedia
Posts: 11
Joined: 09 Sep 2017, 01:10

### Re: How Do I Load scenes using vrep-api-python ?

Hi

I get response: 8

I am trying to load a file in using an absolute path.

If I try using a relative path to the simulator homedir (os.environ["VREP"]), I get error 32 (client side error).

coppelia
Posts: 7917
Joined: 14 Dec 2012, 00:25

### Re: How Do I Load scenes using vrep-api-python ?

The first error code means there was an error on the server side (i.e. V-REP), the second error code means there was an error on the client side (i.e. remote API client).

Cheers

psychemedia
Posts: 11
Joined: 09 Sep 2017, 01:10

### Re: How Do I Load scenes using vrep-api-python ?

Re: error codes: yes, I get that; but I'm not sure what I'm doing wrong / how to chase the error down?

coppelia
Posts: 7917
Joined: 14 Dec 2012, 00:25

### Re: How Do I Load scenes using vrep-api-python ?

Did you try to load the scene if it is located directly in the same folder as your remote API client or V-REP installation folder.
I have just tested (on windows) and following works:

Code: Select all

import vrep

print 'Program started'
vrep.simxFinish(-1) # just in case, close all opened connections
clientID=vrep.simxStart('127.0.0.1',19997,True,True,5000,5)
if clientID!=-1:
print 'Connected to remote API server'
# relative to remote API client location, relative path:
# relative to V-REP executable location, relative path:
# relative to remote API client location, absolute path:
# relative to V-REP executable location, absolute path:
vrep.simxFinish(clientID)
else:
print 'Failed connecting to remote API server'
print 'Program ended'
Cheers

psychemedia
Posts: 11
Joined: 09 Sep 2017, 01:10

### Re: How Do I Load scenes using vrep-api-python ?

Hi

Thanks for that - seems to work (on my Mac) with each combination except for the path relative to the simulator install directory which is perhaps something to do with the environment variable setting?

I also think not closing all opened connections was breaking things when I tried.

Thanks,
--tony