fantastic Io…I’ll check it out when I get home…who would’ve thought something so simple could be so tedious to script?
Maxscript was not designed to be a dotnet language, therefore you should expect a bit more tedium in dealing with dotnet code vs. vanilla maxscript.
great it works fine. Thnks a lot. I still have to get my head around item indexes refer to…the idea of placing eventhandlers only on tree view ctrls confused me, as your previous scriptt didnt ctually implement that, but now I think I get it…
Well you didn’t originally tell us you’re trying to find the selected treeview node, you said you are trying to get mouseclick events from all controls of the form, and that is what I gave you.
Hi Io…I adjusted your code so that the choice is printed on closing the form:
lv = dotNetObject "MaxCustomControls.MaterialExplorerControls.MaterialExplorerDialog"
lv.show()
global matselect
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
matselect = hitInfo.node.item[0]
)
else print "No nodes hit"
)
fn printo = (print matselect)
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
Which works,
However when I use the event method :
on lv closed e do (
print matselect )
I get a ‘needs function or argument ’ error, and I’m not sure why.
You are trying to add a maxscript ui item event handler to a dotnet object. You must use dotnet events.
but the on <control name> closed e format is listed as a dotnet event for the dotnet control in the help! Now I’m really confused.
There is a difference between DotNetControl and a DotNetObject.
A DotNetControl is a maxscript UI wrapper for a dot net object which inherits from System.Windows.Forms.Control. It’s only purpose is to be able to embed dotnet controls inside standard maxscript rollouts. Because it is essentially a maxscript ui control, you can use maxscript events with it. This is not the case you have here. You are not creating a maxscript rollout, you are creating a dotnet form.
A DotNetObject may be delcared and instantiated anywhere, and uses the maxscript dotNet event system (dotnet.AddEventHandler) to register events.
Thank you sir…that makes it clear. Why don’t you post a series of lessons or tutorials on dotnet forms and controls and UI apps?
There isnt much out there…
There is quite a bit out there, but it’s not organized in any way.
LoneRobot once wrote a very nice introduction to dotnet in maxscript:
http://lonerobot.net/?p=1125
I believe he should be coaxed into writing part2
There are also some very popular tutorials on Paul Neale’s website:
http://www.paulneale.com/tutorials/dotNet/dotNet.htm