Is it possible when I press the “Click Me” button in hForm1 the findRootObjs() function that “belongs” to hForm to be executed and the result to be printed in the listener?
Here is the code:
(
try(hForm1.close())catch()
global hForm1 = dotNetObject "System.Windows.Forms.Form"
hForm1.size = dotNetObject "System.Drawing.Size" 500 300
btn_clickMe = dotNetObject "System.Windows.Forms.Button"
btn_clickMe.Location = dotNetObject "System.Drawing.Point" 10 10
btn_clickMe.Text = "Click me"
hForm1.controls.add btn_clickMe
fn btn_clickMe_Click =
(
hForm.findRootObjs()
)
dotNet.AddEventHandler btn_clickMe "Click" btn_clickMe_Click
ok
)
(
clearListener()
local rootObjs=#()
local tvObjs = dotNetObject "System.windows.forms.treeview"
tvObjs.text= "Objects On Scene"
tvObjs.size= dotNetObject "System.Drawing.Size" 200 200
tvObjs.location=dotNetObject "System.Drawing.Point" 20 30
btn_openNewForm = dotNetObject "System.Windows.Forms.Button"
btn_openNewForm.Location = dotNetObject "System.Drawing.Point" 250 200
btn_openNewForm.Text = "Open form"
local chkObjs = dotNetObject "System.windows.forms.checkbox"
try(hForm.close())catch()
global hForm = dotNetObject "System.Windows.Forms.Form"
hForm.size = dotNetObject "System.Drawing.Size" 500 300
-- hForm.TopMost=true
hForm.controls.add tvObjs
hForm.controls.add btn_openNewForm
fn findRootObjs=
(
rootObjs=#()
for o in objects do
(
if o.parent==undefined then append rootObjs o
)
format "rootObjs: % \n" rootObjs
)
fn recurseHierarchy obj treeNode=
(
for i = 1 to obj.children.count do
(
recurseNode= (dotNetObject "System.Windows.Forms.TreeNode" obj.children[i].name)
treeNode.nodes.add recurseNode
recurseHierarchy obj.children[i] recurseNode
)
)
fn populateTreeView=
(
findRootObjs()
for x in rootObjs do
(
newNode=(dotNetObject "System.Windows.Forms.TreeNode" x.name)
tvObjs.nodes.add newNode
recurseHierarchy x newNode
)
)
fn nodesSelected=
(
print tvObjs.selectedNode.text
if (getNodeByName tvObjs.selectedNode.text).IsSelected then
(
deselect (getNodeByName tvObjs.selectedNode.text)
)
Else
(
selectmore (getNodeByName tvObjs.selectedNode.text)
--sel=for o in selection collect o
)
if zoomChk==true then
(
max zoomext sel
)
)
fn nodesChkd args=
(
print args.node.text
tvObjs.selectedNode=args.node
)
fn btn_openNewForm_Click =
(
findRootObjs()
hForm1.show()
)
dotNet.AddEventHandler btn_openNewForm "Click" btn_openNewForm_Click
fn formLoad=
(
clearListener()
populateTreeView()
tvObjs
tvObjs.checkboxes=true
)
dotNet.addEventHandler hForm "Load" formLoad
dotNet.addEventHandler tvObjs "AfterSelect" nodesSelected
dotNet.addEventHandler tvObjs "AfterCheck" nodesChkd
hForm.show()
ok
)