[Closed] eventhandler on dotnet object doesnt work inside plugin rollout
I tried create slider on treeview using (dotNetObject “button”) inside plugin doesnt work at all. but when I create inside dialog it works.
heres plugin code:
plugin modifier 'slider'
name:"slider"
classID:#(0x1e11866d, 0x3f9028db)
(
rollout test "Test"
(
local slideH, slideW=7, slideOffset=10, slideIndex
local nodeTree
local pressed=false, val
local Ccolor = dotnetclass "system.drawing.color"
local slide=dotNetObject "button"
dotNetControl treeView "system.windows.forms.treeView" height:200 width:150 align:#center
fn MouseDown e=
(
val=slide.width-e.x
pressed=true
)
fn MouseUp=
(
slide.width=slideW
pressed=false
)
fn mousemove e=
(
if pressed do
(
if slide.width < 7 do slide.width=7;
if slide.width > 107 then
(
slide.width=107
)else(slide.width=val+e.x)
)
)
fn createSlide=
(
slide.backColor=(dotNetClass "system.drawing.color").blue
slide.height=slideH; slide.width=7
slide.location.x=slideOffset; slide.location.y=(slideH*slideIndex)+1
treeView.controls.add slide
dotnet.addEventHandler slide "MouseDown" MouseDown
dotnet.addEventHandler slide "MouseUp" MouseUp
dotnet.addEventHandler slide "mousemove" mousemove
slide.flatStyle=slide.flatStyle.flat
slide.backColor=slide.backColor.blue
slide.flatappearance.mouseoverbackcolor = Ccolor.green
slide.flatappearance.mousedownbackcolor = Ccolor.red
slide.flatappearance.bordercolor = Ccolor.yellow
)
fn removeSlide= --fungsi untuk meremove slideLabel
(
try(treeView.controls.Remove slide)catch()
)
on treeView mousedown e do
(
local mouseBtn=e.Button --detect mouse button
--get treeview node and get y position of treeview node
nodeTree=(treeView.GetNodeAt e.location); slideIndex=(((e.y)/16.0)as integer)
removeSlide()
if mouseBtn==mouseBtn.Left and nodeTree!=undefined and nodeTree.Parent!=undefined do
(
createSlide()
)
)
on test open do
(
--populate treeview
uiFn.dotNetTreePopulate treeView obj:(for o in objects where o.parent==undefined collect o)
clearlistener()
slideH=treeView.ItemHeight
-- treeView.focus()
)
)
)
and heres the createdialog code:
try(destroydialog test)catch()
rollout test "Test"
(
local slideH, slideW=7, slideOffset=10, slideIndex
local nodeTree
local pressed=false, val
local Ccolor = dotnetclass "system.drawing.color"
local slide=dotNetObject "button"
dotNetControl treeView "system.windows.forms.treeView" height:200 width:150 align:#center
fn MouseDown e=
(
val=slide.width-e.x
pressed=true
)
fn MouseUp=
(
slide.width=slideW
pressed=false
)
fn mousemove e=
(
if pressed do
(
if slide.width < 7 do slide.width=7;
if slide.width > 107 then
(
slide.width=107
)else(slide.width=val+e.x)
)
)
fn createSlide=
(
slide.backColor=(dotNetClass "system.drawing.color").blue
slide.height=slideH; slide.width=7
slide.location.x=slideOffset; slide.location.y=(slideH*slideIndex)+1
treeView.controls.add slide
dotnet.addEventHandler slide "MouseDown" MouseDown
dotnet.addEventHandler slide "MouseUp" MouseUp
dotnet.addEventHandler slide "mousemove" mousemove
slide.flatStyle=slide.flatStyle.flat
slide.backColor=slide.backColor.blue
slide.flatappearance.mouseoverbackcolor = Ccolor.green
slide.flatappearance.mousedownbackcolor = Ccolor.red
slide.flatappearance.bordercolor = Ccolor.yellow
)
fn removeSlide= --fungsi untuk meremove slideLabel
(
try(treeView.controls.Remove slide)catch()
)
on treeView mousedown e do
(
local mouseBtn=e.Button --detect mouse button
--get treeview node and get y position of treeview node
nodeTree=(treeView.GetNodeAt e.location); slideIndex=(((e.y)/16.0)as integer)
removeSlide()
if mouseBtn==mouseBtn.Left and nodeTree!=undefined and nodeTree.Parent!=undefined do
(
createSlide()
)
)
on test open do
(
--populate treeview
uiFn.dotNetTreePopulate treeView obj:(for o in objects where o.parent==undefined collect o)
clearlistener()
slideH=treeView.ItemHeight
-- treeView.focus()
)
)
createdialog test
please help
I think it is something wrong with the grammar of ur Plug-in code . search “plugin” in maxscript help document for detail . this is a example copied from help document :
plugin helper lightMaster
name:" light master ... "
classID:#(12345 , 54321 ) -- genClassID will give u a new one .
extends dummy
.......
(
parameters main rollout params -- this rollout is main , and will set in a different block .
(
..........
)
on something set val do .......
rollout params " rollout name here "
(
button xxx "xxx "
-- ur rollout code should be here .
)
)
search this forum for the answer. i remember at least three threads about this subject.
I think it is something wrong with the grammar of ur Plug-in code . search “plugin” in maxscript help document for detail . this is a example copied from help document :
its just rollout plugin that I want to show you. the actual plugin script is too long to post
search this forum for the answer. i remember at least three threads about this subject.
i did it denis, so far the solution is to use “dotNet.setLifetimeControl” but still it didnt work.
as I said inside dialog the button dotnet object is work but when you put it inside plugin rollout it stop working.
oh, and if you want to try my code you should run this struct before :
struct uiFunction
(
--####ui dotnet treeview control####
--Recurse hierarchy and add treeview nodes.
fn dotNetTreeRecurse obj tv=
(
for i=1 to obj.children.count do --Loop through each of the children
(
local n=(dotNetObject "System.Windows.Forms.TreeNode" obj.children[i].name)
tv.nodes.add n
dotNetTreeRecurse obj.children[i] n --Call recursion on each of the children.
)
),
--Adds root nodes to treeView.
fn dotNetTreePopulate tv obj:#()=
(
--Loop through all the objects in the scene.
for o in obj do
(
--Create a treeViewNode and add it to the treeView control
local n=(dotNetObject "System.Windows.Forms.TreeNode" o.name)
tv.nodes.add n
dotNetTreeRecurse o n --Call recursive function on each of the root nodes.
)
)
)
uiFn=uiFunction()
its populate object like outliner, and if you select treeview node that have parent, button dotnet object will show up. and that button can stretch like slider when you click and drag.
if it doesn’t work it’s not a solution.
you are absolutely right – dotnet objects(controls) are loosing their events being placed in a scripted plugin’s rollout. the only solution that i found is to use some global timer to add controls event handlers on-fly by using rollout’s open event. there should be a sample on this forum how to do it.
I had a similar problem when trying to place dotnet buttons on a CA modifier . the solution is global timer begun at startup and eventhandler attached to it. Io and Denis helped with this two or three months ago – search back about three months, you’ll find t. I’d post my code but i think its better you check the test code out in the forum, as denis has said…It’s a hack but it works.
ah, I found it in this thread http://forums.cgsociety.org/showthread.php?f=98&t=1029374 . thanks guys for pointing out