dotNet + MXS


sorry… I don’t understand what you want to do… your code is working but I don’t know what you suppose to get.

what nodes do you want to add (or remove) dynamically?


i just need a way to loop trough all TreeNodes and append their name into the array.

so adding or removing something, the result will be different e.g.
if you add a node at parent a (NEW) i want hierarchy_ARRAY = #(a,b,c,d,e,f,g,h,i,NEW)


[b]dotNetObject:System.Windows.Forms.TreeView [/b]
[i][b]GetNodeCount includeSubTrees[/b][/i]


i tried to use this form but didn´t work…


do you want to get all node names of a tree view hierarchal?

try(destroydialog treeRol) catch()
rollout treeRol "Tree View" 
 dotNetControl tv "TreeView" width:190 height:160 pos:[4,4]
 button getNames "Get Names" 
 local root = "root"
 local a = "a", b = "b", c = "c", d = "d", e = "e", f = "f", g = "g", h = "h", i = "i", j = "j"
 fn initTreeView =
  root = #(root)
  one = #(a,b,c,f)
  two = #(d,e)
  three = #(g,h)
  four = #(i,j)
  roots = for n in root collect (dotNetObject "TreeNode" n)
  ones = for n in one collect (dotNetObject "TreeNode" n)
  roots[1].nodes.addRange ones
  twos = for n in two collect (dotNetObject "TreeNode" n)
  ones[3].nodes.addRange twos
  threes = for n in three collect (dotNetObject "TreeNode" n)
  ones[4].nodes.addRange threes
  fours = for n in four collect (dotNetObject "TreeNode" n)
  threes[2].nodes.addRange fours
  n = tv.nodes.addRange roots
[color=yellow] fn getnodename node list:#() = 
  if node != undefined do
   if (node.gettype()).tostring() == "System.Windows.Forms.TreeNode" do append list node.text
   for i=0 to node.nodes.count-1 do list = getnodename node.nodes.item[i] list:list
 on getnames pressed do
  list = getnodename tv
  print list
 on treeRol open do 
createdialog treeRol width:200 height:200 [/color]

but i don’t understand a reason of doing it… TreeView is a hierarchal list already…


yes denisT, that´s exactly what i want, thanks for that !!

another question:

how to clean up the TreeView,
e.g. delete all nodes (or back it to default nodes) ?




great denisT, thank you very much !

works like a charm.


how to check if a TreeNode has another TreeNode as parent/children and print it ?


'-> a

ItemName: a
parent: root
children: b


every tree view node has the “parent” and the “nodes” properties.
“parent” contains a parent node, “nodes” is collection of children nodes

if node.parent != undefined do print node.parent.text --(or whatever you want)
for n=0 to node.nodes.count-1 do print node.nodes.item[n].text 
-- where node is a tree view node


thanks again


Is it possible to use a WPF (windows Presentation Foundation) control using maxscript. I’m trying to host one in a custom forms control but haven’t managed to get it to work (yet). The custom forms control displays but not the WPF control inside it. Any thoughts?


Hi guys,

I am trying to open up a socket in max so that I can send commands from a javascript but I have no idea where to start. My understaning is that you can do it through .net.

What I am trying to achieve is to build a box inside max by pressing a button in a web page then to display the name of the newly created box back in the web page.

Any ideas are greatly appreciated!


Hey guys,
Here are two snippets I’ve wrote recently, one for printing files and the other to get hashs (MD5, SHA1) from text and from files. Hope it’s of you to someone. Cheers.



Is it possible to use a image processing libary like image magick for a scriptet RenderEffect?



Strange timing.

I started playing around with the MagickNET, a .NET wrapper for ImageMagick that can be loaded into MXS, just the other day.

I chose to compile it from source but you may be able to locate a pre-compiled version. I didn’t do much other than verify that I can use it to load and save files.

I’m trying to find an easy to use library that will allow me read PSD files, fiddle with their image layers and then write them back out.


Could anyone successfully use ManagedServices.MaxColorPicker and ManagedServices.MaxSpinner from ManagedServices.dll? Without events they are useless. But I have know idea how to set event properties up from MXS. Does anyone know?


Hi Dennis,

I asked about maxspinner on the autodesk blog a while back, thinking it was a dotnetcontrol that would get around the decimal/integer casting issue - the reply i got was -

MaxSpinner is a wrapper class that takes the Spinner custom control that we expose in Win32 and provides a managed interface so that it can be used in an interop solution. This means that we take care of instantiating the class, but the client would need to grab the handle, using MaxNativeControl::HostWindowHandle, and embedd it in an interop solution (such as System.Windows.Interop.HwndHost in WPF.)

Mike -

is this any use to you? As for external image libraries, I have used AdvancedImageLibrary (a wrapper for the freeimage project) and tried All were a bit lacking with 64bit support. I knew ImageMagick has a 64bit release but I couldn’t get it to compile, could you give me a few pointers?


I played around ways of creating delegates…

Here is some code that will create a proxy object with a method that takes the correct type for the event handler. You can can use it to bind to the ColorChanged and ColorConfirmed delegate properties.

The technique may turn out to be useful in other situations where need to add a delegate to something that is opaque to MXS.

fn CreateMXSProxy forceRecompile:false =
	if (forceRecompile or 
		(classof ::MXSProxyAssembly) != dotNetObject or 
		((::MXSProxyAssembly.GetType()).ToString()) != "System.Reflection.Assembly") do
		sb = "using System.Text;
		sb += "class MXSProxy
		sb += "{
		sb += "  public System.String cmd;
		sb += "  public MXSProxy() {
		sb += "  }
		sb += "  public void Invoke(System.Object obj, CSharpUtilities.ValueChangedEventArgs<System.Drawing.Color> clr) {
		sb += "    if (cmd.Length > 0) {
		sb += "      StringBuilder newcolor = new StringBuilder();
		sb += "      StringBuilder oldcolor = new StringBuilder();
		sb += "      StringBuilder cmdcolor = new StringBuilder();
		sb += "      newcolor.AppendFormat(\"(color {0} {1} {2} {3})\",clr.NewValue.R,clr.NewValue.G,clr.NewValue.B,clr.NewValue.A);
		sb += "      oldcolor.AppendFormat(\"(color {0} {1} {2} {3})\",clr.OldValue.R,clr.OldValue.G,clr.OldValue.B,clr.OldValue.A);
		sb += "      cmdcolor.AppendFormat(cmd,newcolor,oldcolor);
		sb += "      ManagedServices.MaxscriptSDK.ExecuteMaxscriptCommand(cmdcolor.ToString());
		sb += "    }
		sb += "  }
		sb += "}

		csharpProvider = dotnetobject "Microsoft.CSharp.CSharpCodeProvider"
		compilerParams = dotnetobject "System.CodeDom.Compiler.CompilerParameters"
        compilerParams.ReferencedAssemblies.Add((getdir #maxroot) + "CSharpUtilities.dll");
        compilerParams.ReferencedAssemblies.Add((getdir #maxroot) + "ManagedServices.dll");
		compilerParams.GenerateInMemory = true
		compilerResults = csharpProvider.CompileAssemblyFromSource compilerParams #(sb)
		if (compilerResults.Errors.Count > 0 ) then
			errs = stringstream ""
			for i = 0 to (compilerResults.Errors.Count-1) do
				err = compilerResults.Errors.Item[i]
				format "Error:% Line:% Column:% %
" err.ErrorNumber err.Line \                                              
													 err.Column err.ErrorText to:errs 
			MessageBox (errs as string) title: "Errors encountered while compiling C# code"
			format "%
" errs
			::MXSProxyAssembly = undefined
			return undefined
			::CreateMXSProxyAssembly = compilerResults.CompiledAssembly
	::CreateMXSProxyAssembly.CreateInstance "MXSProxy"

-- Create a delegate that will forward the event properties on to maxscript
ccehType = (dotnet.gettype "ManagedServices.ConfirmColorEventHandler") 
changeDelly = (dotnetclass "Delegate").CreateDelegate ccehType (CreateMXSProxy()) "Invoke"
confirmDelly = (dotnetclass "Delegate").CreateDelegate ccehType (CreateMXSProxy()) "Invoke"

mcp = dotnetobject "ManagedServices.MaxColorPicker"
mcp.ColorChanged = changeDelly
mcp.ColorConfirmed = confirmDelly

-- You can combine delegates to allow more than one event handler	
-- mcp.ColorChanged = changeDelly.combine mcp.ColorChanged changeDelly

-- Note that these are C# string formating rules. You should be able to modify the maxscript that executes dynamically = "Print \"Changing from {0} to {1}\"" = "Print \"Confirm!\""



thank you Mike for your mxsproxy. but it’s not working if i construct colorpicker dialog as

mcp = dotNetObject “ManagedServices.MaxColorPicker” (dotnetobject “System.IntPtr” (windows.getMAXHWND())) on “”

it’s only way how to get it with alpha.
i’m sure it’s a MAX bug.

another problem is a function called in the event has to be global or has to have full path. which is not good in my case.

anyway… you’ve pointed me to the right direction and i thank you so much.


Thanks for the link (of course I’d already checked your site out beforehand, I’m a fan… :slight_smile:

I was hoping to be able to do the ‘simple’ stuff I wanted to without having to require photoshop. Not much luck. I’ve worked with/in ExtendScript in the past. That may be the way I have to go this time too.

I only compiled the 32 bit release of MagicNET and I ground through the process without taking notes. IIRC, I had to tweak it (MagicNET source) a little to link with the latest version of ImageMagick …something about the way ‘virtual pixels’ were exposed changed?

Anyhow, I’ll give 64 bit a try when I get a chance and pay more attention along the way.


Hi Mike,

That would be great if you get the time. I couldnt find the free .net wrapper for the freeimage project. It looks like it has been withdrawn. My forays into 3rd party image libraries are -

it is very fast and reasonably priced, but alas no 64bit support for freeimage.

another option is -

I tried the 32bit and it worked well enough.