[Closed] custom dotnet material tree script does nothing
Can anyone tell me why this tiny script won’t work?
lv = dotNetObject "MaxCustomControls.MaterialExplorerControls.MaterialExplorerDialog"
lv.show()
fn popup =
(
print "lol"
)
dotnet.addeventhandler lv "MouseClick" popup
Because the material explorer dialog is filled 100% with other controls, and there are no pixels that actually belong to the material explorer dialog itself, so clicking anywhere will trigger the mouseclick event for other controls, but not for the form itself.
without writing a dedicated c# assembly, the only way I can think of is to simple loop recursively over all your form’s controls, and add an event handler to each one.
Thanks guys but I’m still not sure how to access the material exporers controls…I’ve tried lv.controls, and got a dotnet object but how to inspect the collection? It doesn’t behave like an array at all -won’t accept an index. I’m sorry I know I’m being obtuse but the max help lists all the properties, methods, and events for this control and they run into the hundreds, but I still don’t understand why the events don’t work as expected.
Could you just post a fragment of code as a clue to how to inspect a control on this thing, because I’ve tried SelectedMaterialExplorerControl , activecontrol, tabindex…there’s so many possibilites I’m getting bogged down and frankly I still don’t see how I can use the events, or why even the onload event doesn’t work either… thanks for your time.
lv = dotNetObject "MaxCustomControls.MaterialExplorerControls.MaterialExplorerDialog"
lv.show()
global ctrls = #()
fn popup = print "lol"
fn addEventRecursive ctrl =
(
dotnet.addeventhandler ctrl "MouseClick" popup
append ctrls ctrl --for protection against garbage collection of events
for c = 1 to ctrl.controls.count do addEventRecursive ctrl.controls.item[c-1]
)
addEventRecursive lv
Thanks Io. I tried the following to get selected node or text of selected node:
lv = dotNetObject "MaxCustomControls.MaterialExplorerControls.MaterialExplorerDialog"
lv.show()
global ctrls = #()
fn popup sender arg = (hitNode = lv.GetNodeAt (dotNetObject "System.Drawing.Point" arg.x arg.y)
if hitNode != undefined do ( print hitNode.text ))
fn addEventRecursive ctrl =
(
dotnet.addeventhandler ctrl "MouseClick" popup
append ctrls ctrl --for protection against garbage collection of events
for c = 1 to ctrl.controls.count do addEventRecursive ctrl.controls.item[c-1]
)
addEventRecursive lv
But obviously it can’t work because GetNodeAt is not a method of the customcontrol, so I am left pondering what to do. Any help greatly appreciated…
Obivously you don’t want that event on every control of the form, but only the treeview.
find the treeview control and only register the event to it.
ok yes I found the treeview dotnetobject(it’s ctrls[24] in the script below) but it doesn’t have a GetNodeAt method either…although it does have’ item’…
my nearest attempt is this:
lv = dotNetObject "MaxCustomControls.MaterialExplorerControls.MaterialExplorerDialog"
lv.show()
global ctrls = #()
fn popup sender arg = ( hit = ctrls[24].Nodes.item ;print hit)
fn addEventRecursive ctrl =
(
dotnet.addeventhandler ctrl "MouseClick" popup
append ctrls ctrl --for protection against garbage collection of events
for c = 1 to ctrl.controls.count do addEventRecursive ctrl.controls.item[c-1]
)
addEventRecursive lv
but it doesn’t give the actual node name , just a function called get_item(), and I don’t know what arguments it requires.
I’m sorry but I’m getting lost in the maxscript ‘help’, which isn’t very helpful I must say in this case.
and whenever I inspect the properties and methods of each item, I just get further confused in the myriad results…
maxscript arrays can be accessed using the syntax myArr[24]
dotnet collections can be accessed using the syntax myCol.item[23] (where the indexer is 0-based!)
Let’s think about what you’re trying to do here. You don’t want to process the mouseclick event of ALL the controls on the form, do you? You just want to get the treelist control. So let’s set up a string for the type of the control and then only register for controls of that type.
The Maxscript help is not going to be of much use to you, as the MaxCustomControls assembly is very poorly documented. Because all the max custom controls are built on DevExpress controls, go right to the source and use their documentation.
This is where I found info about the CalcHitInfo method:
http://documentation.devexpress.com/#WindowsForms/DevExpressXtraTreeListTreeList_CalcHitInfotopic
lv = dotNetObject "MaxCustomControls.MaterialExplorerControls.MaterialExplorerDialog"
lv.show()
global treeListObject
global treeListTypeString = "MaxCustomControls.BaseMaterialControls.MaterialExplorerTreeList"
fn popup sender arg =
(
local hitInfo = sender.calcHitInfo (dotnetObject "System.Drawing.Point" arg.X arg.Y)
if hitInfo.node != undefined then
(
--showproperties hitInfo.node
print hitInfo.node.item[0]
)
else print "No nodes hit"
)
fn addEventRecursive ctrl =
(
if (ctrl.getType()).ToString() == treeListTypeString do
(
dotnet.addeventhandler ctrl "MouseClick" popup
treeListObject = ctrl --for protection against garbage collection of events
)
for c = 1 to ctrl.controls.count do addEventRecursive ctrl.controls.item[c-1]
)
addEventRecursive lv