Notifications
Clear all

[Closed] Using hasProperty with subAnim

Hey guys,
Does anyone know how to us the hasProperty function with a subAnim?

On an example object:
$[3][1][2].isAnimated returns true
but
hasProperty $[3][1][2] #isAnimated returns false

If you’re looping through the subAnims $[i].isAnimated can throw an “Unknown Property” error so I wanted to try and use hasProperty() to filter out the subAnims that might crash a loop.

Using try()catch() works fine but just out of curiosity I wanted to know if it’s possible to inspect subAnim properties.

Thanks.

23 Replies

havn’t tested but I tend to use isProperty rather than hasProperty. i think a long time ago i did some testing and decided it was better. dont remember why

huh, isProperty seems to work the way I expected hasProperty to. Thanks, man. isProperty returns true while hasProperty still returns false… I wonder why though?

do you not read the mxs help?
just simply put The difference between hasProperty and isProperty in search and get an answer…

1 Reply
(@pacermike)
Joined: 11 months ago

Posts: 0

Denis, I LIVE in the MXS help files. This particular topic wasn’t making any sense to me so I asked for help because I am trying to learn and understand. I have spent a very good deal of time being completely confused by some of the things written in the help files. I thought this forum was a place to come for help clearing up some of that confusion. Not everyone has as good an understanding of this stuff as you do.
From the help file:

hasPropertyuses the same code as showPropeties, but instead of returning a list of the properties found, it returns true on the first property name that matches the specified pattern.

To me, that is vaguely written because it seems to be saying that it would only return the first matching result instead of going through the whole list, kind of like using “while” in a for loop. If that is not the case then I don’t understand when using hasProperty would ever be useful. I’ll happily use isProperty instead, it just would have been nice to understand why.

Hi Andy,
hasProperty uses the same code as showPropeties” – this is it.

  • ShowPropeties has limited scope (“MAXClass definition”),
  • while isProperty is like a try/catch wrapper.

i double-checked how the mxs help tells and i have to say that i can’t explain this matter better. but i will try to say the same in a different words.
showproperties method looks at only properties defined by class, inherited from base class, and dynamic properties (see help). it doesn’t look at properties which come with modifiers, materials, custattributes, controllers, etc.
so showproperties collects all names of those properties and shows them if they match the wild card.

hasproperty method uses the the result of showproperty method by getting the match.

getpropertynames looks… hmm… this is not actually true, but let’s say recursively.
it looks for inherent and acquired properties.

isproperty is not a try/catch wrapper. it’s a result of the searching in getpropertynames return…
so if you have an object with HUGE amount of properties it’s much faster to ask getproperty with try/catch than use isproperty to verify the property existence.

4 Replies
(@panayot)
Joined: 11 months ago

Posts: 0

hmm… interesting…
Where you find extra info on what stay behind IsProperty function?
I really interesting because i found nothing, and as its slow looks to me like try/catch wrapper.
Also “getpropertynames” returns Undefined in my Max 2009.

(@denist)
Joined: 11 months ago

Posts: 0

i’m pretty far right now from max 2009. i don’t have a chance to check this version.
but if getpropertynames returns undefined, the isproperty has to return false.

(@panayot)
Joined: 11 months ago

Posts: 0

I mean that getpropertynames is not existing function in max 2009.
But more interesting is – where you find additional info about IsProperty()?

[edit] i search this function into mxs-reference 2011/2012 but not found it there as well.
and the official description for IsProperty lead me to those try/catch conclusion.

but as i said – more info will be welcome

(@denist)
Joined: 11 months ago

Posts: 0

getpropertynames doesn’t exist (my bad – copy/paste issue). there is getpropnames since max 5.

Bobo explained it very well for me in the mxs help, but maybe he will find a time to clear it a bit better.

Thank you, guys! That is actually MUCH more clear than the help files. I guess I didn’t realize that even default transform controllers would be excluded from a showProperties/hasProperty search, or that the inspection types were so dramatically different in where they were searching, but I see how that makes sense now. Thanks for clearing it up for me

here’s all what i find about IsProperty in the help:

The [font=Courier New]isProperty() function allows you to test whether an object has a specified property.[/font]

[left][font=Verdana]isProperty on the other hand actually tries to access the specified object with the specified name and to detect whether the access succeeded or failed.
[/font]

[/left]

This part of the help wasn’t written by me, the info was passed to me “from above” (from the developers).

My understanding of the topic is this:

hasProperty() is like

findItem (getPropNames theObject) theProperty > 0

As you know, findItem stops at the first item found, which explains the mentioning of that process in the Help.

isProperty is like

try(getProperty theObject theProperty;true)catch(false)

An attempt is made to access the property and if it is successful, the property most probably exists.

So if you create a Sphere, you can get the following:

getPropNames $
#(#smooth, #radius, #segs, #mapcoords, #slice, #hemisphere, #sliceFrom, #sliceTo, #chop, #recenter, #realWorldMapSize)

showProperties $
  .smooth : boolean
  .radius : float
  .segs : integer
  .mapcoords : boolean
  .slice : boolean
  .hemisphere : float
  .sliceFrom : angle
  .sliceTo : angle
  .chop : integer
  .recenter : boolean
  .realWorldMapSize : boolean

hasProperty $ #radius --> true
hasProperty $ #visibility --> false
isProperty $ #radius --> true
isProperty $ #visibility --> true
findItem (getPropNames $) #radius > 0 --> true
findItem (getPropNames $) #visibility > 0 --> false
try(getProperty $ #radius;true)catch(false) --> true
try(getProperty $ #visibility;true)catch(false) --> true

The exact details might be a bit different, but this is what I understood from the info I got before including it in the Help…

EDIT:

Going a bit further, you can add a Bend modifier to the Sphere and try this:

hasProperty $ #bend --> false
isProperty $ #bend --> true
findItem (getPropNames $) #bend > 0 --> false
try(getProperty $ #bend;true)catch(false) --> true

hasProperty $ #angle --> false
isProperty $ #angle --> false
findItem (getPropNames $) #angle > 0 --> false
try(getProperty $ #angle;true)catch(false) --> false

This is because you cannot access angle as a property of the Sphere, only as a property of the Bend, e.g. $.bend.angle

Page 1 / 2