Notifications
Clear all

[Closed] Using hasProperty with subAnim

 lo1

from a test I conducted a while back, isProperty gave almost identical performance to a manual try/catch like bobo demonstrated, reinforcing the notion that it is essentially a try/catch wrapper.

isProperty is not try/catch wrapper. isProperty searches a property in the list all properties until find it or come to the end.
it finds quicker the properties in beginning of the list, and much slower in the end.
getProperty/setProperty uses the isProperty method internally. It’s why they have the same as isProperty searching time (the time of execution might be different).

hasProperty might be only faster than isProperty because it searches in smaller list – only base class properties, class properties, some interfaces. isProperty searches further to hasProperty list in modifiers, materials, custom attributes, transform controllers, … maybe some other places.

here is a sample with CA:


 FlipAttrib = attributes "FlipAttrib" ( parameters main (flip type:#boolean) )
 b = box()
 custAttributes.add b FlipAttrib
 
 hasProperty b #flip -- false
 isProperty b #flip -- true
 	
 hasProperty b #FlipAttrib -- false
 isProperty b #FlipAttrib -- true
 
 hasProperty b.FlipAttrib #flip -- true
 isProperty b.FlipAttrib #flip -- true
 

because getProperty/setProperty uses the isProperty method internally any way, it doesn’t make sense to do isProperty test before using these methods, it’s batter to use try/catch expression.


if [b]isproperty <node> <prop>[/b] do [b]getproperty <node> <prop>[/b]
-- is about two time slower than
try([b]getproperty <node> <prop>[/b]) catch()

 lo1

I ran this test to see exactly the performance effects, and to my surprise, all access methods (even direct property access) depend on the order of the property in the list of properties:

(
tpt = teapot()
ts = timestamp()
for i = 1 to 10000 do try(tpt #smooth)catch()
format "try/catch getProperty first property: %ms
" (timestamp()-ts)
ts = timestamp()
for i = 1 to 10000 do try(getProperty tpt #realWorldMapSize)catch()
format "try/catch getProperty last property: %ms
" (timestamp()-ts)
ts = timestamp()
for i = 1 to 10000 do try(getProperty tpt #fakeProperty)catch()
format "try/catch getProperty no match: %ms
" (timestamp()-ts)
ts = timestamp()
for i = 1 to 10000 do try(tpt.smooth)catch()
format "try/catch direct access first property: %ms
" (timestamp()-ts)
ts = timestamp()
for i = 1 to 10000 do try(tpt.realWorldMapsize)catch()
format "try/catch direct access last property: %ms
" (timestamp()-ts)
ts = timestamp()
for i = 1 to 10000 do try(tpt.fakeProperty)catch()
format "try/catch direct access no match: %ms
" (timestamp()-ts)
ts = timestamp()
for i = 1 to 10000 do isProperty tpt #smooth
format "isProperty first property: %ms
" (timestamp()-ts)
ts = timestamp()
for i = 1 to 10000 do isProperty tpt #realWorldMapSize
format "isProperty last property: %ms
" (timestamp()-ts)
ts = timestamp()
for i = 1 to 10000 do isProperty tpt #fakeProperty
format "isProperty no match: %ms
" (timestamp()-ts)
delete tpt
)

Results:

try/catch getProperty first property: 376ms
try/catch getProperty last property: 1425ms
try/catch getProperty no match: 2250ms
try/catch direct access first property: 6ms
try/catch direct access last property: 1381ms
try/catch direct access no match: 1963ms
isProperty first property: 17ms
isProperty last property: 1405ms
isProperty no match: 1396ms
1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

this is not really direct method… it’s a variation of getProperty method (but executed internally).
the real direct method is:


  b = box()
  b.baseobject[6].value
  
  -- check the time difference:
  b.baseobject[6].value -- direct
  b.baseobject[#Height_Segments].value -- uses find sub anim by name
  getProperty b #Height_Segments -- uses find property by name
  getProperty b.baseobject #Height_Segments -- uses find property by name but in a smaller list
  
 lo1

I see your point, but isn’t this only good for subanims?
Is there a similar method of indexed access to properties which are not subanims?

2 Replies
(@denist)
Joined: 11 months ago

Posts: 0

unfortunately NO. i can’t understand why developers don’t give direct access to parameter block (at least for an advanced users :))

 lo1
(@lo1)
Joined: 11 months ago

Posts: 0

Maybe they are afraid of making Maxscript overly efficient, and as a result get less paying members of ADN

Denis, that was very informative, thanks!
I see that you spent time to examine this function,
but be honest and admit that the explanation in the book is not obvious

Page 2 / 2