I think you are confused about how the logic is working in your code. You
say "inputConnectionCheck" is already a list. But it is *only* a list if
the color attribute for which you are calling listConnections() actually
has destination connections. Otherwise it is None. Just because you put a
print statement inside your for-loop doesn't mean it should still work. You
cannot even being the for-loop over a None value. You even print the
"inputConnectionCheck" value just before hitting the for-loop, so you
should be seeing that when you have selected geometry that uses a shader
with no connections on its color attribute, that you get nothing for that
return value.
That is the reason Nils suggested formatting your call like this:
inputConnectionCheck = cmds.listConnections(colorAttribute,destination
= True) or []
It means that if you call listConnections on an attribute that has no
connection, you will get back None, which means the OR will proceed and
give you an empty list instead. This prevents you from hitting an exception
when you then try to blindly loop on the None type.
Just to help your test a bit, try printing something that is a bit more
easy to see:
inputConnectionCheck = cmds.listConnections(colorAttribute,destination
= True)
print repr(inputConnectionCheck), type(inputConnectionCheck)
Hope that helps clarify it a bit.
On Sun, Jan 12, 2014 at 10:39 AM, Nitin Singh <[email protected]>wrote:
> "inputConnectionCheck" is already a list. I don't know why its giving me
> error. i tried every thing i know, also tried to look online at other
> places didn't found anything.
>
> for loop give error on first run itself.
> when i select a shader with a file node connected to it, it spits out the
> name of the file node and map, what it is suppose to do when it enters for
> loop *BUT *when i select a shader without a file node connected to it, it
> give error as it enters for loop even when i just put a print statement in
> it. and that is very weird to me and have no idea why ..
>
> still trying to figure out :(
>
> i have attached a maya file this time so that you can check . maybe it
> will help you to see what i am doing.
>
> thanks
>
> On Saturday, January 11, 2014 8:09:07 PM UTC+1, Justin Israel wrote:
>
>> I've always found it so annoying that the cmds module has functions that
>> return inconsistently. It makes no sense to me that they wouldn't always
>> just return the empty list. Some functions do it and some don't.
>> On Jan 12, 2014 5:16 AM, "Nils Lerin" <[email protected]> wrote:
>>
>>> The error happends because cmds.listConnections(colorAttribute,destination
>>> = True) returns None because there are no such connections. Do you have
>>> anything connected to the shaders color-attribute?
>>>
>>> If you want the script to work even if nothing is connected to
>>> shader.color you can change:
>>> inputConnectionCheck = cmds.listConnections(colorAttribute,destination
>>> = True)
>>> to
>>> inputConnectionCheck = cmds.listConnections(colorAttribute,destination
>>> = True) or []
>>>
>>> That way the for loop will just not run (because the list will be empty)
>>> but you'll always have a list there.
>>>
>>>
>>> On Sat, Jan 11, 2014 at 5:04 PM, Nitin Singh <[email protected]>wrote:
>>>
>>>> hey Guys,
>>>>
>>>> i m trying to get the color node incoming connection so that i can
>>>> store it for later use,
>>>> ever thing works well before for loop but when i run for loop to chk
>>>> the type then it give me error :
>>>>
>>>> # Traceback (most recent call last):
>>>> # File "<string>", line 12, in <module>
>>>> # File "<string>", line 17, in <module>
>>>> # TypeError: 'NoneType' object is not iterable
>>>>
>>>> and i have no idea how to fix it, please help.
>>>>
>>>> thanks a lot.
>>>> have a good weekend. :)
>>>>
>>>>
>>>>
>>>> import maya.cmds as cmds
>>>>
>>>> # getting the shape node from transform node
>>>> selectedObj = cmds.ls(sl = True )[0]
>>>> selectType = cmds.listRelatives( selectedObj, shapes = True )
>>>> #getting the name of shader connected to it
>>>> listConnect = cmds.listConnections(selectType, type="shadingEngine")[0]
>>>> shadername = (listConnect + ".surfaceShader")
>>>> shader = cmds.listConnections(shadername)[0]
>>>>
>>>> colorAttribute = (shader+".color")
>>>> colorValues = cmds.getAttr(colorAttribute)
>>>> print colorValues
>>>>
>>>> inputConnectionCheck = cmds.listConnections(colorAttribute,destination
>>>> = True)
>>>> print inputConnectionCheck
>>>>
>>>> for incoming in inputConnectionCheck:
>>>> if cmds.objectType( incoming, isType='file'):
>>>> filePath = cmds.getAttr(incoming+".fileTextureName")
>>>> print filePath
>>>> else:
>>>> colorValues = cmds.getAttr(colorAttribute)
>>>> RGBvalues = colorValues[0]
>>>> redValue = RGBvalues[0]
>>>> greenValue = RGBvalues[1]
>>>> blueValue = RGBvalues[2]
>>>> print (redValue, greenValue, blueValue)
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Python Programming for Autodesk Maya" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to [email protected].
>>>> To view this discussion on the web visit https://groups.google.com/d/
>>>> msgid/python_inside_maya/6f64d6a1-4329-4115-b9e0-
>>>> 1aeec25e58ce%40googlegroups.com.
>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Python Programming for Autodesk Maya" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> To view this discussion on the web visit https://groups.google.com/d/
>>> msgid/python_inside_maya/CAGkBUFcGUA8O3JtCsw%3D9%2B8DGPAuGxihXO1rA-
>>> CWRXdyzcWXXTw%40mail.gmail.com.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/1a514087-42e2-4c85-96ad-6f13da26c656%40googlegroups.com
> .
>
> For more options, visit https://groups.google.com/groups/opt_out.
>
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA17w9_7TKD01M78mP9U9adf3DrHfz5KmZwS7pgri0ixVQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.