Notifications
Clear all

[Closed] struct reference to a .NET TreeNode

I’m trying to build a .NET interface for my script, with a TreeView that contains a set of nodes with children (like a scene hierarchy).

First off I’d like to say I’m a newbie when it comes to .net. I managed to build the interface but only with the help of MaxScript and MSDN reference articles, google and a bit of trial&error.

Now I want to “assign” certain maxscript variables to each TreeNode in such a way that I can access the variables through the nodes.
The way I found to do this is through the tag property. This seems to work for integers, strings and even arrays. But when I try to assign a custom maxscript struct to a tag, I get the following error:
>> MAXScript dotNet event handler Exception:
– Unable to convert: … to type: System.Object <<

I think maxscript tries to convert the assigned variable to a .net object, and it doesn’t work for structures. So my questions are:

  1. Is there a way to reverence a maxscript struct in a .net TreeNode without converting it?
  2. How can I convert the struct to a .net object, or is there an equivalent in .net? I found something but I can’t figure out how to use it in maxscript.
6 Replies

dotnetmxsvalue is for that…

try(destroydialog tv) catch()
rollout tv "Tree View Sample" width:200 height:132
(
	struct TVData (items = #(), names = #())
	local def = TVData #("A", "B", "C") #("Anna", "Bella", "Clara")
	
	dotnetcontrol tv "TreeView" width:190 height:100 pos:[5,5]
	dotnetcontrol tx "TextBox" width:190 pos:[5,107]
		
	on tv AfterSelect s e do
	(
		ss = stringstream ""
		format "% >> %
" e.node.text s.tag.value.names[e.node.index+1] to:ss
		tx.text = ss as string
	)
	on tv open do
	(
		tv.tag = dotnetmxsvalue def
		for d in def.items do tv.nodes.Add d
	)
) 
createdialog tv  

Thanks for the solution denis! dotnetmxsvalue does exactly what I wanted.

I also learned something new, I had no idea you can add .net elements to a maxscript rollout via dotnetcontrol. I already went ahead and created a whole .net form interface, but I’ll keep it in mind for future projects.

Thanks again!

P.S. I am still curious if and how I could define a .net structure in maxscript. So if anyone is familiar with this, please shed some light.

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

what is .net structure in your case?

Basically I want the equivalent of this in .net:

struct sceneObject(name, transform, meshLink, material)

so I can like this:

def = sceneObject "Some mesh" (matrix3 1) 123 Standard()
anode = dotNetObject "System.Windows.Forms.TreeNode"
anode.text = def.name
anode.tag = def --this is where I get the error because struct is not a dotNet object

anode.tag = dotnetmxsvalue def works of course, but as I’ve said I’m curious if a more direct approach is possible.

In other words, I want to know if it is possible to define a .net struct in maxscript

public struct Book
{
    public decimal price;
    public string title;
    public string author;
}

@lo OK, thanks!

2 Replies
 lo1
(@lo1)
Joined: 11 months ago

Posts: 0

Absolutely not.

(@wallworm)
Joined: 11 months ago

Posts: 0

And that, my friends, is absolutely not nice!