Changing object geometry through Python API

Typically: "How do I... ", "How can I... " questions
Post Reply
Posts: 2
Joined: 02 Jan 2019, 09:04

Changing object geometry through Python API

Post by fraserprice » 12 Jan 2019, 23:23

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?

Site Admin
Posts: 7020
Joined: 14 Dec 2012, 00:25

Re: Changing object geometry through Python API

Post by coppelia » 16 Jan 2019, 08:32


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

Post Reply