Dynamic Dropdownlist

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 06 June 2011   #1
Dynamic Dropdownlist

What would be the best way to dynamically load a dropdownlist.

I have a dropdownlist which has all my maxscript in it. When i create a new one or place a new one within the folder on my desktop Id like when I open the dropdown list that it be updated with all the new scripts.

Any thoughts on this?
My initial thought would be to do a timer which updates ever so often which I would assume to be taxing.
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 06 June 2011   #2
idea

try(destroydialog ::drop_roll)catch()
rollout drop_roll "Drop Down List"
(
local obj_arrayA = #("1","2","3","4","5")
local obj_arrayB = #("6","7","8","9","10")

dropdownlist obj_dd "Objects :" offset:[0,-20] items:obj_arrayA

fn fnUpdateList = obj_dd.items = (join obj_arrayA obj_arrayB)

on obj_dd rightClick do fnUpdateList()

)
createDialog drop_roll
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 06 June 2011   #3
You could look into a dotnet FileSystemWatcher object if realtime update is so crucial.
 
Old 06 June 2011   #4
Originally Posted by JokerMartini: What would be the best way to dynamically load a dropdownlist.

I have a dropdownlist which has all my maxscript in it. When i create a new one or place a new one within the folder on my desktop Id like when I open the dropdown list that it be updated with all the new scripts.

Any thoughts on this?
My initial thought would be to do a timer which updates ever so often which I would assume to be taxing.


i would use .net ComboBox and its DropDown event. All things with timer are slowing down the system.
 
Old 06 June 2011   #5
See my post in your other dropdownlist thread, here, for a .net combobox example.

denisT, do you know how to get the DropDownStyle to work? My tests don't disable the combobox text entry and break the dropdown function. Or do you need to use the MaxCustomControls.MaxToolStripComboBox to get the DropDownStyles to work?

-Eric
__________________
"The Evil Monkey hiding in your closet."
 
Old 06 June 2011   #6
Originally Posted by PiXeL_MoNKeY:
denisT, do you know how to get the DropDownStyle to work? My tests don't disable the combobox text entry and break the dropdown function. Or do you need to use the MaxCustomControls.MaxToolStripComboBox to get the DropDownStyles to work?


Strange, using DropDownStyle.DropDownList works fine for me without MaxCustomControls...
 
Old 06 June 2011   #7
I found a nice method that I converted from VB to use with a combobox - it calculates the maximum width of the text strings in the dropdown and adjusts the width accordingly. You use the dropdown event to fire this function and pass the combobox as the argument (depending of the scope of the function of course)

	
-- function calculates the max width of an item string in the dropdownlist and adjusts the comboboxdropdown accordingly. Is called by the dropdown event
fn FindWidthForDropDown ComboBox =
(
     local g = ComboBox.CreateGraphics()
     local WidestWidth = ComboBox.DropDownWidth
     local ValueToMeasure 
     local CurrentWidth 
     local vertScrollBarWidth = if ComboBox.Items.Count > ComboBox.MaxDropDownItems then ((dotnetclass "systeminformation").VerticalScrollBarWidth)*2 else 0
     For i = 0 To ComboBox.Items.Count - 1 do 
		(    
		ValueToMeasure = ComboBox.Items.item[i]
                CurrentWidth = (g.measurestring ComboBox.items.item[i] ComboBox.font).width +vertScrollBarWidth
		If CurrentWidth > WidestWidth Then WidestWidth = CurrentWidth
		)

     ComboBox.DropDownWidth = WidestWidth
     g.Dispose()
)


so you can set this up as so -

on cmbcontrol dropdown sender args do FindWidthForDropDown sender


p.s eric- DropDownStyle.DropDownList works for me also
__________________
Regards,
Pete

Read my technical blog - lonerobot.net

Last edited by LoneRobot : 06 June 2011 at 05:01 PM.
 
Old 06 June 2011   #8
Alright

It sounds like dotNet is the way to go for this type of thing. I'll look into it and see what I can get. I'm not to familiar with the dotNet controls at all. But I'm more than up for a new challenge.
I'll be sure to post what I end up with to see what you guys think.
Thanks
JokerMartini
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 06 June 2011   #9
Start

This is what I have so far for the maxscript side of things.


(
	local directory = "Q:\ASSETS\John-Martini\Scripts\JokerMartini\_MyTools" -- Targeted scripts folder 
	local sFiles = getFiles (directory + "\\*.ms*")
	local ScriptsArray = #()
	local thisScript = 1
	local ScriptName = 1
	
	sort sFiles
	
	ScriptsArray = for file in sFiles collect
	(
		local fIndex = findItem sFiles file
		local fbName = "b" + (fIndex as string)
		(getFIleNameFile file)
	) 
		
	rollout rlScriptList "Scripts"
	(
		dropdownlist ScriptsList "" width:170 pos:[2,2] items:ScriptsArray height:23
		button btnOpenScript "Run Script" width:87 height:26 pos:[0,24]
		button btnEditScript "Edit Script" width:87 height:26 pos:[87,24]
		
		on ScriptsList selected i do 
		(
			thisScript = i
			ScriptName = ScriptsList.items[i]
		)
		
		on btnOpenScript pressed do
		(
			execute (openfile (sFiles[thisScript] as string))
			print ScriptName
			try(destroyDialog rlScriptList)catch()
		)
		
		on btnEditScript pressed do
		(
			if thisScript != undefined do (edit (sFiles[thisScript] as string))
			print ScriptName
			try(destroyDialog rlScriptList)catch()
		)
	)
	createDialog rlScriptList 174 50 500 200
)
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 06 June 2011   #10
DotNet Version

This is what I have so far for the dotNet version.
This is great by the way. Thank you everyone!
However I'm not sure how to get the count property for the combobox to use to execute the script.

I'm open to different methods of calling up the script, whether its using its "string name" or by the order its placed in the array. Whichever is most efficient and fool proof.


 --Change the local variable "Directory" to a folder filled with just .ms scripts for max
 --After that the scripts list will be ordered alphabetically with all the scripts found in the targeted folder
 --Select a script in the dropdownlist and then evaluate the script and the rest is self explanatory
 
 try(destroyDialog ::rlScriptList)catch()
 (
 	local directory = "Q:\ASSETS\John-Martini\Scripts\JokerMartini\_MyTools" -- Targeted scripts folder 
 	local sFiles = getFiles (directory + "\\*.ms*")
 	local ScriptsArray = #()
 	local thisScript = 1
 	local ScriptName = ""
 	
 	sort sFiles
 	
 	rollout rlScriptList "Scripts"
 	(
 		dotNetControl dlScriptsList "System.Windows.Forms.ComboBox" height:20 width:160 pos:[10,10]
 		button btnOpenScript "Run Script" width:80 height:28 pos:[10,40]
 		button btnEditScript "Edit Script" width:80 height:28 pos:[90,40]
 		
 		
 		fn fnUpdateList = -- collects scripts and sorts them
 		(
 			-- Collect the scripts into an array
 			ScriptsArray = for file in sFiles collect
 			(
 				local fIndex = findItem sFiles file
 				local fbName = "b" + (fIndex as string)
 				(getFIleNameFile file)
 			) 
 			-- Clear the ComboBox list
 			dlScriptsList.items.clear()
 			-- Build a new ComboBox list using the view array
 			dlScriptsList.items.addrange ScriptsArray
 		)
 		
 		on dlScriptsList open do (fnUpdateList()) --Fill on open
 		on dlScriptsList DropDown do (fnUpdateList()) --Fill on expanding the list
 		
 		on dlScriptsList SelectedIndexChanged do
 		(
 			--Command to execute on selecting the entry
 			ScriptName = dlScriptsList.text
 		)
 		 
 		on btnOpenScript pressed do
 		(
 			execute (openfile (sFiles[thisScript] as string))
 			print ScriptName
 			try(destroyDialog rlScriptList)catch()
 		)
 	
 		on btnEditScript pressed do
 		(
 			if thisScript != undefined do (edit (sFiles[thisScript] as string))
 			print ScriptName
 			try(destroyDialog rlScriptList)catch()
 		)
 	)
 	createDialog rlScriptList 180 80
 )
 
 
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com

Last edited by JokerMartini : 06 June 2011 at 05:41 PM.
 
Old 06 June 2011   #11
refs code

Hey John,
if i see correct the final goal then
maybe this script will be interesting to you.

utility scriptBrowser "MXS Browser"
(
	local rootDir = GetDir #scripts
	local sdLength = rootDir.count + 1
	local templist = #()
	local subDirs = for d in GetDirectories (rootDir + "\\*") collect d
	local visDirs = for s in subDirs collect (replace s 1 sdLength "")
	local files = getFiles (subDirs[1] + "\\*.ms")
 
	DropDownList currDir "" items:visDirs
	ListBox filelist
	radiobuttons action labels:#("Edit", "Run")
 
	function UpdateFiles = (
		if files.count != 0 then (
			for f = 1 to files.count do templist[f] = FilenameFromPath files[f]
		filelist.items = templist
		) else filelist.items = #()
	)
 
	on scriptBrowser open do ( UpdateFiles() )
	on filelist doubleClicked itm do if filelist.selection != 0 do
	(
		local itmFile = (rootDir + "\\" + currDir.selected + templist[itm])
		case action.state of (
			1: edit itmFile
			2: FileIn itmFile
			default: edit itmFile
		)
	)
	on currDir selected i do
	(
		templist = #()
		files = getFiles (rootDir + "\\" + currDir.items[i] + "\\*.ms")
		UpdateFiles()
	)
)


It may need update only if you create new folder
Its a bit old, one of my first scripts ever
but you know, i like the simple staffs
and i use it as it is all the time
Attached Files
File Type: zip MXSBrowser.zip (637 Bytes, 5 views)
__________________
* everyone can win previous war

Last edited by Panayot : 06 June 2011 at 11:12 PM.
 
Old 06 June 2011   #12
bug!

I've hit a snag.
In this script the dropdown list label/text is "Scripts List:"
I want that word to remain in the list the entire time.
I've pasted the code here below on what I figured would work based on the things I know but for some reason the dropdownlist.text = "Scripts List:" will not overwrite it for some reason.

Is there a count property like the max dropdownlist has as well?


try(destroyDialog ::rlScriptList)catch()
(
local directory = "$scripts/Startup/" -- Targeted scripts folder
local sFiles = getFiles (directory + "\\*.ms*")
local ScriptsArray = #()
local thisScript = 1
local ScriptName = ""

sort sFiles

rollout rlScriptList "Scripts"
(
dotNetControl dlScriptsList "System.Windows.Forms.ComboBox" text:"Scripts List:" height:20 width:160 pos:[10,10]

fn fnUpdateList = -- collects scripts and sorts them
(
-- Collect the scripts into an array
ScriptsArray = for file in sFiles collect
(
local fIndex = findItem sFiles file
local fbName = "b" + (fIndex as string)
(getFIleNameFile file)
)
-- Clear the ComboBox list
dlScriptsList.items.clear()
-- Build a new ComboBox list using the view array
dlScriptsList.items.addrange ScriptsArray
)

on dlScriptsList open do (fnUpdateList()) --Fill on open
on dlScriptsList DropDown do (fnUpdateList()) --Fill on expanding the list

on dlScriptsList SelectedIndexChanged do
(
--Command to execute on selecting the entry
ScriptName = dlScriptsList.text
print ScriptName
dlScriptsList.text = "Scripts List:"
)
)
createDialog rlScriptList 180 40
)
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 06 June 2011   #13
Why not set that as your first item in the array and set your selected item back to the base entry? Then in your SelectedItemChanged event do a test if the selected item is 0 do nothing, else execute your code.

-Eric
__________________
"The Evil Monkey hiding in your closet."
 
Old 06 June 2011   #14
Alright.

Thanks for that idea. I'm going to go ahead an do it that way then.

JokerMartini
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 06 June 2011   #15
final concept!


	try(destroyDialog ::rlScriptList)catch()
	(
	local directory = "$scripts/Startup/" -- Targeted scripts folder
	local sFiles = getFiles (directory + "\\*.ms*")
	local ScriptsArray = #()
	local thisScript = 1
	local ScriptName = ""
	
	sort sFiles
	
	rollout rlScriptList "Scripts"
	(
	  dotNetControl dlScriptsList "System.Windows.Forms.ComboBox" text:"Scripts List:" height:20 width:160 pos:[10,10]
	
	  fn fnUpdateList = -- collects scripts and sorts them
	  (
	   -- Collect the scripts into an array
	   ScriptsArray = for file in sFiles collect
	   (
		local fIndex = findItem sFiles file
		local fbName = "b" + (fIndex as string)
		(getFIleNameFile file) 
	   )
	   -- Clear the ComboBox list
	   dlScriptsList.items.clear()
	   insertItem "Scripts List:" ScriptsArray 1
	   -- Build a new ComboBox list using the view array
	   dlScriptsList.items.addrange ScriptsArray
	  )
	
	  on dlScriptsList open do (fnUpdateList()) --Fill on open
	  on dlScriptsList DropDown do (fnUpdateList()) --Fill on expanding the list
	
	  on dlScriptsList SelectedIndexChanged do
	  (
	   --Command to execute on selecting the entry
	   ScriptName = dlScriptsList.text
	   print ScriptName
	   dlScriptsList.SelectedIndex = 0-- alternate = dlScriptsList.text = "Scripts List:"
	  )
	)
	createDialog rlScriptList 180 40
	)
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
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 08:15 PM.


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