dotNet + MXS


I’d prefer it to be translated over to the cgWiki like the geometrical calculations thread has been, but it’s your call. It would be great to be able to cross-reference it with stuff like this.


Why not do it both? I like Pauls site and have it under my favourites… I never seem to get around wiki’s, don’t understand the navigation of these things… :shrug:



I certainly have no problem with that, I’m just doing my job as a wiki/max moderator. :smiley:


While my brain was melting after a major commercial I did this to include in my scripts, it’s a .ms file with class declarations to help the programming of .Net stuff, after that I’ve created a small script to enumerate all the variables assigned in that file… the files are quite self-explanatory.

I also added a variable called New that executes the string “dotNetObject” so when we want to create some object we can do something simple as textbox = new dotNetTextBox. There’s still so much thing to add but that’s the basic stuff I’ve seen on MSDN.

I’ll add more as I need and you can also do the same, just keep the same structure, so when you run the Enumerate script it creates a .txt file with all the correct declarations and it’s easier to share with others updated versions of the file. Hope you like it and feel free to download and improve it! Cya

PS - Both files need to be in the same directory.


Knock yourself out! I think it’s great idea…the forum can get a little messy from time to time



Yes Please. I have a maxscript file which I’m making with as much .net as humanely possible in one script as I learn so that I have a clipboard to copy paste code snipets from and reference.

A community effort would be very useful since .net is very very sparsely documented in the help and translating C# into maxscript syntax is for me a trial and error process.


Has anyone gotten something like a contextual menu to work?

I can do something like:

contextMenu = dotNetObject "System.Windows.Forms.ContextMenu"

But when it comes to creating it, I am unsure how to do that




A .NET Forms ContextMenu can only be shown over a .NET Forms control. Is trackview a .NET Forms control ?


I have this working, but I don’t know how to get the selected item back… will update when i figure it out.

on tv nodeMouseClick arg do
       if arg.button == tv.mousebuttons.right then
    	   contextMenu = dotNetObject "System.Windows.Forms.ContextMenu"
    	   contextMenu.MenuItems.Add("Select all children")
    	   contextMenu.MenuItems.Add("Expand branches")
    	   pointTest = (dotNetObject "System.Drawing.Point" arg.x arg.y)
    	   contextmenu.Show tv pointTest


Got it with some help from my friend MarcoK!

fn OnClick sender args =
     --print sender.Text
     case sender.Text of
 	 "Expand branches": if tv.selectedNode != undefined then tv.selectedNode.ExpandAll()
   on tv nodeMouseClick arg do
     if arg.button == tv.mousebuttons.right then
 	 contextMenu = dotNetObject "System.Windows.Forms.ContextMenu"
 	 dotnet.addeventhandler (contextMenu.MenuItems.Add("Select all children")) "Click" OnClick
 	 dotnet.addeventhandler (contextMenu.MenuItems.Add("Expand branches")) "Click" OnClick
 	 pointTest = (dotNetObject "System.Drawing.Point" arg.x arg.y)
 	 contextmenu.Show tv pointTest


I finally went on and picked up on dotnet. It’s not as hard as I thought :slight_smile:
But I do have a refresh problem. I do an label edit and with the “AfterLabelEdit” eventhandler I update the listview i have. The problem I have is that
listview.items.clear() works but appearantly not for the label that was edited…!?

I create an extra refresh button and after pressing that it does work… The edited label simply renames an object. It looks like after renaming the script is faster to update the labels than max with renaming the object… any suggestions?

Also, is listview the right way to go when I want to also edit the other fields in a row? It looks like I can’t but maybe I’m missing something?



For the label edit, I don’t have an immediate solution…as for editing the other columns, you can’t do it…well actually there is a hack, but I don’t think we have enough access into dotnet via maxscript to get it to work.

The listview only allows for the editing of the first column. If you want to update the other columns, I suggest having a look at one of the grids. That should provide you with the ability to edit the cells.

I’ve been poking at the idea of writting my user interfaces in Java and using the COM access to send commands back to Max. I know the COM part works, but I’ve not had much time to look into the rest…but this is for a very particular idea…



To edit the other fields you can get the placment of the mouse over the field and determine which it is. Then move and editText field to that location for the user to imput information into.

A hack but it works.


How do you get a reference to the editfield? Do you create own? How do you place it within the control??

All the code I’ve seen that does this seems to rely on obtaining window handles…?!?



Hi Paul / Shane, thanks for that I will look into it! If it isn’t what I want or too much of a hack, which datagrid object would you suggest? The thing I need is almost like the new max2008 scene explorer.

Here’s a script snippet, too demonstrate that the label is not updating… any suggestions are welcome!

Create some camera’s, run the script. Rename camera via label by clicking a label and wait a sec. Then edit and hit enter or click outside. The object gets renamed properly, the list gets updated and the renamed object moves to the right location. Although the labelplace where the object was doesn’t seem to follow along… bit hard to exlpain, please have a look.


(I’ll be gone for 2 days so if I don’t respond it’s not because I don’t care, cause I do :wink: )


I have been using “system.IO.file” for managing files how ever I’m stuck on setting permissions on a file and how to set it to readOnly. Any one know where I should be looking?


Oh and does any one know where I can down load the .net library from MSDN so speed up searches?


You’ll have to forgive the code, I pulled it directly from the MSN docs, but

File.SetAttributes(path, File.GetAttributes(path) Or FileAttributes.ReadOnly) 

should be able to set the attribute

If (File.GetAttributes(path) And FileAttributes.ReadOnly) = FileAttributes.ReadOnlyThen

should return true if the file is readonly.



I know a version comes with Visual Studio, it’s what I use. If someone can tell me if I’m allowed to “upload” it here, I will.



I’ll have a poke, thanks.