Reputation: 11
I have a field of Spot Lights and am trying to use pm.aimConstraint
to link their target to a locator (called "Light Point"). Here's the section that I'm struggling with and the error it gives me:
import pymel.core as pm
aimTarget = "Light Point"
selection = pm.ls(sl = True)
for each in selection:
pm.aimConstraint(aimTarget, each)
Error: MayaNodeError: file C:\Program Files\Autodesk\Maya2013\Python\lib\site-packages\pymel\internal\pmcmds.py line 140: #
Obviously the selection is all the Spot Lights.
Ideally I would like to do this without having to select all the lights, which I think would look something like this:
pm.aimConstraint("Light Point", "spotLight"+light)
"light" being the number of lights in the range of a for loop, converted to a string. This gets the same error.
I am still very new to python, but have used the first script before and am very confused why it won't work on anything, not even just the spotlights.
Upvotes: 0
Views: 632
Reputation: 492
I realize this is an older post but should anyone else sees it,
PyMEL has the PyNode()
function. So if you were to pass "Light Point" through there it will return the object in the scene.
i.e.
from pymel.core import *
PyNode("myCube")
# Result: nt.Transform(u'myCube') #
Upvotes: 0
Reputation: 4434
"Light Point" is not a valid object name.
When you create nodes in Maya you need to capture the object that your given on creation otherwise there's no guarantee that its the object you think it is.
Upvotes: 1