CloseMaxScript6 资源文件之 dll as mse

概述

将dll作为mse文件
使用filein就能载入dll文件,简化交付、简化调用
同时也是兼容替换3dmax2026新运行时动态编译的方案之一

注意:所有资源都是原样嵌入,勿将此当成加密资源

打包脚本

fn build = 
(
	global Cmxs6Publisher, Cmxs6SettingsModel
	global cmxs6_cli_mode = true
	local curDir = getFilenamePath (getThisScriptFilename())
	filein cmxsProgramFile
	--配置
	config = Cmxs6SettingsModel()
	config.InputFile = curDir + "YourWrapperScript.ms"
	config.AddResourcesFile (curDir + @"your.dll") releaseName:"new_name.dll" compress:true writeToLocal:false
	--
	global result = Cmxs6Publisher.build config
	--ShellLaunch (getFilenamePath result) ""
	--
	filein result
)


build()  

包装脚本 YourWrapperScript.ms

global YourNamespace_YourClassName

fn __load =
(
	product = Cmxs6Container.MxsRuntime.Call "LastTool"
	bytes = product.Call "GetResources" @"new_name.dll"
	asm = (dotnetClass "System.Reflection.Assembly").Load bytes
	----
	global YourNamespace_YourClassName= asm.createInstance "YourNamespace.YourClassName"
	
	print ("Load Ok")
)

try(
	__load()
)catch(print ("Load ERR: " + getCurrentException()))  

调用

--将本代码尽量靠前载入

-- 1. 声明需要的变量
global YourNamespace_YourClassName

-- 2. 载入,你需要指定你的文件放置路径
filein (@"YourWrapperScript.mse")
posted @ 2025-01-23 14:17  trykle  阅读(53)  评论(0)    收藏  举报