Page 1 of 1

Object handle error

Posted: 26 Mar 2020, 03:11
by robo_ninja
I have created 100 cubes in a scenario with names Cube_1, Cube_2, Cube_3 ...... so on ...... Cube_100. Now I want to retrieve object handle for each of these cubes inside a function. My portion of code inside the function where I am trying to calculate contact forces for each box -

Code: Select all

  for i = 0, 100, 1 do
    local force = 0
    local SumF = 0
    local forceMax = 0

      objectsInContact,_,forceDirectionAndAmplitude = sim.getContactInfo(sim.handle_all, sim.getObjectHandle("Box"..i), index)
        force = (math.abs(forceDirectionAndAmplitude[1])+math.abs(forceDirectionAndAmplitude[2])+math.abs(forceDirectionAndAmplitude[3]))/10
        SumF = SumF + force
        print("Force : ".. SumF)
Everytime I call the function, I get the following error -
Object does not exist. (sim.getObjectHandle)
Can you help please?

Re: Object handle error

Posted: 26 Mar 2020, 08:46
by fferri
You say you have cubes with names Cube_1, Cube_2, Cube_3 ... Cube_100.

Your code will call sim.getObjectHandle with arguments Box0, Box1, Box2, ... Box100.

Does that ring a bell?

Re: Object handle error

Posted: 26 Mar 2020, 10:35
by coppelia

Re: Object handle error

Posted: 26 Mar 2020, 12:34
by robo_ninja
Sorry for the typo. I had changed it in my code -

Code: Select all

 objectsInContact,_,forceDirectionAndAmplitude = sim.getContactInfo(sim.handle_all, sim.getObjectHandle("Cube_"..i), index)
But still keep getting the same error.

I created a dummy object "Cube" and associated script with the function. Still get the error. Do I have to make the dummy object parent of all the cubes?

Thanks

Re: Object handle error

Posted: 30 Mar 2020, 09:52
by coppelia
Please post a minimalistic scene that illustrates your problem.

Cheers