------------------------------------------------------------------------------ -- PickHierarchy.ms -- By Sergo Pogosyan (www.sergepogosyan.com, contact@sergepogosyan.com) -- v 1.0 -- Created On: 2008-10-25 -- tested using Max 2009 ------------------------------------------------------------------------------- -- Description: -- macroscript for selecting whole heirarchy by picking one belonging object. ------------------------------------------------------------------------------- -- Installing: -- Install macroscript by running this file and assign shortcut keys to "PickHierarchy" command in "Sergo Pogosyan" category. -- Usage: -- Run script by shortcut or button and pick some object in scene. If this object belongs to some hierarchy it will be selected. -- mouse click + CTRL button adds picked hierarchy to exitsting selection, click + ALT removes picked hierarchy from current selection. ------------------------------------------------------------------------------- -- TO DO list: -- Major features -- 1. If object already selected than use it as picked object. -- done:2. Add multiple picking support. -- 3. Consider hidden objects. -- 4. Consider Selection Filters. -- Bug fix -- done:support canceling ------------------------------------------------------------------------------- -- history -- 2009-09-25: started -- 2009-10-25: release ------------------------------------------------------------------------------- macroScript pickhierarchy category:"Sergo Pogosyan" toolTip:"PickHierarchy" buttonText:"PickHierarchy" ( --function to collect all the children of argument object(s) to the argument array fn collect_children child_array obj_array = ( for i in obj_array do ( if ((i.children).count > 0) then ( temp_children = for j in (i.children) collect j --convert childrenarray to array join child_array temp_children --add children to main array collect_children child_array temp_children --call this function with children as arguments ) ) ) --find most upper parent object fn find_upper_parent obj= ( parent = obj.parent if parent != undefined then return find_upper_parent parent else return obj ) --testing function fn test_with_current_selection= ( child_array = #() selection_array = ($selection as array) join child_array selection_array collect_children child_array selection_array print child_array select child_array ) --testing function fn test_with_picking= ( obj = pickObject message:"pick object to select its heirarchy" count:1 select:false child_array = #() selection_array = #(find_upper_parent obj) join child_array selection_array collect_children child_array selection_array print child_array selectMore child_array ) --testing function. --this function is used currently as main selecting function. fn test_with_loop_picking= ( do --do until user cancels function ( --pick ONE object obj = pickObject message:"pick object to select its heirarchy" count:1 select:false forceListenerFocus:false if ((obj != undefined) and (obj != #escape)) then ( child_array = #() selection_array = #(find_upper_parent obj) --find parents join child_array selection_array --join parents and picked objects into array collect_children child_array selection_array --find all children if keyboard.controlPressed then selectMore child_array --add selection else if keyboard.altPressed then ( deselect child_array --remove selection ) else select child_array --just select picked hierarchy ) ) while ((obj != undefined) and (obj != #escape)) --stop the loop if something happened - user cancel or some other thing. ) --call selecting function. test_with_loop_picking() )