Checking if an object exists

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
  03 March 2003
Checking if an object exists

I'm writing a script at the moment that will check whether certain objects exist in the current scene....

I'm currently doing it with the following procedure:

PHP Code:
 global proc int findObject(string $name)
{
    
select -r $name;
    
$object = `ls -sl`;
    if(
size($object) == 0)
    {
        print(
"Failed to find "+$name+"\n");
        return 
0;
    }
    else
        return 
1;



However, if it finds that an object doesn't exist, the select command gives an error, and no more of the script is executed....

Is there any way of getting around this without writing my own stuff to go through all of the objects in the scene?
__________________
Hugh Macdonald
nvizible
 
  03 March 2003
try this ...


     if (`exists $obj`)
     {
              //do funny stuff
     };


$obj is the object that you wanna ask if it exist
__________________
| xt_textureStudio | xt_prefabLibrary |xt_normalis | Get it @ Fuchtelworld V.3 |
 
  03 March 2003
ah - okay - I'll give that a go...

When I looked in the MEL reference, it said that 'exist' was for checking if a function existed....
__________________
Hugh Macdonald
nvizible
 
  03 March 2003
oh damn, you're right ... i must lern to read the description first =D ...

but try this =D

objExists $objectname;

thats works .. you get 0 back if it not exist or 1 if it exist .. have fun ..
__________________
| xt_textureStudio | xt_prefabLibrary |xt_normalis | Get it @ Fuchtelworld V.3 |
 
  03 March 2003
thanks!

I did go the route you thought at first...

What would be great would be to somehow catch the error that select gives out...

Edit: Nice - thanks - I hadn't come across that one! Thanks for your help...
__________________
Hugh Macdonald
nvizible
 
  03 March 2003
with objExists, you can also check if an attribute exists on a node:

objExists ($obj + ".myAttr")

Klod
 
  01 January 2006
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 08:52 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.