dotNet UI

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

REPLY TO THREAD
 
Thread Tools Search this Thread Display Modes
Old 10 October 2011   #31
lo

Hey lo,
So I've built the script into the structural format like you mentioned.
This is what I've got to far.
Just change the dir variable to a directory with folders containing scripts and it should be good to go.
All dynamically created controls.

So if you guys want to check it out and let me know your thoughts about it that would be great. Thanks


global exampleDotNetTool

	--//Variables
	dir = @"C:\Users\IEVFX\Desktop\trash\scripts" --//Main Scripts directory
	dirArray = GetDirectories (dir+"/*") --//Get subfolders in directory
	parentFolders = for d in dirArray collect (trimright (filenameFromPath d) "\\") --//Array which stores just the names of the subfolders
	
struct exampleDotNetToolStr
(
	--// components
	form,
	parentBtns,
	childBtns,
	
	
	--// handlers
	fn parentClicked s e =
	(
		for b in exampleDotNetTool.childBtns do b.visible = b.tag == s.tag
	),
	
	fn childClicked s e =
	(
		format "child of group % pressed\n" s.tag
	),
	
	
	--// initialization functions
	fn controlFactory type text backColor X Y W H tag =
	(
		local ctr = dotNetObject type
		ctr.text = text
		ctr.bounds = dotNetObject "System.Drawing.Rectangle" X Y W H
		ctr.backColor = (dotNetClass "System.Drawing.Color").fromArgb backColor.a backColor.r backColor.g backColor.b
		ctr.tag = tag
		ctr
	),	
	
	fn initializeForm =
	(
		form = dotNetObject "maxCustomControls.maxForm"		
		form.showInTaskbar = false
		form.text = "Dotnet Tool Example"
		form.bounds = dotNetObject "System.Drawing.Rectangle" 100 100 250 300
		form.controls.addRange parentBtns
		form.controls.addRange childBtns		
		local sysPointer = dotNetObject "System.IntPtr" (windows.getMaxHWND())
		local maxHandle = dotNetObject "maxCustomControls.win32HandleWrapper" sysPointer
		form.show maxHandle
	),

	fn initializeControls =
	(		
		local parentBtnDefs = #()
		local childBtnDefs = #()
		local pos = 10
		
		--//Create Groups
		for i = 1 to parentFolders.count do (
			sFiles = #()
			sFiles = getFiles (dirArray[i] + "*.ms*")
			
			groupName = (parentFolders[i] as string)
			groupColor = (color (i*50) 130 150)
			
			newGroup = #("Button", groupName,groupColor, pos, 10, 70, 30, i)
			append parentBtnDefs newGroup
			
 			--// Create children for each group
 			if sFiles.count > 0 do
 			(
				cPos = 40
				
				for n = 1 to sFiles.count do
 				(
 					ChildName = getFIleNameFile sFiles[n]
					newChild = #("Button", ChildName,groupColor, pos, cPos, 70, 30, i)
					append childBtnDefs newChild
					
					cPos += 30
 				)
 			)
			pos +=70
		)
		
		parentBtns = for b in parentBtnDefs collect (controlFactory b[1] b[2] b[3] b[4] b[5] b[6] b[7] b[8])
		for b in parentBtns do dotnet.addEventHandler b "Click" parentClicked		
		childBtns = for b in childBtnDefs collect (controlFactory b[1] b[2] b[3] b[4] b[5] b[6] b[7] b[8])
		for b in childBtns do dotnet.addEventHandler b "Click" childClicked
		initializeForm()		
	),

	init_trigger = initializeControls() --auto-initialize the controls on struct creation
)

::exampleDotNetTool = exampleDotNetToolStr()
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com

Last edited by JokerMartini : 10 October 2011 at 05:42 PM.
 
Old 10 October 2011   #32
A few suggestions:

* groupColor = (color (i*50) 130 150) will only work for 5 groups or less, otherwise the red component will go over 255 and dotnet will raise an exception.

* You will probably want to initialize all child buttons to be invisible at startup.

* You can also move the first 3 global variables (dir, dirArray, parentFolders) into the struct. The nice thing about encompassing a dotnet tool in a struct is that you don't pollute the global space and avoid collisions with other scripts. For example, leaving the variable 'dir' as a global variable is bound to get you in trouble at some point or another.
 
Old 10 October 2011   #33
Thank you for overlooking that and giving the suggestions.

As far as the color goes I'm going to end up doing an array of colors because I'll know ahead of time how many groups there will be and I'll want to control it.

ex.

groupColor = #((color 74 134 230),(color 119 187 68),(color 203 73 73))--//Blue,Green,Red


I appreciate all your help with this lo.

I set the visible state right above the initializeForm() after it adds the event handler.
for b in childBtns do b.visible = false


As far as the global variables going into the structure that is a great point to make. It makes complete sense and a good mention.
I'm sure many people have used dir as a variable. I use it quite often.

Next would be connecting the actual script to the button. In doing so I would just store that along with everything else in the tag property correct?

newGroup = #("Button", groupName,groupColor[i], pos, 10, 70, 30, i, FilePath)

then when the tag is referenced for the visiblity property I'll just change it to reference part one of the array in the tag.

b.tag = (groupVisibility,"c:\\users\destop\scripts\Trees.ms")
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 10 October 2011   #34
looks like you're on the right path
 
Old 10 October 2011   #35
Awesome

This is great.
The more I become familiar with the help file the easier and more smooth things will develop as well.

I'll go ahead and make another round of developments over the weekend and the beginning of next week before my next post.
I'll have some new things and ideas to try and conquer.
Till next week!

Have a good weekend guys.

JokerMartini
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 10 October 2011   #36
Nice work John, looks like you're getting up to speeds with dotNet very quickly Looking forward to the results you post up soon.
 
Old 10 October 2011   #37
Combine

Now I'm wanting to combine these two ideas.
This first script snippet is the main base of the script.
The second snippet is the new addition I want to mix into the first. I want to use the second snippet to create all the children buttons so they are vertically aligned.
Special thanks to Paul Neal for the second snippet of code.



Snippet 1

global exampleDotNetTool	
struct exampleDotNetToolStr
(
	--// components
	form,
	parentBtns,
	childBtns,
	
	
	--// handlers
	fn parentClicked s e =
	(
		for b in exampleDotNetTool.childBtns do b.visible = b.tag == s.tag
	),
	
	fn childClicked s e =
	(
		format "child of group % pressed\n" s.tag
	),
	
	
	--// initialization functions
	fn controlFactory type text backColor X Y W H tag =
	(
		local ctr = dotNetObject type
		ctr.text = text
		ctr.bounds = dotNetObject "System.Drawing.Rectangle" X Y W H
		ctr.backColor = (dotNetClass "System.Drawing.Color").fromArgb backColor.a backColor.r backColor.g backColor.b
		ctr.tag = tag
		ctr
	),	
	
	fn initializeForm =
	(
		form = dotNetObject "maxCustomControls.maxForm"		
		form.showInTaskbar = false
		form.text = "Dotnet Tool Example"
		form.bounds = dotNetObject "System.Drawing.Rectangle" 100 100 250 300
		form.controls.addRange parentBtns
		form.controls.addRange childBtns		
		local sysPointer = dotNetObject "System.IntPtr" (windows.getMaxHWND())
		local maxHandle = dotNetObject "maxCustomControls.win32HandleWrapper" sysPointer
		form.show maxHandle
	),

	fn initializeControls =
	(		
		--//Variables
		dir = @"C:\Users\IEVFX\Desktop\trash\scripts" --//Main Scripts directory
		dirArray = GetDirectories (dir+"/*") --//Get subfolders in directory
		parentFolders = for d in dirArray collect (trimright (filenameFromPath d) "\\") --//Array which stores just the names of the subfolders
		local parentBtnDefs = #()
		local childBtnDefs = #()
		local pos = 10

		--//Create Groups
		for i = 1 to parentFolders.count do (
			sFiles = #()
			sFiles = getFiles (dirArray[i] + "*.ms*")
			
			groupName = (parentFolders[i] as string)
			groupColor = #((color 74 134 230),(color 119 187 68),(color 203 73 73))--//Blue,Green,Red,
			
			newGroup = #("Button", groupName,groupColor[i], pos, 10, 70, 30, i)
			append parentBtnDefs newGroup
			
 			--// Create children for each group
 			if sFiles.count > 0 do
 			(
				cPos = 40
				
				for n = 1 to sFiles.count do
 				(
 					ChildName = getFIleNameFile sFiles[n]
					newChild = #("Button", ChildName,groupColor[i], pos, cPos, 70, 30, i)
					append childBtnDefs newChild
					
					cPos += 30
 				)
 			)
			pos +=70
		)
		
		parentBtns = for b in parentBtnDefs collect (controlFactory b[1] b[2] b[3] b[4] b[5] b[6] b[7] b[8])
		for b in parentBtns do dotnet.addEventHandler b "Click" parentClicked		
		childBtns = for b in childBtnDefs collect (controlFactory b[1] b[2] b[3] b[4] b[5] b[6] b[7] b[8])
		for b in childBtns do dotnet.addEventHandler b "Click" childClicked
		for b in childBtns do b.visible = false
		initializeForm()		
	),

	init_trigger = initializeControls() --auto-initialize the controls on struct creation
)

::exampleDotNetTool = exampleDotNetToolStr()


Snippet 2

try(form.close())catch()

Ccolor = dotnetclass "system.drawing.color"	
	
bt=dotNetObject "button"
bt.flatStyle=bt.flatStyle.flat
bt.backColor=bt.backColor.blue
bt.flatappearance.bordercolor = Ccolor.blue
bt.flatappearance.mouseoverbackcolor = Ccolor.lightblue
bt.flatappearance.mousedownbackcolor = Ccolor.blue	
bt.size=dotNetObject "system.drawing.size" 24 64
bt.location=dotNetObject "system.drawing.point" 10 10

font=dotNetObject "System.Drawing.Font" "Arial" 8
brush=dotNetObject "System.Drawing.SolidBrush" (dotNetClass "system.drawing.color").white

fn btPaint sender arg=
(
    --Set a variable to make it easier to use for the graphics engine.
    g=arg.graphics
    --Move the starting point of the text over and down.
    g.TranslateTransform 6 58
    --Rotate the text -90 degrees. 
    g.RotateTransform -90
    --Draw the text.
    g.DrawString "Button" font brush (dotNetObject "system.drawing.pointF" 0 0)
)

dotNet.addEventHandler bt "paint" btPaint
dotNet.setLifeTimeControl bt #dotNet

form=dotNetObject "form"
form.controls.add bt

form.show()
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com

Last edited by JokerMartini : 10 October 2011 at 03:09 PM.
 
Old 10 October 2011   #38
Looks nice. By the way you may want to have a look at some other button controls that ship with 3ds Max. the default ones are OK but they don't exactly take on the max theme.

Autodesk includes a few dll's created by devExpress that are well worth checking out.

Try playing with this:


btn1 = dotNetObject "DevExpress.XtraEditors.simpleButton"


You can get really nice looking buttons with these settings that fit in with max 2010+:


btn1.lookandfeel.UseDefaultLookAndFeel = false
btn1.lookAndFeel.style = btn1.lookAndFeel.style.ultraFlat
btn1.imageList = --Add imageList here for icons
btn1.backGroundImageLayout = btn1.backGroundImageLayout.center
btn1.appearance.backColor = (dotNetClass "System.Drawing.Color").transparent
btn1.allowFocus = false

Last edited by TimHawker : 10 October 2011 at 04:38 PM.
 
Old 10 October 2011   #39
These look very slick.
I like the appearance of these buttons. Thanks Tim

It seems to bug out when I run the code on this line.

"btn1.lookAndFeel.style = btn1.lookAndFeel.style.ultraFlat"


btn1 = dotNetObject "DevExpress.XtraEditors.simpleButton"		
btn1.lookandfeel.UseDefaultLookAndFeel = false
btn1.lookAndFeel.style = btn1.lookAndFeel.style.ultraFlat
btn1.imageList = --Add imageList here for icons
btn1.backGroundImageLayout = btn1.backGroundImageLayout.center
btn1.appearance.backColor = (dotNetClass "System.Drawing.Color").transparent
btn1.allowFocus = false

hForm = dotNetObject "System.Windows.Forms.Form" 
hForm.controls.add btn1
hForm.topmost = true
dotNet.addEventHandler mButton "click" whenButtonIsPressed 

--Finally display the image
hForm.show()


I wish the vertical aligning of the buttons was as easy as just having a rotate property on the button itself.

Why is the form dialog different from the dialog being created within the struc?
Is there limitations to one over the other.
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 10 October 2011   #40
Originally Posted by TimHawker: Autodesk includes a few dll's created by devExpress that are well worth checking out.


Nice! Is this documented anywhere?
 
Old 10 October 2011   #41
Originally Posted by JokerMartini: These look very slick.
I like the appearance of these buttons. Thanks Tim

It seems to bug out when I run the code on this line.

"btn1.lookAndFeel.style = btn1.lookAndFeel.style.ultraFlat"


Look at the line below that. It is asking for an imageList but i didn't provide one. Get rid of that line if you don't want to add an icon imagelist. If you do add an imageList you will also need to tell it what imageIndex icon to use as well.

Originally Posted by lo: Nice! Is this documented anywhere?


None than I can find which is a shame. I believe they included the devexpress dll's to create the scene explorer, which uses a devexpress treelist:


dotNetObject "DevExpress.XtraTreeList.TreeList"


Search your 3ds Max install dir for "devExpress" and it will show a few dll's that Autodesk have included since version 2009 I believe.

Edit:
Although there is no documentation from Autodesk, there is a HUGE amount of documentation on the devexpress website. If I've ever had a problem the answer has usually been found in their online support ticket forum. http://www.devexpress.com/

Last edited by TimHawker : 10 October 2011 at 06:40 PM.
 
Old 10 October 2011   #42
Equivalent of a subrollout

What would be the equivalent of a subrollout using dotNet? I want to try and do something like this next.



When you click the “Offset” the script would do what is the equivelant of a
fileIn (in maxscript) and those controls would then be loaded into this panel where the user could adjust the desired settings and options before applying the changes to the scene. Keeping in mind that these other *.ms files would be written only for use within this master script. You wouldn't be able to go file>run>offset.ms and it work properly.

In this case the fileIn *.ms would consist of something similar to this....which is just ui controls and whatnot. If it makes more sense I can create an example of what I'm after using maxscript. Just let me know.



form=dotNetObject "form"

nud=dotNetObject "System.Windows.Forms.NumericUpDown"
nud.DecimalPlaces=2
nud.Increment=.1
nud.maximum=10
nud.minimum=-10
nud.ReadOnly=false
enableAccelerators=false
showProperties nud

form.controls.add nud
form.show()
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 11 November 2011   #43
Example

I went ahead and made an example file.
Just extract and check it out. Run the masterDialog.ms
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 11 November 2011   #44
Originally Posted by TimHawker: None than I can find which is a shame. I believe they included the devexpress dll's to create the scene explorer, which uses a devexpress treelist:


That's just insane! They give us this incredible set of tools for free but fail to inform us of their existence for 4 years!
 
Old 11 November 2011   #45
Originally Posted by lo: That's just insane! They give us this incredible set of tools for free but fail to inform us of their existence for 4 years!


incredible set of tools... incredible is a strong word in this context.
 
reply share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright ©2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 03:42 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.