How to find if an object contains another [message #22146] |
Thu, 19 October 2000 00:00  |
Dave Greenwood
Messages: 33 Registered: October 2000
|
Member |
|
|
How do I determine if an object "contains" another one?
For example, I can create a model object and add a surface object or
a plot object. Given that model object, how would I find out whether
or not a surface object has been added?
The best I've come up with is something like:
xx = model->get(/all,isa='idlgrsurface')
s = size(xx)
if s[1] eq 11 then $
print,'Has one or more surface' $
else $
print,'Has no surfaces'
Surely there's a simpler way?
A related question is: how do I test if an object pointer (returned by
the GetByName method, for example) is null?
Thanks,
Dave
--------------
Dave Greenwood Email: Greenwoodde@ORNL.GOV
Oak Ridge National Lab %STD-W-DISCLAIMER, I only speak for myself
|
|
|
Re: How to find if an object contains another [message #22740 is a reply to message #22146] |
Sun, 03 December 2000 00:00   |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Dave Greenwood (greenwoodde@ornl.gov) writes:
> How do I determine if an object "contains" another one?
>
> For example, I can create a model object and add a surface object or
> a plot object. Given that model object, how would I find out whether
> or not a surface object has been added?
>
> The best I've come up with is something like:
>
> xx = model->get(/all,isa='idlgrsurface')
> s = size(xx)
> if s[1] eq 11 then $
> print,'Has one or more surface' $
> else $
> print,'Has no surfaces'
>
> Surely there's a simpler way?
How about something like this:
xx = model->get(/all,isa='idlgrsurface', Count=numFound)
Print, numFound
> A related question is: how do I test if an object pointer (returned by
> the GetByName method, for example) is null?
If an object is NULL it is an invalid object:
IF Obj_Valid(theObject) EQ 0 THEN Print, 'Object is invalid.'
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|
Re: How to find if an object contains another [message #23319 is a reply to message #22146] |
Wed, 17 January 2001 06:01  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Dave Greenwood (greenwoodde@ornl.gov) writes:
> How do I determine if an object "contains" another one?
>
> For example, I can create a model object and add a surface object or
> a plot object. Given that model object, how would I find out whether
> or not a surface object has been added?
>
> The best I've come up with is something like:
>
> xx = model->get(/all,isa='idlgrsurface')
> s = size(xx)
> if s[1] eq 11 then $
> print,'Has one or more surface' $
> else $
> print,'Has no surfaces'
>
> Surely there's a simpler way?
That's one way. But, and I think you have stumbled
upon this, it is much easier (and produces more
readable code) if you give the objects you are
looking for "names" and fish them out with the
GetByName method.
> A related question is: how do I test if an object pointer (returned by
> the GetByName method, for example) is null?
You use the Obj_Valid function to find a null object:
IF Obj_Valid(theObject->GetByName('MYSURFACE') THEN $
Print, "Object Found!!!" ELSE Print, "Object Not Here."
Cheers,
David
P.S. I think Martin is on vacation at the moment, but
he has a wonderful modified IDL_CONTAINER object named
MGS_CONTAINTER that can find any object by name. You
can use wildcard searches, etc. It's very nice for this
kind of thing. You can find it in his extensive program
library.
--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|