0

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.

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199

2 Answers2

1

"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.

joojaa
  • 4,354
  • 1
  • 27
  • 45
  • When the Locator is made it is renamed "Light POint". However, I have now realised that it infact gets named Light_Point. So this has been adjusted. For some reason the script is now working. I am still unclear as to why, so any explanations are welcome!! – user2153909 Mar 10 '13 at 16:10
  • 1
    space is a invalid character in the name of a object. Maya will just rewrite it to a underscore _. – joojaa Mar 10 '13 at 16:20
0

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') # 
Argiri Kotsaris
  • 492
  • 3
  • 7