PDA

View Full Version : how get this?


czweb
05-10-2006, 09:10 AM
how get this?
group

JohnSwafford
05-10-2006, 10:21 AM
The thread you started on Monday gave the answer:
http://forums.cgsociety.org/showthread.php?t=354408

I slightly modified j-man's code below, and it works fine in max:
fn findhead obj =
(
if (isGroupHead obj)
then (return obj)
else (if (isGroupMember obj) then (findhead (obj.parent)) else (return undefined))
)

This function will return the node itself, so if you want the name of the group (or "None" if there is no group), use the code below:
(
local ReturnedNode = (findhead obj)
local TheText = (if ReturnedNode!=undefined then ReturnedNode.name else "None")
)

czweb
05-11-2006, 06:42 AM
thank you very much

JohnSwafford
11-23-2006, 01:58 AM
I finally began using the above code in a script of my own, and I realized that it only returns the first group head found as it goes upward through the group structure. If you are testing a node that is a member of a group within a multitiered or "nested" group, then it will not return the top level group head.

I modified the test expression to fix this. Before returning any group head node, it tests whether that group head is also a group member, which would make it a lower group nested within another group. When this is the case, it keeps searching up the structure until it finds the top level group head.


fn findhead obj =
(
if ((isGroupHead obj)AND(not (isGroupMember obj)))
then (return obj)
else (if (isGroupMember obj) then (findhead (obj.parent)) else (return undefined))
)

j-man
11-23-2006, 12:07 PM
I was pleased with that little one liner, but never go any thanks for it. I'm glad you've managerd to transform it into something a little bit more useful. I feel dirty though LOL.

J.

JohnSwafford
11-24-2006, 06:17 AM
Thank you very much for that post earlier this year....seriously.

You were answering czweb's question, but you showed the first clear example of a recursive function I'd ever seen. I didn't even know a function could call itself until I read your post. Even after having your example, I still have to stare at it a bit to get my "barely-coding" head around it. Thanks again.

j-man
11-24-2006, 03:41 PM
well it seems like you're doing well now LOL

J.

CGTalk Moderation
11-24-2006, 03:41 PM
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.