PDA

View Full Version : MEL: "catch" command frequency


bentllama
12-09-2002, 06:26 PM
using the "catch" command:

ie: catch (`select -add "f_hip"`);

Q: Is it wrong to use the "catch" command very frequently in a script? I have heard it may slow it down a bit, but I need a way of perfoming an action IF an object exists in a scene..."catch" seems like the easiest way to do that with the least amount of lines of code...

What is your opinion on this?

Thanks.

alexx
12-09-2002, 07:33 PM
when i was quite unexperienced in maya and mel i used catch from time to time as well.
but honestly i havent used it in the last 3 years and in that time i wrote several 10000 lines of mel code for sure.

as you mentioned there is no need for you to check for an object before doing e.g. that select operation.. catch will mostly do the job. i recognized that catch does not 100% work.. in some cases i was not able to use the catch return value for further actions.. that might be solved by now but still i think it is no good style.

if i get a warning or error message in a script i need to know what was wrong.
imagine a script that generates 10 errors and 20 warnings.. i dont want to debug that one for a REAL error.
and further imagine other ppl working with your scripts.. they will really be distracted when they see all those error messages..

i havent encountered something that could not be done without a catch.
and it is always a good idea to do all neccessary checks before performing an operation. then you can be 100% sure, your script does what it should in all cases and not maybe in most cases..

hope that helped

cheers

alexx

bentllama
12-09-2002, 08:09 PM
Perhaps I should have stated what I am using the "catch" for...

The scripts I am authouring with "catch" are hard-coded for specific character structures in our game. For the most part these scripts are used to attach character meshes to game skeletons, general parenting, auto-rig, etc...

eg: catch (`parent m_r_toe b_r_toe`); //parent mesh to skel

We have X number of characters and they share the same naimg convention scheme...

Therefore I need to do the same functions to most characters but need to account for slight differences in heirarchy and node structure between characters.

For instance, one character could have a regular human hand while the other could have something more alien. I need to account for that node difference without having to augment each separate character script. I am not collecting attr data for use elsewhere in these scripts...and if I was doing that a simple IF statement would suffice.

Perhaps I am jhust being lazy here and an IF statement is better. I just thought that "catch" requires one line and is generally accepted to be OK.

So given the new knowledge about my situation, do you have a different opinion?

Thanks again for responding, alexx. I appreciate it. :D

alexx
12-09-2002, 08:13 PM
testing for the existance of an object is one line as well.. sorry have no maya here otherwise i would quick check for the command..

i think in your case it is mostly a matter of style.. i would not code it that way but i think you wont have any problems if you will do so :)

cheers

alexx

alexx
12-10-2002, 12:39 PM
objExists is the command of choice

cheers

alexx

bentllama
12-10-2002, 04:10 PM
Originally posted by alexx
objExists is the command of choice


I use that for somethings, but it can get to be alot of lines of code to query if a node exists [I will have many files with vastly different nodes within each]

...three lines to query an ojbect's existence and do the function I want IF it does exist...maybe I am just being lazy :D

Thanks again for the reply! :beer:

CGTalk Moderation
01-13-2006, 11:00 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.