Page 1 of 1

Changing object geometry through Python API

Posted: 12 Jan 2019, 23:23
by fraserprice
I am writing a reinforcement learning task which requires programmatic modifications to the geometry of objects in my scene; this will be before simulation starts.

For example, I wish to set the z-coordinate length of a cuboid (in it's own frame).

Is this possible to do through the Python API?

Re: Changing object geometry through Python API

Posted: 16 Jan 2019, 08:32
by coppelia

yes, you can do this in following way: on the python remote API client side, call simxCallScriptFunction. The call needs to be directed to a customization script, if called when simulation is not running.
Inside of the called function, in the customization script, you can appropriately call sim.scaleObject. You might have to previously gather the current object size if you want to set a specific size, instead of just scaling the object. Following could help:

Code: Select all

function model.setObjectSize(h,x,y,z)
    local r,mmin=sim.getObjectFloatParameter(h,sim.objfloatparam_objbbox_min_x)
    local r,mmax=sim.getObjectFloatParameter(h,sim.objfloatparam_objbbox_max_x)
    local sx=mmax-mmin
    local r,mmin=sim.getObjectFloatParameter(h,sim.objfloatparam_objbbox_min_y)
    local r,mmax=sim.getObjectFloatParameter(h,sim.objfloatparam_objbbox_max_y)
    local sy=mmax-mmin
    local r,mmin=sim.getObjectFloatParameter(h,sim.objfloatparam_objbbox_min_z)
    local r,mmax=sim.getObjectFloatParameter(h,sim.objfloatparam_objbbox_max_z)
    local sz=mmax-mmin