Evaluate whether object name exists or not

Typically: "How do I... ", "How can I... " questions
Post Reply
tmalheiro
Posts: 29
Joined: 27 Nov 2015, 22:53

Evaluate whether object name exists or not

Post by tmalheiro »

Hello Coppelia,

How can I evaluate whether an object name exists in scene?
simGetObjectHandle is throwing a Lua runtime error, but from documentation I was expecting it to return -1 on error.

Best,
Tiago

coppelia
Site Admin
Posts: 8371
Joined: 14 Dec 2012, 00:25

Re: Evaluate whether object name exists or not

Post by coppelia »

Hello Tiago,

you have two options:

1. You can disable throwing errors for V-REP API functions if you set variable raiseErrorWithApiScriptFunctions to false in system/usrset.txt. This is not an elegant solution, since an error message will still be output in the status bar.
2. You can use following code:

Code: Select all

    local savedState=simGetInt32Parameter(sim_intparam_error_report_mode)
    simSetInt32Parameter(sim_intparam_error_report_mode,0)
    print(simGetObjectHandle('objectName'))
    simSetInt32Parameter(sim_intparam_error_report_mode,savedState)
Cheers

tmalheiro
Posts: 29
Joined: 27 Nov 2015, 22:53

Re: Evaluate whether object name exists or not

Post by tmalheiro »

Hi coppelia,

Thank you!

Best,
Tiago

elephant
Posts: 8
Joined: 11 Feb 2021, 18:29

Re: Evaluate whether object name exists or not

Post by elephant »

coppelia wrote:
12 Jul 2016, 20:26
Hello Tiago,

you have two options:

1. You can disable throwing errors for V-REP API functions if you set variable raiseErrorWithApiScriptFunctions to false in system/usrset.txt. This is not an elegant solution, since an error message will still be output in the status bar.
2. You can use following code:

Code: Select all

    local savedState=simGetInt32Parameter(sim_intparam_error_report_mode)
    simSetInt32Parameter(sim_intparam_error_report_mode,0)
    print(simGetObjectHandle('objectName'))
    simSetInt32Parameter(sim_intparam_error_report_mode,savedState)
Cheers

5 years later, newest version of coppelia doesnt have this variable. How we do it now, please?

fferri
Posts: 714
Joined: 09 Sep 2013, 19:28

Re: Evaluate whether object name exists or not

Post by fferri »

From sim.getObjectHandle:
objectName: If the name is appended by a "@silentError" suffix, then no error will be output if the object does not exist.
So, sim.getObjectHandle('Floor@silentError')

Post Reply