Object handle error

Typically: "How do I... ", "How can I... " questions
Post Reply
robo_ninja
Posts: 15
Joined: 07 May 2018, 20:01

Object handle error

Post 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?

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

Re: Object handle error

Post 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?

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

Re: Object handle error

Post by coppelia »


robo_ninja
Posts: 15
Joined: 07 May 2018, 20:01

Re: Object handle error

Post 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

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

Re: Object handle error

Post by coppelia »

Please post a minimalistic scene that illustrates your problem.

Cheers

Post Reply