The code worked fine for me. I did run through it and add some comments and additional description.
What happens when you try to run it? Do you get an error? Does it do nothing? Or does it do something incorrectly?
One thing to note about the conversion from lattice to skinCluster (at least the way that this script does it) is that rotation may not behave as expected.
This is an example scene that I ran the scene in. In the below you see what happens when I translate a joint. In RED is the result that the lattice produces originally produced. And in BLACK you can see the result the new skinCluster produced the exact same results.

In this second image you see the result of rotating that joint instead. The lattice and skinCluster do not produce the same result.

You will end with some useful weights either way but if rotation is involved the results won't be identical.
If you have a single non-rotating joint per point on the lattice though. Then the conversion will be identical.
A conversion method that may be better would be to attach a joint to each point of the lattice that has the same influence on the final mesh as that lattice point.
Anyway here is the commented version of the code.
'''
#Lattice weights transfer to skincluster
Data : April 11, 2017
last modified : April 15, 2017
Author : Subin Gopi
subing85@gmail.com
Description :
Select a lattice that is modifed by a skinCluster.
This script will convert the deformations done by the lattice,
into skinCluster deformation.
There will be differences in the result if the lattice is
deformed by joints that rotate.
Input : mesh > lattice > skincluster
Maya version : Maya 2016
'''
import maya.api.OpenMaya as om
import maya.api.OpenMayaAnim as oma
import maya.cmds as cmds
def convertLatticeToSkinCluster():
selectList = cmds.ls (sl=1)
latticeShape = cmds.listRelatives (selectList[0], type='lattice')[0]
ffd = cmds.listConnections (latticeShape, type='ffd')[0]
skincluster = cmds.listConnections (latticeShape, type='skinCluster')[0]
geometry = cmds.lattice (latticeShape, q=1, g=1)[0]
jointList = cmds.skinCluster (skincluster, q=1, inf=1)
meshMSelection = om.MSelectionList ()
meshMSelection.add (geometry)
meshDagPath = meshMSelection.getDagPath (0)
mFnMesh = om.MFnMesh (meshDagPath)
geoPosition = mFnMesh.getPoints (om.MSpace.kObject)
weightList = []
for index in range (len(jointList)) :
jntParent = cmds.listRelatives (jointList[index], p=1)
jntChild = cmds.listRelatives (jointList[index], c=1)
if jntParent :
cmds.parent (jointList[index], w=1)
if jntChild :
cmds.parent (jntChild[0], w=1)
jointMSelection = om.MSelectionList ()
jointMSelection.add (jointList[index])
jointDagPath = jointMSelection.getDagPath (0)
mFnTransform = om.MFnTransform (jointDagPath)
world = mFnTransform.translation (om.MSpace.kWorld)
moveWorld = om.MVector (world.x + 1, world.y, world.z)
mFnTransform.setTranslation (moveWorld, om.MSpace.kWorld)
movePosition = mFnMesh.getPoints (om.MSpace.kObject)
jointWeights = []
for vertexIndex in range (len(movePosition)) :
length = movePosition[vertexIndex] - geoPosition[vertexIndex]
weight = length.length ()
jointWeights.append (weight)
weightList.append (jointWeights)
mFnTransform.setTranslation (world, om.MSpace.kWorld)
if jntParent :
cmds.parent (jointList[index], jntParent[0])
if jntChild :
cmds.parent (jntChild[0], jointList[index])
geoSkinCluster = cmds.skinCluster (jointList, geometry)[0]
skinMSelection = om.MSelectionList ()
skinMSelection.add (geoSkinCluster)
skinMObject = skinMSelection.getDependNode (0)
mfnSkinCluster = oma.MFnSkinCluster (skinMObject)
vertexIndexList = range (len(geoPosition))
mfnIndexComp = om.MFnSingleIndexedComponent ()
vertexComp = mfnIndexComp.create (om.MFn.kMeshVertComponent)
mfnIndexComp.addElements (vertexIndexList)
influenceObjects = mfnSkinCluster.influenceObjects ()
influenceList = om.MIntArray ()
for eachInfluenceObject in influenceObjects :
currentIndex = mfnSkinCluster.indexForInfluenceObject (eachInfluenceObject)
influenceList.append (currentIndex)
mWeightList = om.MDoubleArray ()
for wIndex in range (len(weightList[0])) :
for jntIndex in range (len(weightList)) :
mWeightList.append (weightList[jntIndex][wIndex])
mfnSkinCluster.setWeights (meshDagPath, vertexComp, influenceList, mWeightList)
cmds.setAttr ('%s.envelope' % skincluster, 0)
cmds.setAttr ('%s.envelope' % ffd, 0)