Maybe this thread and related links can help:
But as @sebavan explained, creating rigged meshes by code is not an easy task…