--------------------------------------------------------------- -- mental ray proxy baking script -- test/proof of concept version -- this is UNSUPPORTED SOFTWARE -- use at your OWN RISK -- v1.0 Zap. 08-04-15 --------------------------------------------------------------- global mrProxyWarning macroScript mrProxyBaking enabledIn:#("max", "viz") category:"mental ray" internalcategory:"mental ray" ButtonText:"Convert Object(s) to mental ray Proxy..." Tooltip:"Convert Object(s) to mental ray Proxy..." (-- macro begins on isVisible return ((classof renderers.current == mental_ray_renderer) and ((Selection.count > 0) and ((superClassof Selection[1] == GeometryClass) and (CanConvertTo Selection[1] Mesh)))) on isEnabled return ((classof renderers.current == mental_ray_renderer) and ((Selection.count > 0) and ((superClassof Selection[1] == GeometryClass) and (CanConvertTo Selection[1] Mesh)))) on execute do ( -- this test is probably redundant... if (((Selection.count > 0) and ((superClassof Selection[1] == GeometryClass) and (CanConvertTo Selection[1] Mesh)))) do with undo "Convert to MR Proxy" on ( result = #yes if (mrProxyWarning == undefined) do ( msg = "\nThis will convert the selection to mr Proxy object(s). \n\n" + "The original object(s) will be deleted and replaced\n" + "by the mr Proxies. The original object(s) will NOT\n" + "be saved in any way! Make sure you have a\n" + "backup copy of your object before irreversibly\n" + "converting to an mr Proxy!\n\n" + "Do you wish to skip this warning next time?\n\n" result = yesNoCancelBox msg title:"mr Proxy Creation" if (result == #yes) then mrProxyWarning = false ) if (result != #cancel) then if (Selection.count == 1) then ( -- Create a proxy object proxy = mr_Proxy() -- Set this to variable - we need this since "current selection" -- is changed by the proxy creation code... obj = Selection[1] if (obj.renderable) do ( if (proxy.writeProxyDlg obj) then ( -- I have to do this to avoid a circular reference in "replaceInstances" proxy.SrcGeometry = undefined -- Now replace the old objects w. the new replaceInstances obj proxy -- remove modifier stack from instances InstanceMgr.GetInstances proxy &inst for obj in inst do while (obj.modifiers.count > 0) do deleteModifier obj 1 -- Delete the proxy, not needed any more! delete proxy ) else delete proxy -- Get rid of it again, the bake failed! ) ) else ( local originalSet = Selection As Array local newFileName = getSaveFileName types:"mr Proxies (*.mib)|*.mib" caption:"File name PREFIX (object names will be appended):" if (newFileName != undefined) do ( local head = getFilenamePath newFileName + getFilenameFile newFileName local tail = getFilenameType newFileName local errorstring = "" for obj in originalSet do ( local filename = head + obj.name + tail if doesFileExist filename do errorstring = errorstring + filename + "\r" ) if (errorstring != "") do ( if not queryBox ("These files already exists. Do you want to replace them?\r\r" + errorstring) title:"mr Proxy Creation" do originalSet.count = 0 ) local wantzoom = yesNoCancelBox "Create detailed preview by Zooming in on each object?" title:"mr Proxy Creation" -- user cancelled if (wantzoom == #cancel) do originalSet.count = 0 for obj in originalSet do ( -- test this, in case the selection set contains an object already turned into a proxy.... if ((superClassof obj == GeometryClass) and (CanConvertTo obj Mesh) and (obj.renderable)) do ( local filename = head + obj.name + tail local proxy = mr_Proxy() proxy.writeProxy obj filename zoom:(wantzoom == #yes) -- I have to do this to avoid a circular reference in "replaceInstances" proxy.SrcGeometry = undefined -- Now replace the old objects w. the new replaceInstances obj proxy -- remove modifier stack from instances InstanceMgr.GetInstances proxy &inst for obj in inst do while (obj.modifiers.count > 0) do deleteModifier obj 1 -- Delete the proxy, not needed any more! delete proxy ) ) ) ) ) ) ) -- macro ends