脚本管理插件
MaxScriptMAX脚本 5892 50
实名

通过了实名认证的内容创造者

发布于 2013-10-21 20:24:47

您需要 登录 才可以下载或查看,没有账号?注册

x

Snipaste_2019-01-14_21-01-10.jpg


http://www.cgplusplus.com/bbs/viewthread.php?tid=5542&extra=page%3D3

本脚本自动加载指定目录下的*.ms或*.mse脚本文件到插件,有多少个这样的脚本就创建几个按钮,并自动以脚本文件名为按钮名称;这个工具的布局有点像max工具箱,由于篇幅不是很长,技术含量也不高,就直接发源码了;支持列表拉伸

  1. /**
  2. * 2013-5-10 由 霸王硬上弓 编写
  3. * cg++ id :脚本天下
  4. * 转载请注明出处,Element3ds万岁
  5. */

  6. global dlgIns = rolloutCreator "defaultRol" rolloutName  --控件的父窗口
  7. global currBtnList = undefined

  8. fn findLastString str substr =(  --可以使用findLastString "12xx3xxxx4xxx567x8" "xx"测试;找到最后一个字符串的索引
  9.         lastInd = ind = 0
  10.         while ((ind = findstring str substr) !=undefined) do(
  11.                 str = substring str (ind+1) -1
  12.                 lastInd+=ind
  13.         )
  14.         lastInd
  15. )

  16. fn filterstr str findstr &strs= (
  17.         ind = findstring str findstr
  18.         if ind !=undefined then (
  19.                 if ind > 1 do (
  20.                         cutstr = substring str 1 (ind-1)
  21.                         append strs cutstr
  22.                 )
  23.                 levstr = substring str (ind + findstr.count) -1
  24.                 filterstr levstr findstr &strs
  25.         )
  26.         else if str!="" then append strs str
  27. )
  28. firstInd
  29. fn replaceString str findStr replaceStr filterStand:on =( --默认开启标准filter,需要使用逐字符过滤就关闭
  30.         strArr = #()
  31.         if filterStand then (
  32.                 strArr = filterstring str findstr
  33.         ) --filterstring "xxx-xxx-xxx" "x-x"结果为#()空,不是#("xx","x","xx")
  34.         else(
  35.                 filterstr str findstr &strArr
  36.         )
  37.         firstInd = findstring str findstr
  38.         lastkey  = findLaststring str findstr
  39.         result = ""
  40.         for i=1 to strArr.count do append result (strArr+replaceStr)
  41.         if lastkey+findstr.count != str.count+1 do result = substring result 1 (result.count-replaceStr.count) --替换字符串不为尾项就掐掉
  42.         if firstInd == 1 do result = replaceStr + result  --替换字符串为首项就添加替换字符到最前
  43.         result
  44. )

  45. fn getMxs_ directory &pathArr=(
  46.         if directory != undefined and doesFileExist directory then (
  47.                 mxsArr = getFiles (directory+"*.ms*")
  48.                 mxsArr = for mxs in mxsArr where not (getFileAttribute mxs #hidden) collect mxs
  49.                 join pathArr mxsArr
  50.                 dirArr = getDirectories (directory+"*")
  51.                 dirArr = for d in dirArr where not  (getFileAttribute d #hidden) collect d
  52.                 for d in dirArr do getMxs_ d pathArr
  53.                 pathArr
  54.         )
  55.         else #()
  56. )

  57. fn gencurrBtnList files rolloutName = ( --用于脚本管理器中 生成动态对话框
  58.         dlgIns = rolloutCreator "defaultRol" rolloutName
  59.         dlgIns.begin()
  60.         for i=1 to files.count do(
  61.                 fname = getFilenameFile files
  62.                 theCtrl = "dlgIns.addControl #Button #Button"+(i as string)+" "" + fname + "" " + "paramStr: " width:150 height:25 ""
  63.                 execute theCtrl
  64.                 event = "dlgIns.addHandler #Button"+(i as string)+" #pressed filter:on codeStr:"fileIn @"+files+"@" "
  65.                 execute event
  66.                 event2 = "dlgIns.addHandler #Button"+(i as string)+" #rightclick filter:on codeStr:"shellLaunch @"+files+"@ @ @ " " --两个@ @不能靠紧
  67.                 execute event2
  68.         )
  69.         rol = dlgIns.end()
  70.         rol
  71. )

  72. fn defaultPath srcPath tagPath = (
  73.         if not doesFileExist srcPath then tagPath
  74.         else srcPath
  75. )

  76. rollout rt_mxsManager  "MaxScript Manager" width:200 height:400(
  77.         edittext edt_msPath "Path:" text:"" width:150 height:20 across:2
  78.         button btn_msPath "+" width:20 offset:[35,0]
  79.         subrollout workZone "subRol" height:(rt_mxsManager.height - 40 )

  80.                 local selfScriptDir = getFileNamePath (getsourceFileName()) --缺省脚本目录
  81.         local msPathIni = selfScriptDir + "msPath.ini"


  82.         on rt_mxsManager  open do (
  83.                 pathFromIni = getIniSetting msPathIni "Directories" "MS"
  84.                 msPath = defaultPath pathFromIni selfScriptDir
  85.                 edt_msPath.text = replaceString msPath "/" "\"
  86.                 dfiles = getMxs_ msPath #()
  87.                 files = for file in dfiles collect (replaceString file "\" "/")
  88.                 currBtnList = gencurrBtnList files "Third Plugin"
  89.                 AddSubRollout rt_mxsManager.workZone currBtnList

  90.                 height = (getIniSetting msPathIni "UI" "height") as number
  91.                 if height == 0 do height = 400
  92.                 rt_mxsManager.height = height
  93.                 rt_mxsManager.workZone.height = (amax height 41) - 40
  94.         )

  95.         on btn_msPath pressed do(
  96.                 scriptDir = getSavePath caption:"Get Directories" initialDir:(defaultPath (edt_msPath.text) selfScriptDir)
  97.                 edt_msPath.text = scriptDir
  98.                 dfiles = getMxs_ scriptDir #()
  99.                 files = for file in dfiles collect (replaceString file "\" "/")
  100.                 if files.count>0 do (
  101.                         newBtnList = gencurrBtnList files "Third Plugin"
  102.                         removeSubRollout rt_mxsManager.workZone currBtnList
  103.                         AddSubRollout rt_mxsManager.workZone newBtnList
  104.                         currBtnList = newBtnList
  105.                 )
  106.         )

  107.         on rt_mxsManager close do (
  108.                 setINISetting msPathIni "Directories" "MS" ( replaceString (edt_msPath.text) "\" "/" )
  109.                 setINISetting msPathIni "UI" "height" (rt_mxsManager.height as string)
  110.         )

  111.         on rt_mxsManager resized size do (
  112.                rt_mxsManager.workZone.height = size.y - 40
  113.         )
  114. )
  115. createDialog rt_mxsManager lockWidth:on lockHeight:off style:#(#style_resizing,#style_toolwindow,#style_sysmenu)
点击此处复制文本



我的帖子不喜欢无意义的自动回复,如有疑问可加好友私聊或留言
使用道具 <
bearforce  发表于 2014-2-24 14:05:45  
2#
技术牛!
回复 收起回复
使用道具
追忆童年  发表于 2014-2-27 18:16:22  
3#
讲的不错,支持一下
回复 收起回复
使用道具
protoss  发表于 2014-3-5 11:00:59  
4#
大神的绝学都 公布了!受益终身啊!
回复 收起回复
使用道具
懲墨  发表于 2014-5-29 15:03:45  
5#
{:1_141:}
回复 收起回复
使用道具
一个英雄火鸟  发表于 2014-6-23 13:44:46  
8#
给力!元素有你更精彩
回复 收起回复
使用道具
放纵的自由  发表于 2014-6-26 10:41:48  
9#
牛人
回复 收起回复
使用道具
Spirit  发表于 2014-7-1 00:54:27  
10#
我和我的小伙伴们都惊呆了!
回复 收起回复
使用道具
cgvfx  发表于 2014-7-9 13:54:28  
12#
楼主不该放弃治疗啊!
回复 收起回复
使用道具
ren96168  发表于 2014-7-9 14:44:41  
13#
太牛了
回复 收起回复
使用道具
落花爱上流水  发表于 2014-7-24 16:33:53  
14#
好东西
回复 收起回复
使用道具
落花爱上流水  发表于 2014-7-24 16:33:55  
15#
好东西
回复 收起回复
使用道具
落花爱上流水  发表于 2014-7-24 16:34:00  
16#
好东西
回复 收起回复
使用道具
_SKY_  发表于 2014-7-30 08:35:04  
17#
讲的不错,支持一下
回复 收起回复
使用道具
Gawain  发表于 2014-7-31 09:27:49  
18#
给力!元素有你更精彩
回复 收起回复
使用道具
wjm  发表于 2014-8-26 16:39:50  
19#
谢谢分享
回复 收起回复
使用道具
zwxzxl  发表于 2014-9-5 00:57:38  
20#
{:1_152:}
回复 收起回复
使用道具
123下一页
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表