macroScript Static_Pose_Restore category:"Grants" ( -- Created by Grant Adam, grant@inter.net.au -- A util for restoring positions of hierarchies. -- be aware that if you have changed controllers (ie added list with a different default, lookat's etc) -- results may not be as desired. -- version 0.4 -- globals global obj_ar, pos_ar, rot_ar, sca_ar, selset rollout keyselect "Static Pose Restorer" ( edittext ovnam_txt "Name:" pos:[4,8] width:220 text:"Static Pose01" label lb1 "Select at least the root node(s) of your hierarchy(s)." label lb2 "Stores complete Hierarchies only, make sure" label lb3 "you have selected the root node(s)." label lb4 "(it can work on more than one Hierarchy at once)." button sett "Set object set + save pose" width:200 button rcl "Restore Pose (animate auto on)" width:200 button save_sets "Save data to file" width:200 offset:[0,5] button load_sets "Load data from file" width:200 button slct "Select object set" width:100 offset:[0,5] button clrdumm "Clear all arrays" width:100 enabled:true on sett pressed do ( disablesceneredraw() try ( obj_ar = #() orig_sel = #() selset = #() flagd = 0 if selection.count > 0 then ( orig_sel = selection as array for i in 1 to selection.count do ( if selection[i].parent == undefined then ( a = ("$'" + selection[i].name + "'") --as stringstream -- this since 'selection[i]...*' doesn't work try( select (execute (a + "...*")) -- I need to select before I can walk selection - it builds the selection in the correct order. for j in selection do ( c = j.name -- as stringstream append obj_ar c --(replaceSpaces c) -- this since I need to allow scene deletions, so I store by name string ) ) catch(print ("Failed at " + a)) select orig_sel -- restore orig seletion so loop still works flagd = 1 ) ) pos_ar = for i in obj_ar collect (try(execute("$'" + i + "'.pos"))catch("null")) -- simply storing the data rot_ar = for i in obj_ar collect (try(execute("$'" + i + "'.rotation"))catch("null")) sca_ar = for i in obj_ar collect (try(execute("$'" + i + "'.scale"))catch("null")) if flagd == 0 then (messagebox "You must select at least one root node.") ) else (messageBox "You must select something to work on.") ) catch(enablesceneredraw(); redrawviews()) enablesceneredraw() redrawviews() ) on slct pressed do ( selset = #() disablesceneredraw() try( for i in obj_ar do ( try (if i != undefined then (append selset (execute ("$'" + i + "'")))) catch() ) select selset ) catch(enablesceneredraw(); redrawviews()) enablesceneredraw() redrawviews() ) on rcl pressed do ( --try( disablesceneredraw() with animate on( for i in 1 to obj_ar.count do ( try(if sca_ar[i] != "null" then (execute ("$'" + obj_ar[i] + "'.scale" + " = " + (sca_ar[i] as string))))catch() ) for i in 1 to obj_ar.count do ( try(if rot_ar[i] != "null" then (execute ("$'" + obj_ar[i] + "'.rotation" + " = " + (rot_ar[i] as string))))catch() -- using strings to avoid scene deletion problems and allow loading of saved data ) for i in 1 to obj_ar.count do ( try(if pos_ar[i] != "null" then (execute ("$'" + obj_ar[i] + "'.pos" + " = " + (pos_ar[i] as string))))catch() ) ) --) --catch(enablesceneredraw(); redrawviews(); messagebox "Error has occurred") enablesceneredraw() redrawviews() ) on save_sets pressed do -- this 'borrowed' from a mondo script ( TheFilePath = getSaveFileName caption:"Save Text File" types:"Text(*.txt)|*.txt|All|*.*|" filename:ovnam_txt.text if TheFilePath != undefined then ( createfile TheFilePath MyOpenText = openFile TheFilePath mode:"a" print ovnam_txt.text to:MyOpenText for i = 1 to obj_ar.count do ( oneItem = #(obj_ar[i], rot_ar[i], pos_ar[i], sca_ar[i]) print oneItem to:MyOpenText ) close MyOpenText ) ) on load_sets pressed do ( myOpenLinkFilePath = getOpenFileName caption:"Open Link File" types:"Text(*.txt)|*.txt|All|*.*|" if myOpenLinkFilePath != undefined then ( obj_ar = #() pos_ar = #() rot_ar = #() sca_ar = #() MyOpenLinkFile = openfile myOpenLinkFilePath ovnam_txt.text = execute (readline MyOpenLinkFile as stringstream) --skipToNextLine MyOpenLinkFile try ( while not eof MyOpenLinkFile do ( append obj_ar (execute (readLine MyOpenLinkFile)) append rot_ar (execute (readLine MyOpenLinkFile)) append pos_ar (execute (readLine MyOpenLinkFile)) append sca_ar (execute (readLine MyOpenLinkFile)) ) ) catch() ) ) on clrdumm pressed do ( obj_ar = #() pos_ar = #() rot_ar = #() sca_ar = #() selset = #() ) --rollout objcts "Object List" --( --) ) if ks != undefined then closerolloutfloater ks ks = newRolloutFloater "Static Pose Util" 270 330-- 930 100 addRollout keyselect ks )