I tried Google but it's hard to google "$" - So i wasn't successful.
I#M using
3Ds Max 2011 64Bit
I always thought
$ and
$selection give you the same result: the current selection.
BUT
If you have e.g. a box linked to another box, select the blue one and execute the code below, you'll get different results:
Code with $
for obj in $ do print obj
Result
$Box:Box01Parent @ [0.000000,0.000000,0.000000]
$Box:Box01Child @ [20.000000,0.000000,0.000000]
Code with $selection
for obj in $selection do print obj
Result
$Box:Box01Parent @ [0.000000,0.000000,0.000000]
Interesting
If you have the same situation but twice, and you select both parents, the results are equal for both code variations:
Code with $
for obj in $ do print obj
Result
$Box:Box01Parent @ [0.000000,0.000000,0.000000]
$Box:Box01Parent @ [0.000000,21.652542,0.000000]
Code with $selection
for obj in $selection do print obj
Result
$Box:Box01Parent @ [0.000000,0.000000,0.000000]
$Box:Box01Parent @ [0.000000,21.652542,0.000000]
Why is this important?
For example if you've a script which moves objects around. In this example i add +10 to the x axis and in one case the linked box moves relative, in the other example it moves too far:
Is this a bug? Or did i just misunderstand the system?
Replies
http://docs.autodesk.com/3DSMAX/14/ENU/MAXScript%20Help%202012/files/GUID-8395020C-E3B6-4282-AF1C-5B58BDB97A2-391.htm
The $ is the most dangerous one - and in so many ways it's not even funny. It returns different values based on what how many nodes are selected:
So when one node is selected, what happens? $ returns the node itself and you are not iterating an array of nodes, you are iterating that node, basically saying:
It just so happens that you can actually do that and it will give you the node and all its children and their children's children etc. Most of the time you want a snapshot of the selection as array, so selection as array or getCurrentSelection() is the safest bet.
92ms for $
61ms for obj = $
69ms for selection[1]
I know 30ms isn't exactly a discernible difference, but if you've got a huge code project littered with little slow downs, it all adds up.