Search ProofOfProgress Blog

Sunday, April 3, 2011

AutoLoad CallBacks On File Open in MaxScript



[Source Code Below] Download Source: ****HERE****



-- 1 2 3 4 5 6 7 8 9 10
--34567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
--
--********************************************************************
--********************************************************************
--MORE FREE SCRIPTS AT: http://www.youtube.com/user/PolygonRunner ****
--********************************************************************
--********************************************************************
--
--What it does:
--[1]: Registers callback when you open the file and move the time slider.
--[2]: UnRegisters when you open a different max file.
--
--How to use:
--[1]: Put code into a script controller of a dummy object.
--[2]: Make sure last line of script controller is:
-- : [0,0,0], or other valid point3 if position script.
-- : quat 0 0 0 1, or other quaternion if rotation script.
-- : ect...
--[3]: If you want, you can also edit this code to handle
-- "when constructs" and "change handlers".
--
--My personal application:
--[1]: Use to force update script controllers that are not
-- Executing in the correct order.
--
Global MFP_586_214_3958; --MFP = "Max File Path";
Global BFN_586_214_3958; --BFN = "Bound Function";
if (MFP_586_214_3958 != maxFilePath)then(
MFP_586_214_3958 = maxFilePath;
Function BindThisFunction
=(
--Need code to un-register itself when the maxFilePath changes.
if(MFP_586_214_3958 != maxFilePath)then(
--Must remove globals so that will re-register
--If you re-open this file or another file with this
--script in it.
unRegisterRedrawViewsCallback BFN_586_214_3958;
MFP_586_214_3958 = undefined;
globalVars.remove "MFP_586_214_3958";
globalVars.remove "BFN_586_214_3958";
print("Unregistering Callback");
)else(
print("Callback executed on frame" + currentTime as string);
--**********YOUR CALLBACK CODE HERE***********
--**********YOUR CALLBACK CODE HERE***********
--**********YOUR CALLBACK CODE HERE***********
)--[x]
)--[FN:BindThisFunction]

--Bind function to global variable, else the function will
--Not be capable of unRegistering itself.
BFN_586_214_3958 = BindThisFunction;

--Register the function as a callback.
registerRedrawViewsCallback BFN_586_214_3958;
print("CallBack has been registered");
)--[END]

-- 1 2 3 4 5 6 7 8 9 10
--34567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890

No comments:

Post a Comment