User config callback functions

A customization script that includes a user config callback function (which is one of many system callback functions), will display a configuration dialog icon, in the scene hierarchy:

[Configuration dialog icon]


When double-cliked, the user config callback function is triggered. This can be used as a convenient way of displaying a custom user interface to the user, that is specific to the object/model the customization script is attached to. User data can be read and written to objects with sim.readCustomDataBlock/sim.writeCustomDataBlock for instance:

[Custom configuration dialog]


function sysCall_init() modelHandle=sim.getObject('.') end function sysCall_userConfig() local xml =[[<ui title="Robot" closeable="true" modal="true" layout="form" on-close="customUiClosed"> <label text="Max. velocity:" /> <edit id="1" value="-" on-editing-finished="velocityChanged"/> <label text="Max. acceleration:" /> <edit id="2" value="-" on-editing-finished="accelerationChanged"/> </ui>]] local ui=simUI.create(xml) local data=readData() simUI.setEditValue(ui,1,tostring(data.maxVel)) simUI.setEditValue(ui,2,tostring(data.maxAccel)) end function customUiClosed(ui) simUI.destroy(ui) end function velocityChanged(ui,id,val) local data=readData() val=tonumber(val) if val then if val<0.1 then val=0.1 end if val>0.5 then val=0.5 end data.maxVel=val end simUI.setEditValue(ui,id,tostring(data.maxVel)) writeData(data) end function accelerationChanged(ui,id,val) local data=readData() val=tonumber(val) if val then if val<0.01 then val=0.01 end if val>0.2 then val=0.2 end data.maxAccel=val end simUI.setEditValue(ui,id,tostring(data.maxAccel)) writeData(data) end function readData() local data=sim.readCustomDataBlock(modelHandle,'RobotParams') if data then data=sim.unpackTable(data) else data={} data.maxVel=0.2 data.maxAccel=0.05 end return data end function writeData(data) sim.writeCustomDataBlock(modelHandle,'RobotParams',sim.packTable(data)) end