It's not actually that weird when you think about it.  The loop is not causing 
an error because you are asking it not to raise one. One should be very 
cautious about using a blanket statement "try...except: pass" in code. It makes 
it very very hard to debug problems when they are nested in your code. When you 
use try..except, you should be catching specific exceptions that you know could 
be raised, and that you want to handle.

selected = cmds.ls(sl=1)
for objects in selected:
   try:
      cmds.SeparatePolygon(objects) 
   except:
      pass

If `cmds.SeparatePolygon(objects)` fails for any reason whatsoever, you are 
catching that exception and simply ignoring it. The result is it would fly 
through the loop and you don't really know what happened with each operation. 

Let's assuming you had some critical steps that had to happen one after the 
next:

#
try:
    setup_something_important()
except:
    pass

do_something_with_the_setup()
#

You would never know that the setup failed, and would move right on to the next 
part that relied on the previous steps success.
Trivial example:

try:
    my_val = 1/0
except ZeroDivisionError, e:
    print "We failed to divide the numbers with error: %s" % e 
    my_val = 10

We know that our operation could potentially divide by zero, so we catch that 
kind of exception, warn, and set some default value. The point is that we 
actually are specifically handling an exceptional case.

Hope that help!

-- justin



On Nov 21, 2012, at 6:04 AM, Daz wrote:

> Heya
> 
> Got rather weird problem I thought it would go without problems but it get 
> stuck on 1st object it try to edit.
> 
> In any case trying to separate all selected objects and I get no error/good 
> result. It fails on 1st object and ignore rest...
> 
> http://pastebin.com/7kz3YfiG
> 
> Any hints why I'm hitting a wall with it ? :/
> 
> -- 
> view archives: http://groups.google.com/group/python_inside_maya
> change your subscription settings: 
> http://groups.google.com/group/python_inside_maya/subscribe

-- 
view archives: http://groups.google.com/group/python_inside_maya
change your subscription settings: 
http://groups.google.com/group/python_inside_maya/subscribe

Reply via email to