I would like to place locators on every vertex of a curve then have the locators fallow the curve. The script works fine if the curve is not altered after creation. If the curve is rebuild, add knots or any vertex moved the .worldSpace attribute in the curve shape does not read the new vertex position or number.
botCrvDef = cmds.ls(selection=True)
botCrvDef = botCrvDef[0]
botShapeCrv = cmds.listRelatives(botCrvDef, shapes=True, noIntermediate=True)[0]
# Get the vertex count (CV count)
botVrtxNum = cmds.getAttr(botShapeCrv + ".spans") + cmds.getAttr(botShapeCrv + ".degree")
# Create a locator for each vertex in the curve
for b in range(botVrtxNum):
botVrtxPos = cmds.pointPosition(f"{botCrvDef}.cv[{b}]", world=True)
botVrtxLoc = cmds.spaceLocator(name=f"{botCrvDef}_{b}_Loc")[0]
cmds.xform(botVrtxLoc, worldSpace=True, translation=botVrtxPos)
botPocNode = cmds.createNode("pointOnCurveInfo", name=f"{botCrvDef}_{b}_poc")
param = float(b)
cmds.setAttr(botPocNode + ".parameter", param)
cmds.connectAttr(botPocNode + ".position", botVrtxLoc + ".translate")
# COMMENT THIS LINE OUT AFTER THE CURVE REBUILD.
cmds.connectAttr(botShapeCrv + ".worldSpace[0]", botPocNode + ".inputCurve")
# Scale down locators for better visibility
cmds.setAttr(botVrtxLoc + ".scaleX", 0.1)
cmds.setAttr(botVrtxLoc + ".scaleY", 0.1)
cmds.setAttr(botVrtxLoc + ".scaleZ", 0.1)
Create a EP curve then run this code. This will place a locator on each vertex. If the curve is translated or rotated the locators will fallow. This is great, what Im looking for.
Now remove all locators from the scene. Rebuild the curve or just simply insert 2 knots. Rerun the script. Now one there are locators at the center of the grid.(0,0,0) The curveShape.worldSpce cant read the new position or vert count.
One again remove all locators, comment out line 26 cmds.conectAttr etc. And rerun the code you will notice that all the locators are in the correct space on the curve. But they are not connected to the shape node of the curve. If you try to manually connect the curveShape.worldSpce to the pointOnCurveInfo.inputCurve same problem will occur some locators will receive 0,0,0 as translation.
Why is the curveShape.worldSpace not recognizing the change in vertex count and position? Is there another way to achieve this end result?