CGTalk > Software > Autodesk 3ds max > 3dsMax SDK and MaxScript
Login register
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 10-10-2006, 04:44 PM   #1
davestewart
Repeat-customer
 
davestewart's Avatar
Dave Stewart
Animator / scripter
United Kingdom
 
Join Date: Sep 2004
Posts: 488
Renaming menu items

Is it possible to rename menu items dynamically? I have a Macro that displays as "Open most recent file" in my File menu, which loads either the last Autobackup, or the first most-recent file (whechever is newer).

It would be nice to display, using the onEnabled handler, "Open most recent file (Dave's File 03.max)" or whatever.

If it's not straightforward (for example I have to dynamically redefine the macroscript), I may just print it to the Listener.

Any ideas would be welcome,
Thanks,
Dave
 
Old 10-13-2006, 12:30 AM   #2
Zbuffer
Expert
Wanabee Scripter
Finland
 
Join Date: Jan 2003
Posts: 568
Hi,

funny you ask about this, I just did a little script to have a "recent script' menu added to the MaxScript menu

I used the .settitle funtion to set the menu title,
if interested here is the code i wrote:

Code:
------------------------------------------------------------------------ -- FileName: Zbuffer-OpenScript.mcr -- Version: 0.1 -- Author: Zbuffer -- date: 28/09/2006 -- -- description: Replaces the MaxScript/Open Script menu and adds a 'Recent Scripts' menu to the MaxScript menu. -- usage: 1. Put this script in the <MAXROOT>\UI\MacroScipt folder. (or evaluate) -- 2. Go to the 'Customize/Customize User Interface' menu -- 3. On the 'menu' tab, replace/add the 'Maxscript/Open Script' with this one ('Zbuffer' category). -- Tou can modify the Maxfiles variable if you want more than 10 recent files ------------------------------------------------------------------------- macroscript OpenScript category:"Maxscript buttonText:"Open Script" ( local Maxfiles = 10 -- Number of recent files in the Menu local ScriptDir = (getdir #scripts)+"\\" -- Always show the open file dialog in this folder. local INI = (getdir #plugcfg)+"\\RecentScripts.ini" local FileCount = getINIsetting INI "FileCount" "Count" if FileCount == "" then FileCount = 0 else FileCount = FileCount as integer -- check for 1st run local Recentfiles=#() -- array holding the recent file names -- browse for a file to open. local f=getOpenFileName caption:"Choose Editor File" fileName:ScriptDir types:"All Scripts(*.ms;*.mcr)|*.ms;*.mcr|MaxScript(*.ms)|*.m s|Macroscript (*.mcr)|*.mcr|Text Files (*.txt)|*.txt|All|*.*|" if f !=undefined do ( -- fix path string while ((i=findstring f "\\") != undefined) do f=replace f i 1 "/" -- Update the Recent Scripts list for i=1 to FileCount do append Recentfiles (getINIsetting INI "FileList" ("File"+i as string)) if ((finditem Recentfiles f) == 0) then (insertItem f Recentfiles 1) else ( deleteItem Recentfiles (finditem Recentfiles f) insertitem f Recentfiles 1 ) if RecentFiles.count>Maxfiles do deleteItem Recentfiles (Maxfiles+1) -- Write the list to the INI file for i=1 to Recentfiles.count do setINIsetting INI "FileList" ("File"+i as string) Recentfiles[i] setINIsetting INI "FileCount" "Count" (Recentfiles.count as string) -- Build the menu local ScriptMenu = MenuMan.findMenu "&MAXScript" -- delete the Recent Scripts Menu if it exists if ((Scriptmenu.getItem 1).getTitle())=="Recent Scripts" do ScriptMenu.removeItemByPosition 1 -- Create the Recent Scripts Menu local RecentFileMenu=MenuMan.createMenu "Recent Scripts" -- create the submenuitems for i=1 to Recentfiles.count do ( -- create Macroscripts for the menuitems macros.new "Recent Scripts" ("Script"+i as string) "" (i as string+" "+Recentfiles[i]) ("(edit \""+Recentfiles[i]+"\")") local testItem = menuMan.createActionItem ("Script"+i as string) "Recent Scripts" testItem.setTitle Recentfiles[i] RecentFileMenu.additem testItem -1 ) -- add the subitems to the menu local RecentFileMenuItem = menuMan.createSubMenuItem "RecentScripts" RecentFileMenu -- add the menu at the 1st position in the MAxscript menu ScriptMenu.additem RecentFileMenuItem 1 menuMan.updateMenuBar() -- finaly, open the file in the editor edit f ) )


I use it as a replacement for the "Maxscript/Open Script" menu.
it stores the filenames in a RecentScripts.ini file
it also creates macroscripts each time a new file is opened.

Hope you find this usefull

Note: there seams to be a mistake in the macros.new documentation:
it says:
macros.new <name_string> <category_string> <toolTip_string> <buttonText_string> <body_string>

but I think the fist 2 arguments need to be inverted:
macros.new <category_string> <name_string> <toolTip_string> <buttonText_string> <body_string>

Last edited by Zbuffer : 10-13-2006 at 12:39 AM.
 
Old 10-13-2006, 09:04 AM   #3
davestewart
Repeat-customer
 
davestewart's Avatar
Dave Stewart
Animator / scripter
United Kingdom
 
Join Date: Sep 2004
Posts: 488
Cool stuff man!
I have a ton of "real" (!) work today, but I'll check it out first chance I get.
Cheers,
Dave
 
Old 10-13-2006, 01:02 PM   #4
PEN
R&D/Technical Director
 
PEN's Avatar
portfolio
Paul Neale
PEN Productions
Canada
 
Join Date: Jun 2002
Posts: 7,417
Zbuffer, Cool stuff, The only comment from me is it looks a bit messy because it creates more and more macro script files. Is there a way that you could just write the macro script lines using format to a single file so that the last used are all in one file?

Using popup menus I have populated them with an INI type file before. I wounder if the same method could be used here?
__________________
Paul Neale
http://paulneale.com
 
Old 10-13-2006, 06:08 PM   #5
Zbuffer
Expert
Wanabee Scripter
Finland
 
Join Date: Jan 2003
Posts: 568
update

Quote:
Is there a way that you could just write the macro script lines using format to a single file so that the last used are all in one file?


Yep, simple update, and true, it's much cleaner, so now even if you increase the MaxFile to 20, you only get 1 macroscript file called 'RecentScripts.mcr'

Thx for your comments guys, and glad i can give back to you from wich i have learned a lot !




Code:
------------------------------------------------------------------------ -- FileName: MaxScript-OpenScript.mcr -- Version: 0.2 -- Author: Zbuffer -- date: 28/09/2006 -- -- description: Replaces the MaxScript/Open Script menu and adds a 'Recent Scripts' menu to the MaxScript menu. -- usage: 1. Put this script in the <MAXROOT>\UI\MacroScipt folder. (or evaluate) -- 2. Go to the 'Customize/Customize User Interface' menu -- 3. On the 'menu' tab, replace/add the 'Maxscript/Open Script' with this one ('MaxScript' category). -- Tou can modify the Maxfiles variable if you want more than 10 recent files ------------------------------------------------------------------------- macroscript OpenScript category:"MaxScript" buttonText:"Open Script" ( local Maxfiles = 10 -- Number of recent files in the Menu local ScriptDir = (getdir #scripts)+"\\" -- Always show the open file dialog in this folder. local INI = (getdir #plugcfg)+"\\RecentScripts.ini" local FileCount = getINIsetting INI "FileCount" "Count" if FileCount == "" then FileCount = 0 else FileCount = FileCount as integer -- check for 1st run local Recentfiles=#() -- array holding the recent file names -- browse for a file to open. local f=getOpenFileName caption:"Choose Editor File" fileName:ScriptDir types:"All Scripts(*.ms;*.mcr)|*.ms;*.mcr|MaxScript(*.ms)|*.m s|Macroscript (*.mcr)|*.mcr|Text Files (*.txt)|*.txt|All|*.*|" if f !=undefined do ( -- fix path string while ((i=findstring f "\\") != undefined) do f=replace f i 1 "/" -- Update the Recent Scripts list for i=1 to FileCount do append Recentfiles (getINIsetting INI "FileList" ("File"+i as string)) if ((finditem Recentfiles f) == 0) then (insertItem f Recentfiles 1) else ( deleteItem Recentfiles (finditem Recentfiles f) insertitem f Recentfiles 1 ) if RecentFiles.count>Maxfiles do deleteItem Recentfiles (Maxfiles+1) -- Write the list to the INI file for i=1 to Recentfiles.count do setINIsetting INI "FileList" ("File"+i as string) Recentfiles[i] setINIsetting INI "FileCount" "Count" (Recentfiles.count as string) -- Build the menu local ScriptMenu = MenuMan.findMenu "&MAXScript" -- delete the Recent Scripts Menu if it exists if ((Scriptmenu.getItem 1).getTitle())=="Recent Scripts" do ScriptMenu.removeItemByPosition 1 -- Create the Recent Scripts Menu local RecentFileMenu=MenuMan.createMenu "Recent Scripts" -- create Macroscripts for the menuitems local MCRname=getdir #ui +"\\MacroScripts\\RecentScripts.mcr" local MCR=openfile MCRname mode:"w" for i=1 to Recentfiles.count do ( format "macroscript Script% category:\"Recent Scripts\" buttonText:\"% %\"\n(edit \"%\")\n\n" i i Recentfiles[i] Recentfiles[i] to:MCR ) close MCR filein MCRname -- create the submenuitems for i=1 to Recentfiles.count do ( local testItem = menuMan.createActionItem ("Script"+i as string) "Recent Scripts" testItem.setTitle Recentfiles[i] RecentFileMenu.additem testItem -1 ) -- add the subitems to the menu local RecentFileMenuItem = menuMan.createSubMenuItem "RecentScripts" RecentFileMenu -- add the menu at the 1st position in the MAxscript menu ScriptMenu.additem RecentFileMenuItem 1 menuMan.updateMenuBar() -- finaly, open the file in the editor edit f ) )
 
Old 10-13-2006, 06:08 PM   #6
CGTalk Moderation
Expert
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,478
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 01:34 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.