Yea thats an issue with the usage of partial in this cirumstance. partial()
creates a closure over the parameters that you pass. That means the light list
you give it, is the light list. If your function needs to get the list of
lights every time it is evaluated then you will want to direct it to a callback
that produces these lists on demand, instead of being part of your callback:
###
checkBox = cmds.checkBox('Double Side')
cbk = partial(processCallback, light_editor.box_on, litinv, "invisible")
cmds.checkBox(checkBox, e=True, onc= cbk, ofc=cbk)
def processCallback(callback, param1, param2):
lightsAll = getAllLights()
lightsSel = getSelectedLights()
callback(param1, param2, lightsAll, lightsSel)
###
Referring to that error you mention... I know that cmds.listRelatives can
return a None if nothing was found, so you should probably be checking and
handling that error condition. If you don't care and don't want to do anything
if there aren't any results, then you can just do:
transform = cmds.listRelatives(myLight, p=True) or []
That will ensure transform is always a list, and won't cause the error when you
try to loop over an empty result.
On Sep 14, 2013, at 9:33 PM, Daz wrote:
> Hey Justin
>
> Yea I was trying to build a callable out of 2 strings so that I can input
> different modules with different functions. Atm for that test there really
> was no more code than that. For the moment I dropped the idea of making it
> shorter until I understand partial more. Its proving bit more difficult than
> I want it too and I think I will use it a lot in my scripts from now on so I
> need to study it more.
>
> In any case could you possible show me an example how I would write this in
> partial?
>
> litinv =
> cmds.checkBox("Invisible",onc='box_on(litinv,"invisible",lightsAll,lightsSel)',ofc='box_off(litinv,"invisible",lightsAll,lightsSel)')
>
> My attempts failed badly.
> litDS = cmds.checkBox('Double Side')
> litDS_cbk = partial(light_editor.box_on, litDS, "doubleSided", lightsAll,
> lightsSel)
> cmds.checkBox(litDS,e=True,cc=litDS_cbk)
>
> Also I just found one issue with my script, pretty strange one as that did
> not happen in past. In any case with the slider if I have 5 lights in my
> scene. I want to edit their intensity and so on it works just fine. However
> the second I add 1 extra light. The extra light is not affected any more. Its
> as if he don't re-evaluate the scene and I cant control it- I can control old
> lights but not the new one. Can you have a look at this code see if you spot
> obvious issue?
>
> I'm using Vray lights and its pretty random. Errors I get :
> # Error: 'NoneType' object is not iterable
> # Traceback (most recent call last):
> # File "D:/Scripts/maya/scripts/Daz_Toolkit/Fin/Modules\light_editor.py",
> line 23, in lit_value
> # for shapes in transform:
> # TypeError: 'NoneType' object is not iterable #
> # Error: setAttr: Not enough data was provided. The last 0 items will be
> skipped.
>
> # Traceback (most recent call last):
> # File "D:/Scripts/maya/scripts/Daz_Toolkit/Fin/Modules\light_editor.py",
> line 14, in lit_value
> # cmds.setAttr(shapes+'.'+attribute,value)
> # RuntimeError: setAttr: Not enough data was provided. The last 0 items will
> be skipped. #
> http://pastebin.com/8N9wgWQR
> Thanks, bye.
>
> --
> 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 post to this group, send email to [email protected].
> 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 post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.