Page 1 of 1

How to save the object created by simAddDrawingObject into ttt?

Posted: 10 May 2018, 03:18
by Plug
Hi,

I draw some lines by simAddDrawingObject in customization script but fail to save them into ttt(it seems "save scene" doesn't work for such lines), so that when open the vrep and load the ttt next time, these lines disappears.
Is there anyway to same them into ttt? (for example, is it possible to create a point cloud with such drawing object?)

Re: How to save the object created by simAddDrawingObject into ttt?

Posted: 11 May 2018, 07:56
by coppelia
Hello,

for point clouds, don't use drawing objects but point clouds directly.
Drawing objects cannot be saved. What you however can do is following:

in the init phase of your script, read the coordinates of lines you have previously drawn, e.g.:

Code: Select all

function sysCall_init()
    h=sim.getObjectAssociatedWithScript(sim.handle_self)
    lineContainer=sim.addDrawingObject(sim.drawing_lines,1,0,-1,9999)
    local data=sim.readCustomDataBlock(h,'myLines')
    if data then
        sim.writeCustomDataBlock(h,'myLines',nil)
        data=sim.unpackTable(data)
        drawLines(data)
    end
end

function drawLines(coordinates)
    local data=sim.readCustomDataBlock(h,'myLines')
    if data then
        data=sim.unpackTable(data)
    else
        data={}
    end
    for i=1,#coordinates/6,1 do
        local l={}
        for j=1,6,1 do
            l[j]=coordinates[(i-1)*6+j]
            data[#data+1]=l[j]
        end
        sim.addDrawingObjectItem(lineContainer,l)
    end
    sim.writeCustomDataBlock(h,'myLines',sim.packTable(data))
end
the line data will be saved together with the object (actually stored inside of the object as a custom data block).

Cheers