Today I worked on implementation of snapPoints and nearestPointOnPath function
Here is the working Lua code


lines = {}

function snapPoints(a, b, c, d)
    local points = {}
    table.insert(points, EntityCoordinate(Coordinate(0, 0, 0), 0))
    table.insert(points, EntityCoordinate(Coordinate(100, 0, 0), 1))
    table.insert(points, EntityCoordinate(Coordinate(100, 10, 0), 2))
    table.insert(points, EntityCoordinate(Coordinate(0, 10, 0), 3))
    return points
end

function nearestPointOnPath(coord)
    local point
    local distance

    for i, line in pairs(lines) do
        local tmp = line:nearestPointOnPath(coord)
        local tmpDistance = coord:distanceTo(tmp)

        if(point == nil or tmpDistance < distance) then
            point = tmp
            distance = tmpDistance
        end
    end

    return point
end

b = Builder(document, "Add Rectangle")
ce = CustomEntityStorage("LC Plugin", "Rectangle", Coordinate(0, 0, 0))

b:append(AddBlock(document, ce))

eb = EntityBuilder(document)
b:append(eb)

lb = LineBuilder()
lb:setLayer(document:layerByName("0"))
lb:setBlock(ce)
lb:setStart(Coordinate(0, 0, 0))
lb:setEnd(Coordinate(100, 0, 0))

lines[1] = lb:build()
eb:appendEntity(lines[1])

lb:setStart(Coordinate(100, 10, 0))
lines[2] = lb:build()
eb:appendEntity(lines[2])

lb:setEnd(Coordinate(0, 10, 0))
lines[3] = lb:build()
eb:appendEntity(lines[3])

lb:setStart(Coordinate(0, 0, 0))
lines[4] = lb:build()
eb:appendEntity(lines[4])

b:execute()

ceb = CustomEntityBuilder()
ceb:setLayer(document:layerByName("0"))
ceb:setCoordinate(Coordinate(0, 0, 0))
ceb:setDocument(document)
ceb:setDisplayBlock(ce)
ceb:setSnapFunction(snapPoints)
ceb:setNearestPointFunction(nearestPointOnPath)

eb = EntityBuilder(document)
eb:appendEntity(ceb:build())
eb:execute()