[Closed] 3 dotnet classes
Hi guys, I wrote 3 new classes based on currently existing controls to improve the speed in a script I’m currently doing.
This new classes are :
dnFolders : Based on a treeview but with 3 new methods:
- dnFolders.ProcessTree(path as String) : This fills the treeview with the path and it’s subdirectories, ignoring directories named “thumbs” (lowercase)
- dnFolders.ProcessFile(e as System.Windows.Forms.TreeNodeMouseClickEventArgs) : This one is intended to be used on the NodeMouseClick event where you pass the variable e to the method and it fills dnFolders.NodeFiles with the files contained in that directory (currently it reads only jpg,tga,tif and max extensions)
- dnFolders.ProcessThumbs(nFiles() as String) : This one, for use after the last method described, searchs within the current folder plus ” humbs” for a thumbnail file with the same name as the ones stored in nFiles()
dnThumbs : Based on a flowlayoutpanel with 1 new method to populate with dnPicBox
- dnThumbs.CreateThumbs(tFiles() as String, dnFiles() as string) : This method is quite simple, it just goes thru all the thumbnail stored previously and adds a picture box to the control, the thing is that by doing this way I was able to fill it up 3/4 times faster! In Maxscript it was taking 12 seconds to populate the flowlayoutpanel and now it takes 3 seconds!
dnPicBox: Based on picturebox but with a diferent constructor, you need to add a name string to the picturebox and that string will be used for drag and drop. So if you put the name of the picturebox to “c: est.jpg” then when you drag and drop the picturebox it will perform a drag of that file.
Here’s a small example of what it can do for:
(
--Dont forget to change the path to where the class is located
dotnet.loadAssembly @"KClasses.dll"
-- Create Form
local hForm = dotNetObject "MaxCustomControls.MaxForm"
hForm.Size = dotNetObject "System.Drawing.Size" 1024 768
hForm.FormBorderStyle = (dotnetclass "System.Windows.Forms.FormBorderStyle").FixedToolWindow
hForm.ShowInTaskbar = False
local tvFolders = dotnetobject "KClasses.dnFolders"
tvFolders.Dock = (dotnetclass "System.Windows.Forms.DockStyle").Left
tvFolders.Size = dotNetObject "System.Drawing.Size" 200 350
--Dont point the ProcessTreeMethod to C:\ or whatever, because it goes thru all the subdirs and that may take a while if you are only testing it
tvFolders.ProcessTree(@"C:\Documents and Settings\Administrator\My Documents\3dsmax")
local flThumbs = dotnetobject "KClasses.dnThumbs"
flThumbs.Dock = (dotnetclass "System.Windows.Forms.DockStyle").Fill
flThumbs.AutoScroll=True
hform.controls.add(flThumbs)
hform.Controls.Add(tvFolders)
fn tvFolders_MouseDown sender eb =
(
hittest= tvFolders.Hittest(eb.location)
if hittest.location==(dotnetclass "System.Windows.Forms.TreeViewHitTestLocations").Label then
(
start=timestamp()
flThumbs.Controls.Clear()
tvFolders.ProcessFiles(eb)
tvFolders.ProcessThumbs(tvFolders.NodeFiles)
flThumbs.CreateThumbs tvFolders.NodeThumbs tvFolders.NodeFiles
end=timestamp()
format "Processing took % seconds
" ((end - start) / 1000.0)
)
)
dotnet.addEventHandler tvFolders "NodeMouseClick" tvFolders_MouseDown
hForm.ShowModeless()
)
Nice Artur, thanks for sharing.
Hopefully get to take a peek at this later on!
Top dot nettage artur, I’ve been meaning to write a derived treeview for a while, you have saved me the job! keep it up!
Thanks guys, I forgot to mention that when the treeview is filled each node contains in the .Tag property the full path to the directory. Anyway, if you remind of something that could be implemented please let me know, I would love to write more custom classes or add more functionality to these ones Cheers!
Just a thought Artur, since you are deriving the treeview, you could override the node event handler and place the filepath in the event handler rather than the tag property.
one question that i’ve never figured out is what are the advantages to using “MaxCustomControls.Maxform” over the standard “windows.form” class. I know its been written for max integration but what are the actual difference between the two. I had noticed the huge performance gain from coding dotnet forms over MXS ones with dotnetcontrols.
I just use the Maxform because of the focus and keystrokes on textboxes, also, I’ve noticed that when using app.run max viewport didn’t refresh correctly, so this is actualy the best form to integrate some app in max I think, maybe the guys at autodesk will correct those things who knows, the only thing I really dont like is that the max form inherits all colors from max and doesnt allow you to change them, background color for instance…
Just a thought Artur, since you are deriving the treeview, you could override the node event handler and place the filepath in the event handler rather than the tag property.
Sorry I didnt quite get this one, could explain better? Sorry, sometimes I have a hard time getting some technical/programatic english
hi artur, thanks for that- i didn’t know about the keystroke/color things. so does it not allow you to enter text or something?
As for the treeview thing, sorry, i’ll explain a bit more. I may have this wrong but you said that you are placing the filename inside the tag property? If so, I just suggested that you could write a custom event handler (or one that overrides the original treeview selected node one) that places that info string into there,that way the user can retrieve this directly from the event handler aguments. it keeps it inside the control and allows you to provide error checking on that basis, rather than a public property. You are also giving the user the ability to get a meaningful event property like e.filename rather than sender.tag. Not a issue, but just a different way.
I think I got it, I’ll see that this afternoon
As for the Maxform, I think you got it wrong, the Maxform, when you add a textbox, it focus and gets the text correctly, while using System.Windows.Forms you cant, there’s some threads about this here on cgtalk. One way to get around this was using App.Run instead of the hForm.Show() to display the form (this while using System.Windows.Form) and that way the text box works correctly, but while using that method in my asset management script, I found that with App.Run, the viewport in max, while dragging and dropping a texture into the viewport for example, didn’t refresh, so that’s why I prefered to use MaxForms.
Ah okay, i missed that post. cheers.
The other issue with drag and drop with a max script rollout is that when positioned over a viewport , it triggers the drop while on the control itself, meaning you have to use the .clientrectangle property to check it's outside the form. I updated the info on my [site]( http://www.lonerobot.com/filedrop.html) about this issue with a slightly hacky fix. With a dotnet form you do not get this behaviour. However the safest way of controlling drag/drop operations from what i can see is to implement it via a dotnet form in the first place rather than a max dialog floater.
In fact MaxForm class is from 3ds Max .NET SDK.
So, initially it was designed to be used in plugins mixing managed (C++) / unmanaged (VB.NET, C#, C++/CLI…) code and being able to integrate Windows Forms Form and Controls in 3ds Max user interface.
If you look at the documentation of the .NET SDK, you’ll see there’s some other classes and methods useful in MAXScript:
MaxTextBox
MaxToolStripComboBox
MaxToolStripTextBox
AppSDK.GetMainApplicationIcon()
AppSDK.GetMaxHWND()
Win32API.BringWindowToTop()