[Closed] Filenamestring trouble
HI all,
im trying to script a automatic dropdownmenu that contains the scripts (or links to) all the scripts in a specified folder. This will make it alot easier for me to reuse my scripts – all i would have to do is copy the ms file into the folder and next time max is started its automatically in the dropdownmenu.
im using getFiles to build a array of all the ms files in the folder, but the filepaths in the resulting array are in the form dir\dir\dir\file i would like it to be dir\dir\dir\file.
one of my problems with the single backslash is this:
str = [\jf\D\maxscripts\SOCORun est\inventor2max_pipeline.ms](file://\jfDmaxscriptsSOCORuntestinventor2max_pipeline.ms)
would return:
“\jf\D\maxscripts\SOCORun est\inventor2max_pipeline.ms”
because the is recognized as a tabcode…
also openfile dosent get anywhere with the single backslashes…
[size=1]openfile (“\jf\D\maxscripts\SOCORun est\inventor2max_pipeline.ms”)
[size=1][size=2]would return[/size][/size]
undefined[size=1][size=2][/size][/size]
[size=1][size=2][/size][/size]
[size=1][size=2]Any pointers in the right (or any) direction are greatly appreciated.[/size][/size]
Thanks.
[size=1][size=2]
[/size][/size][/size]
Hi,
I think you have to convert the returned string replacing the single backslash by two backslashs:
‘’ -> “\”
A MAXScript developer made a script that Searches MAXScripts through directories for editing : Supra (needs C4 function library).
Thanks guys…
zbuffer your function works perfectly…thanks
however i still have this problem:
str = [\jf\D\maxscripts\SOCORun est\inventor2max_pipeli ne.ms](file:///jfDmaxscriptsSOCORuntestinventor2max_pipeline.ms)
would return:
“\jf\D\maxscripts\SOCORun est\inventor2max_pipeline.ms”
because the[color=#fffffe] is recognized as a tabcode…
[/color]
Does anyone have a workaround for this?..i know it just a matter of naming the folder to something else – but i would very much like to find a workaround, to avoid future problems with foldernaming (when this problem is long forgotten).
Thanks…
Hi guys,
well my createmenuscript is complete, if anybody else can use it please fell free to do so.
- just edit the vars:
pathToSearch
[size=1][size=2]menuName [/size]
and place the script into your scripts/startup folder.
things to come:
i would like to imlement functionality that would make it recursive both the dirsearch and the menustructure.
Here it is:
BTW. the scripts makes small macroscripts for each scriptfile, this means the scripts in the folder that are searched should not be macroscripts.
[/size]
fn createMScriptString mscriptname mscriptcat scripttorun=(
str = "macroscript "
str += mscriptname
str += " "
str += "category:"
str += "\"" + mscriptcat + "\""
str += " "
str += "buttontext:"
str += "\"" + mscriptname + "\""
str += " "
str += "tooltip:"
str += "\"" + mscriptname +"\""
str += " ("
str += scripttorun
str += ")"
str
)
fn fixPath txt =
(
local result=""
local tmp=filterstring txt "\\"
for i=1 to (tmp.count-1) do result+=(tmp[i]+"[\\\\]( http://forums.cgsociety.org/ )")
result+=(tmp[tmp.count])
--handle UNCpaths
if substring txt 1 2 == "[\\\\]( http://forums.cgsociety.org/ )" do(
result = "[\\\\\\\\]( http://forums.cgsociety.org/ )" + result
)
result
)
pathToSearch = "[\\\\jf\\D\\maxscripts\\SOCORun\ est]( http://forums.cgsociety.org/ )"
files = getFiles (pathToSearch + "[\\*.ms](file:///*.ms)")
menuName = "SOCORun_X"
--Start regisrering the menus
oldSOCORunx = menuMan.findMenu menuName
if (oldSOCORunx != undefined)then(
menuMan.unRegisterMenu oldSOCORunx
)
-- register menu item
if (menuMan.findMenu menuName == undefined)then (
--backup the current mnu file
menuMan.saveMenuFile "pre_CreateMenus-stript_Backup.mnu"
-- Get the main menu bar
local mainMenuBar = menuMan.getMainMenuBar()
-- Create new menu s
local subMenu = menuMan.createMenu menuName
for f in files do(
f = fixpath f
print f
msname = getFilenameFile f
print msname
macrostring = createMScriptString msname menuName ("execute(openfile(\"" + f + "\"))")
execute macrostring
-- menuitem
local menuitem = menuMan.createActionItem msname "SOCORunx"
subMenu.addItem menuitem -1
)
-- Create a new menu item with the menu as it's sub-menu
local subMenuItem = menuMan.createSubMenuItem "SOCORunx" subMenu
-- compute the index of the next-to-last menu item in the main menu bar
local subMenuIndex = mainMenuBar.numItems() - 1
-- Add the sub-menu just at the second to last slot
mainMenuBar.addItem subMenuItem subMenuIndex
-- redraw the menu bar with the new item
menuMan.updateMenuBar()
)