Page 1 of 1

Retrieving scene graph from simulation

Posted: 06 Feb 2018, 18:06
by Klaus
Hello,

I would like to retrieve the current scene's "scene graph" (https://en.wikipedia.org/wiki/Scene_graph) using the remote API.
To clarify, a very simple example of what I mean is something like this:
  • world
    • pole#0
    • car#0
      • wheel#0
      • wheel#1
      • wheel#2
      • wheel#3
      • chassis#0
Considering a scene with a single car and a pole in it.
I looked into the documentation but failed to find it. Is there a command for that?

Thanks in advance.

Klaus

Re: Retrieving scene graph from simulation

Posted: 08 Feb 2018, 07:49
by coppelia
Hello Klaus,

you don't have such a function directly available from the remote API. But you can call a script function that will handle this for you (with simxCallScriptFunction). In that script function, simply iterate over all objects, for instance with:

Code: Select all

function printHierarchy(objHandle,indent)
    if objHandle~=sim.handle_scene then
        local str=string.rep('    ',indent)..sim.getObjectName(objHandle)
        print(str)
        indent=indent+1
    end
    local directChildren=sim.getObjectsInTree(objHandle,sim.handle_all,1+2)
    for i=1,#directChildren,1 do
        printHierarchy(directChildren[i],indent)
    end
end


function sysCall_init()
    printHierarchy(sim.handle_scene,0)
end
Cheers