Notifications
Clear all

[Closed] dotNet UI

 lo1

You need to read about string representations:

http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx

Yes, I think you are right. I will look into this as it has the functions/syntax that I need. Still quite new to dot net in max, but its already proving to be a good move.

Thanks again.

Ok, so have been flapping about and eating pizza and M&Ms for a day, so my sugar levels have hit euphoric levels. I have resolved a lot of the areas I was looking to develop, due largely in part to the help I have been given here, Paul Neale, LoneRobot and others, so thanks very much. I wanted to create a dot net form with a treeview, much like the Paul Neale version, but using just a dot net form. As others who are learning will no doubt want to try this, I have added some code below that is a simple form, a treeview and a button which populates the treeview when clicked. There needs to be a hierarchy/hierarchies in the scene prior to clicking the button. It is mostly a reinterpretation of the Paul Neale example, so 97% of the credit must go to him.
I am going to develop it further as I need to add some mouse actions to the items in the treeview, butthat is fun for another day.

Thanks again everyone. :buttrock:

(
local rootObjs=#() –Will hold all the root nodes found in the scene. Will
struct objectNode (obj,children=#())
local objectTree=#()
–//-CREATE THE FORM———————————————————————————————————————-
treeViewForm = dotNetObject “System.Windows.Forms.Form”
treeViewForm.Size = dotNetObject “System.Drawing.Size” 200 350
treeViewForm.Text = “Treeview Dot net”
treeViewForm.TopMost = true
tvFormColourBorderStyle = dotNetClass “System.Windows.Forms.FormBorderStyle”
treeViewForm.FormBorderStyle = tvFormColourBorderStyle.FixedDialog
treeViewForm.ShowInTaskbar = false
treeViewForm.MinimizeBox = true
treeViewForm.MaximizeBox = false
treeViewForm.helpbutton = true
–//-CREATE A BUTTON OBJECT————————————————————————————————————
bttn = dotnetobject “System.Windows.Forms.button”
bttn.text = “make tree”
bttn.Location = dotNetObject “System.Drawing.Point” 65 280
–//-CREATE A TREEVIEW OBJECT———————————————————————————————————
tv = dotNetObject “System.Windows.Forms.TreeView”
tv.height = 190
tv.Width = 185
tv.Location = dotNetObject “System.Drawing.Point” 5 10
–//-ADD THE CONTROLS TO THE FORM—————————————————————————————————
treeViewForm.controls.add tv
treeViewForm.controls.add bttn
–//——————————————————————————————————————————————–
–FIND ALL ROOT OBJECTS AND APPEND THEM TO THE rooObjs ARRAY
fn findRootObjs =
(
rootObjs=#()
for x in objects do
(
if x.parent == undefined then append rootObjs x
)
)
–//——————————————————————————————————————————————–
–RECURSE THROUGH HIERARCHY AND ADD NODES
fn recurseHierarchy obj theTvNode objNode=
(
for i = 1 to obj.children.count do –Loop through each of the children
(
n=(dotNetObject “System.Windows.Forms.TreeNode” obj.children[i].name)
theTvNode.nodes.add n

		objChildNode=objectNode()	--Create instance of the struct
		objChildNode.obj=obj.children[i]	--Set the object member
		append objNode.children objChildNode	--Append the struct instance with the child struct instance. 
		
		recurseHierarchy obj.children[i] n objChildNode	--Call recursion on each of the children. 
	)
)

–//——————————————————————————————————————————————–
–ADDS THE ROOT NODES TO THE TREE
fn populateTreeView theTv=
(
findRootObjs() –Collect all the root objects.

	--Loop through all the objects in the scene. 
	for x in rootObjs do 
	(
		--Create a treeViewNode and add it to the treeView control
		n=(dotNetObject "System.Windows.Forms.TreeNode" x.name) 
		theTv.nodes.add n
		
		objNode=objectNode()	--Create instance of the struct
		objNode.obj=x	--Set the object member
		append objectTree objNode	--Append the objectTree array with the instance of the struct.
		
		recurseHierarchy x n objNode		--Call recursive function on each of the root nodes. 
	)
)

–//——————————————————————————————————————————————–
–Select objects function.
fn selectObject theTvNode=
(
local indexPath=#() –Array to hold the index of each node in the path.
while theTvNode!=undefined do –While loop to walk backwards from the selected node to root.
(
insertItem theTvNode.index indexPath 1 –Insert the index of each node into array at at start.
theTvNode=theTvNode.parent –Set theTvNode to the parent node.
)

	ot=objectTree[indexPath[1]+1]	--Get the root node in objectTree to start with
	for i = 2 to indexPath.count do	--Loop trough all the index values accept the first.
	(
		ot=ot.children[indexPath[i]+1]	--Set ot to each of the structs by index.
	)
	if isValidNode ot.obj	then select ot.obj--Select the object that is left. 
)

–//——————————————————————————————————————————————–
fn mouseSelect tvEvent tvArg =
(
selectObject (tv.GetNodeAt tvArg.location)
)
–//——————————————————————————————————————————————–
fn makeIt =
(
populateTreeView tv
)
–//-EVENT HANDLERS———————————————————————————————————————-
dotnet.AddEventHandler bttn “Click” makeIt
dotnet.AddEventHandler tv “MouseDown” mouseSelect
treeViewForm.show()
)–END

1 Reply
(@gazybara)
Joined: 11 months ago

Posts: 0

Try to wrap code with tag next time
I organized your code a bit


(
	local rootObjs=#(), objectTree=#() --Will hold all the root nodes found in the scene. Will
	struct objectNode (obj,children=#())

--//-CREATE THE FORM----------------------------------------------------------------------------------------------------------------------
	treeViewForm = dotNetObject "Form"
	treeViewForm.Size = dotNetObject "System.Drawing.Size" 200 350
	treeViewForm.Text = "Treeview Dot net"
	treeViewForm.TopMost = treeViewForm.MinimizeBox = treeViewForm.helpbutton = true
	treeViewForm.FormBorderStyle = treeViewForm.FormBorderStyle.FixedDialog
	treeViewForm.ShowInTaskbar = treeViewForm.MaximizeBox = false
--//-CREATE A BUTTON OBJECT------------------------------------------------------------------------------------------------------------
	bttn = dotnetobject "Button"
	bttn.text = "make tree"
	bttn.Location = dotNetObject "System.Drawing.Point" 65 280
--//-CREATE A TREEVIEW OBJECT---------------------------------------------------------------------------------------------------------
	tv = dotNetObject "TreeView"
	tv.height = 190 ; tv.Width = 185
	tv.Location = dotNetObject "System.Drawing.Point" 5 10
--//-ADD THE CONTROLS TO THE FORM---------------------------------------------------------------------------------------------------
	treeViewForm.controls.addRange #(tv, bttn)
--//--------------------------------------------------------------------------------------------------------------------------------------------
--FIND ALL ROOT OBJECTS AND APPEND THEM TO THE rooObjs ARRAY
	fn findRootObjs = (rootObjs = for x in objects where x.parent == undefined collect x)
--//--------------------------------------------------------------------------------------------------------------------------------------------
--RECURSE THROUGH HIERARCHY AND ADD NODES
fn recurseHierarchy obj theTvNode objNode=
(
	for i = 1 to obj.children.count do --Loop through each of the children
	(
		n = (dotNetObject "TreeNode" obj.children[i].name)
		theTvNode.nodes.add n
		objChildNode = objectNode() --Create instance of the struct
		objChildNode.obj = obj.children[i] --Set the object member
		append objNode.children objChildNode --Append the struct instance with the child struct instance.
		recurseHierarchy obj.children[i] n objChildNode --Call recursion on each of the children.
	)
)
--//--------------------------------------------------------------------------------------------------------------------------------------------
--ADDS THE ROOT NODES TO THE TREE
	fn populateTreeView theTv=
	(
		findRootObjs() --Collect all the root objects.

		--Loop through all the objects in the scene.
		for x in rootObjs do
		(
		--Create a treeViewNode and add it to the treeView control
			n = (dotNetObject "TreeNode" x.name)
			theTv.nodes.add n
			objNode = objectNode() --Create instance of the struct
			objNode.obj = x --Set the object member
			append objectTree objNode --Append the objectTree array with the instance of the struct.
			recurseHierarchy x n objNode --Call recursive function on each of the root nodes.
		)
	)
--//--------------------------------------------------------------------------------------------------------------------------------------------
--Select objects function.
	fn selectObject theTvNode=
	(
		local indexPath=#() --Array to hold the index of each node in the path.
		while theTvNode != undefined do --While loop to walk backwards from the selected node to root.
		(
			insertItem theTvNode.index indexPath 1 --Insert the index of each node into array at at start.
			theTvNode = theTvNode.parent --Set theTvNode to the parent node.
		)
		ot = objectTree[indexPath[1]+1] --Get the root node in objectTree to start with
		for i = 2 to indexPath.count do (ot = ot.children[indexPath[i]+1])--Loop trough all the index values accept the first.
		if isValidNode ot.obj do select ot.obj--Select the object that is left.
	)
--//--------------------------------------------------------------------------------------------------------------------------------------------
	fn mouseSelect tvEvent tvArg = (selectObject (tv.GetNodeAt tvArg.location))
--//--------------------------------------------------------------------------------------------------------------------------------------------
	fn makeIt = (populateTreeView tv)
--//-EVENT HANDLERS----------------------------------------------------------------------------------------------------------------------
	dotnet.AddEventHandler bttn "Click" makeIt
	dotnet.AddEventHandler tv "MouseDown" mouseSelect
	treeViewForm.show()
)--END

Thanks for the organization but the reason I laid it out like that is so that other people who are new to this would be able to see it laid out in a way that is more conducive to their learning. The format originally included indentation, but pasting it in from my script removed this. As with all things though, one persons way of learning will differ from others, so its good to now have both versions for people to refer to.

A more complete version will soon be coming.

Thanks again

EMJAY

All is good in the dot net form but having a little issue with the population. When I make the objects that I need via the other controls, the treeview is populated. If I then append the objects, another hierarchy is mde in the treeview, so I want the treeview to only have one version of the hierarchy when I add or subtract items from it. I am sure it will be a case of clearing the view and rebuilding it, but my brain is full at the moment and I cannot see the woods for the tree (view).

Hahah. I am a comedian. Not.

Cheers

Good evening chaps, the dot net form is going great, amended script below. I have been looking at creating a rclick menu and have the code for creating the control, but am having a little trouble getting the rclick to work on the treeview nodes.

aContextMenu = dotNetObject “System.Windows.Forms.ContextMenuStrip”
aContextMenu.RenderMode = aContextMenu.RenderMode.system
mySep1 = dotNetObject “System.Windows.Forms.ToolStripSeparator”

deleteSel = dotNetObject “System.Windows.Forms.ToolStripMenuItem” “Delete item”

aContextMenu.Items.Add deleteSel
aContextMenu.Items.Add mySep1

The above is what I want the menu to contain (at this time) but I am unclear about where it I need to refer to it when the nodes are made. I thought it would need to go in the populate function, but I think I may be calling it incorrectly.

The UI has two buttons, make tree will populate the treeview with existing scene hirarchies, the other button will delete the selected items, but its currently not working, but I am not bothered about that at this time, I have it working in my full script. If anyone can shed some light on this, as always, I would very much appreciate the pointers.

Thanks

Full code:

(
local rootObjs=#() –Will hold all the root nodes found in the scene. Will
struct objectNode (obj,children=#())
local objectTree=#()

-- Create Form (this is sort of like the rollout creation in maxscript) and set properties
tabFormHeightsAngles = dotNetObject "System.Windows.Forms.Form"
tabFormHeightsAngles.Size = dotNetObject "System.Drawing.Size" 200 350
tabFormHeightsAngles.Text = "Treeview Dot net"
tabFormHeightsAngles.TopMost = true
tvFormColourBorderStyle = dotNetClass "System.Windows.Forms.FormBorderStyle"
tabFormHeightsAngles.FormBorderStyle = tvFormColourBorderStyle.FixedDialog
tabFormHeightsAngles.ShowInTaskbar = false
tabFormHeightsAngles.MinimizeBox = true
tabFormHeightsAngles.MaximizeBox = false
tabFormHeightsAngles.helpbutton = true

–//————————————————————————————-
bttn = dotnetobject “System.Windows.Forms.button”
bttn.text = “make tree”
bttn.height = 30
bttn.width = 70
bttn.Location = dotNetObject “System.Drawing.Point” 5 280

bttnClear = dotnetobject "System.Windows.Forms.button"
bttnClear.Text = "Clear and rebuild"
bttnClear.height = 30
bttnClear.width = 70
bttnClear.Location = dotNetObject "System.Drawing.Point" 120 280

–//————————————————————————————-
camTreeView = dotNetObject “System.Windows.Forms.TreeView”
camTreeView.height = 190
camTreeView.Width = 185
camTreeView.Location = dotNetObject “System.Drawing.Point” 5 10
camTreeView.CheckBoxes = true
–camTreeView.IsExpanded = true
–//—————————————————————————————————————-
tabFormHeightsAngles.controls.add camTreeView
tabFormHeightsAngles.controls.add bttn
tabFormHeightsAngles.controls.add bttnClear
–//—————————————————————————————————————-

aContextMenu = dotNetObject "System.Windows.Forms.ContextMenuStrip"
aContextMenu.RenderMode = aContextMenu.RenderMode.system
mySep1 = dotNetObject "System.Windows.Forms.ToolStripSeparator"

deleteSel = dotNetObject "System.Windows.Forms.ToolStripMenuItem" "Delete item"	


aContextMenu.Items.Add deleteSel
aContextMenu.Items.Add mySep1

–//————————————————————————————-

Find all the root objects in the scene and append them to rootObjs array
fn findRootObjs =
(
rootObjs=#()
for x in objects do
(
if x.parent == undefined then append rootObjs x
)
)

–Recurse hierarchy and add treeview nodes.
fn recurseHierarchy obj theTvNode objNode=
(
for i = 1 to obj.children.count do –Loop through each of the children
(
n=(dotNetObject “System.Windows.Forms.TreeNode” obj.children[i].name)
theTvNode.nodes.add n

		objChildNode=objectNode()	--Create instance of the struct
		objChildNode.obj=obj.children[i]	--Set the object member
		append objNode.children objChildNode	--Append the struct instance with the child struct instance. 
			
		recurseHierarchy obj.children[i] n objChildNode	--Call recursion on each of the children. 
	)
)

–//—————————————————————————————————————-
–Adds root nodes to treeView.
fn populateTreeView theTv=
(
findRootObjs() –Collect all the root objects.

	--Loop through all the objects in the scene. 
	for x in rootObjs do 
	(
		--Create a treeViewNode and add it to the treeView control
		n=(dotNetObject "System.Windows.Forms.TreeNode" x.name) 
		theTv.nodes.add n
		--n.contextMenuStrip = tabFormHeightsAngles.aContextMenu
			
		objNode=objectNode()	--Create instance of the struct
		objNode.obj=x	--Set the object member
		append objectTree objNode	--Append the objectTree array with the instance of the struct.
			
		recurseHierarchy x n objNode		--Call recursive function on each of the root nodes.

			
	)
		
		
)

–//—————————————————————————————————————-
fn makeIt =
(
populateTreeView camTreeView
)

–//—————————————————————————————————————-

–Select objects function.
fn selectObject theTvNode=
(
–print theTvNode.tag
–print (classof theTvNode)
local indexPath=#() –Array to hold the index of each node in the path.
while theTvNode!=undefined do –While loop to walk backwards from the selected node to root.
(
insertItem theTvNode.index indexPath 1 –Insert the index of each node into array at at start.
theTvNode=theTvNode.parent –Set theTvNode to the parent node.
)

	ot=objectTree[indexPath[1]+1]	--Get the root node in objectTree to start with
	for i = 2 to indexPath.count do	--Loop trough all the index values accept the first.
	(
		ot=ot.children[indexPath[i]+1]	--Set ot to each of the structs by index.
	)
	if isValidNode ot.obj then select ot.obj--Select the object that is left. 
)

–//—————————————————————————————————————-
fn mouseSelect tvEvent tvArg =
(
selectObject (camTreeView.GetNodeAt tvArg.location)
)
–//—————————————————————————————————————-
fn nodesSelected=
(
print camTreeView.selectedNode.text
if (getNodeByName camTreeView.selectedNode.text).IsSelected then
(
deselect (getNodeByName camTreeView.selectedNode.text)
)
Else
(
selectmore (getNodeByName camTreeView.selectedNode.text)
–sel=for o in selection collect o
)
if zoomChk == true then
(
max zoomext sel
)
)
–//—————————————————————————————————————-
fn nodesChkd args=
(
print args.node.text
)

–//—————————————————————————————————————-
fn clearAndRebuildTree =
(
delete $
camTreeView.Nodes.Clear()
makeIt()
)

–//—————————————————————————————————————-
–dotnet.AddEventHandler tabFormHeightsAngles “Load” makeIt
dotnet.AddEventHandler bttn “Click” makeIt
dotnet.AddEventHandler bttnClear “Click” clearAndRebuildTree
dotnet.AddEventHandler camTreeView “MouseDown” mouseSelect
dotNet.addEventHandler camTreeView “AfterSelect” nodesSelected
dotNet.addEventHandler camTreeView “AfterCheck” nodesChkd

tabFormHeightsAngles.show()	

)–END

Is there a way to make it so I can select multiple items in the treeview?


try(destroyDialog theRollout)catch()
rollout theRollout "The Rollout"
(
	local TreeNodeClass = dotnetclass "System.Windows.Forms.TreeNode"

	dotNetControl tv "system.windows.forms.treeView" width:150 height:300 pos:[10,10]
	
	fn GetClassTree class =
	(
		c = class as string
		t = dotnetobject TreeNodeClass c
		
		subClasses = #()
		for s = 1 to 3 do
		(
			local sub = dotNetObject TreeNodeClass (s as string)
			append subClasses sub
		)
		t.Nodes.AddRange subClasses
		t
	)
	
	fn getTree =
	(
		local classes = #("Section A","Section B","Section C")
		
		for c in classes do
		(
			n = GetClassTree c
			tv.Nodes.Add n
			--n.Expand()	-- expand the top node
		)
	)

	on theRollout open do
	(
		getTree()
	)
)
createDialog theRollout 170 320


The only way I believe is to use the checkbox property of a tree node. You can set multiple tree nodes to be checked.

 lo1

There’s no built-in way, you’ll have to create your own treeview.

That’s a bummer. I was hoping that would not have to be the route. Does anyone have examples of how to do something like this?

Page 17 / 18