CGTalk > Software > Autodesk 3ds max > 3dsMax SDK and MaxScript
Login register
reply share thread « Previous Thread | Next Thread »
 
Thread Tools Search this Thread Display Modes
Old 10-22-2011, 12:10 AM   #1
JokerMartini
Expert
 
JokerMartini's Avatar
portfolio
John Martini
CG Supervisor, 3D, Maxscript, VFX
Ingenuity Engine
Los Angeles, USA
 
Join Date: Mar 2009
Posts: 1,307
Send a message via AIM to JokerMartini
dotNet UI

I'm going to be building my first complete dotNet ui in maxscript and I wanted to started a post here on cgtalk show the process from start to finish on building the UI.

A few reasons for doing so is....

1. I'm not familiar with dotNet and a lot of people seem intimidated by it, so hopefully in this thread people will be able to pick up an learn things from it which will allow them and hopefully make them want to use dotNet. It has a ton more functionality than that of maxscript and it is also a lot more customizable.

2. With me not knowing dotNet very well, I'll be sure to have a handful of questions on how to achieve and build the UI i'm after.

With all that in mind here we go.

I've attached and image of the UI I'm trying to build stage 1.
There are 3 buttons at the top and if you click on button 1 it then displays a row of, predefined vertically aligned buttons.
If the user clicks on button 2 it does the same thing, hiding all the buttons related to button 1 and then displaying the ones related to group 2.
This part of the UI I'm not sure how to do.

In maxscript I would do a simple visible property on the buttons and just hide and unhide them as needed.

Here is the start of my code so far.
Thanks

John Martini




Code:
--Create a form and display it in Max. --Read about this process in the form & MaxForm tutorial. form=dotNetObject "form" sysPointer=dotNetObject "system.intPtr" (windows.getMaxHWND()) maxHandle=dotNetObject "maxCustomControls.win32HandleWrapper" sysPointer form.show maxHandle form.bounds=dotNetObject "system.drawing.rectangle" 10 90 400 400 form.text="DotNet UI" btn1 = dotNetObject "system.windows.forms.button" btn1.bounds=dotNetObject "System.drawing.rectangle" 10 10 36 36 btn1.flatStyle=btn1.flatStyle.flat btn1.backColor=btn1.backColor.darkRed btn1.text="1" btn2 = dotNetObject "system.windows.forms.button" height:50 btn2.bounds=dotNetObject "System.drawing.rectangle" 48 10 36 36 btn2.flatStyle=btn2.flatStyle.flat btn2.backColor=btn2.backColor.darkGreen btn2.text="2" btn3 = dotNetObject "system.windows.forms.button" btn3.bounds=dotNetObject "System.drawing.rectangle" 86 10 36 36 btn3.flatStyle=btn3.flatStyle.flat btn3.backColor=btn3.backColor.darkBlue btn3.text="3" --Add the pictureBox to the form form.controls.add btn1 form.controls.add btn2 form.controls.add btn3
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 10-22-2011, 08:35 AM   #2
lo
the frequentest!
portfolio
Rotem Shiffman
Tel Aviv, Israel
 
Join Date: Jul 2005
Posts: 2,837
Quote:
Originally Posted by JokerMartini
In maxscript I would do a simple visible property on the buttons and just hide and unhide them as needed.


You can do the same thing with dotnet, all the controls have a .visible property.
 
Old 10-22-2011, 02:57 PM   #3
JokerMartini
Expert
 
JokerMartini's Avatar
portfolio
John Martini
CG Supervisor, 3D, Maxscript, VFX
Ingenuity Engine
Los Angeles, USA
 
Join Date: Mar 2009
Posts: 1,307
Send a message via AIM to JokerMartini
hey lo

Hey Lo thanks for the response.
Is there an easy way to actually rotate the buttons like in the image. So they are sideways.

Aside from that is there a subrollout or the equivelant of that I should put the groups of buttons in. That way if to many get added it will be able to scroll.
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 10-22-2011, 05:25 PM   #4
lo
the frequentest!
portfolio
Rotem Shiffman
Tel Aviv, Israel
 
Join Date: Jul 2005
Posts: 2,837
Quote:
Originally Posted by JokerMartini
Is there an easy way to actually rotate the buttons like in the image. So they are sideways.


the easy way is to make bitmaps and use those instead of text.
The hard way is to use custom paint using GDI, but I'd go with the easy way in this case.

Quote:
Originally Posted by JokerMartini
Aside from that is there a subrollout or the equivelant of that I should put the groups of buttons in. That way if to many get added it will be able to scroll.


There is no control I know that looks like a 3dsmax subrollout, but any controls that inherits from scrollablecontrol (for example, the Panel control) can host other controls and automatically show a scrollbar if they are not in the visible range.

For learning dotnet, it is a good idea to familiarize yourself with the msdn dotnet library, it's a very useful resource:
http://msdn.microsoft.com/en-us/lib...dows.forms.aspx

Last edited by lo : 10-22-2011 at 05:28 PM.
 
Old 10-22-2011, 08:05 PM   #5
TimHawker
Frequenter
portfolio
Tim Hawker
CGI Artist
RTT AG
Germany
 
Join Date: May 2007
Posts: 142
Hey John,

Nice idea creating a post about your experience with dotNet.

Firstly, instead of using a standard dotNet form, you'll probably want to use a maxForm. This will give you the max icon in the top left of the window, automatically minimise the window when the main max window is minimised, and tie in a bit closer to 3ds max

Use this for your form:
Code:
form=dotNetObject "MaxCustomControls.MaxForm"


Also, this may be basic, but it really does help when trying to find out about the possibilities of a dotNet control:

Code:
form = dotNetObject "MaxCustomControls.MaxForm" showProperties form --Shows all properties of maxform showMethods form --Shows all methods of maxform showEvents form --Shows all events of maxform


Tim
 
Old 10-22-2011, 08:26 PM   #6
Pjanssen
Veteran
portfolio
Pier Janssen
Göteborg, Sweden
 
Join Date: Apr 2003
Posts: 2,400
Maybe you have a reason to do it all in maxscript, but I can't help but wonder why you wouldn't do your .NET development in C# with Visual Studio?
 
Old 10-22-2011, 10:21 PM   #7
JokerMartini
Expert
 
JokerMartini's Avatar
portfolio
John Martini
CG Supervisor, 3D, Maxscript, VFX
Ingenuity Engine
Los Angeles, USA
 
Join Date: Mar 2009
Posts: 1,307
Send a message via AIM to JokerMartini
I'd gladly do it in c# in visual studio, I was just going to try and use dotNet since it seemed like an easier route to go rather than c#.

I've never used either one so I found dotNet easier to build since I could do it all in max as well.
Either one will be a fun challenge and something new for me.


I wonder if it would be more fun to quickly build my ui in maxscript then show everyone what I'm after and then convert that to dotNet or c#
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 10-25-2011, 11:27 PM   #8
JokerMartini
Expert
 
JokerMartini's Avatar
portfolio
John Martini
CG Supervisor, 3D, Maxscript, VFX
Ingenuity Engine
Los Angeles, USA
 
Join Date: Mar 2009
Posts: 1,307
Send a message via AIM to JokerMartini
So the next step now is developing a function that when the script is executed, it collects the needed information and creates a button for each file in the dialog window.
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 10-25-2011, 11:38 PM   #9
JokerMartini
Expert
 
JokerMartini's Avatar
portfolio
John Martini
CG Supervisor, 3D, Maxscript, VFX
Ingenuity Engine
Los Angeles, USA
 
Join Date: Mar 2009
Posts: 1,307
Send a message via AIM to JokerMartini
Thanks

I wanted to say thanks to everyone Tim, Lo, and Pjanssen for checking out the post and responding with some helping words. I'm going to post more of my code for you guys to check out.
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 10-25-2011, 11:58 PM   #10
JokerMartini
Expert
 
JokerMartini's Avatar
portfolio
John Martini
CG Supervisor, 3D, Maxscript, VFX
Ingenuity Engine
Los Angeles, USA
 
Join Date: Mar 2009
Posts: 1,307
Send a message via AIM to JokerMartini
Stage 2

Stage 2
The different groups of buttons. Figuring out how it hide and unhides the buttons.

Do i have to make each buttons action within a function? Or can I do what is done when using maxscript and just do a direction action for example
Code:
on button pressed do (print "me")


instead of what I'm doing right now in dotNet which would be the equivalent of this in maxscript

Code:
function = (print "me") on button pressed do function



Here is the updated code so far....
Code:
--Create a form and display it in Max. --Read about this process in the form & MaxForm tutorial. form=dotNetObject "form" function ShowGroup1 = ( btnMS1.visible = true btnMS2.visible = false btnMS3.visible = false ) function ShowGroup2 = ( btnMS1.visible = false btnMS2.visible = true btnMS3.visible = false ) function ShowGroup3 = ( btnMS1.visible = false btnMS2.visible = false btnMS3.visible = true ) sysPointer=dotNetObject "system.intPtr" (windows.getMaxHWND()) maxHandle=dotNetObject "maxCustomControls.win32HandleWrapper" sysPointer form.show maxHandle form.bounds=dotNetObject "system.drawing.rectangle" 10 90 400 400 form.text="DotNet UI" btn1 = dotNetObject "system.windows.forms.button" btn1.bounds=dotNetObject "System.drawing.rectangle" 10 10 36 36 btn1.flatStyle=btn1.flatStyle.flat btn1.backColor=btn1.backColor.darkRed btn1.text="1" btn2 = dotNetObject "system.windows.forms.button" height:50 btn2.bounds=dotNetObject "System.drawing.rectangle" 48 10 36 36 btn2.flatStyle=btn2.flatStyle.flat btn2.backColor=btn2.backColor.darkGreen btn2.text="2" btn3 = dotNetObject "system.windows.forms.button" btn3.bounds=dotNetObject "System.drawing.rectangle" 86 10 36 36 btn3.flatStyle=btn3.flatStyle.flat btn3.backColor=btn3.backColor.darkBlue btn3.text="3" btnMS1 = dotNetObject "system.windows.forms.button" btnMS1.bounds=dotNetObject "System.drawing.rectangle" 10 48 112 24 btnMS1.flatStyle=btn1.flatStyle.flat btnMS1.backColor=btn1.backColor.darkRed btnMS1.text="MaxScript1.ms" btnMS1.visible = false btnMS2 = dotNetObject "system.windows.forms.button" btnMS2.bounds=dotNetObject "System.drawing.rectangle" 10 48 112 24 btnMS2.flatStyle=btn1.flatStyle.flat btnMS2.backColor=btn1.backColor.darkGreen btnMS2.text="MaxScript2.ms" btnMS2.visible = false btnMS3 = dotNetObject "system.windows.forms.button" btnMS3.bounds=dotNetObject "System.drawing.rectangle" 10 48 112 24 btnMS3.flatStyle=btn1.flatStyle.flat btnMS3.backColor=btn1.backColor.darkBlue btnMS3.text="MaxScript3.ms" btnMS3.visible = false --Add the pictureBox to the form form.controls.add btn1 form.controls.add btnMS1 form.controls.add btn2 form.controls.add btnMS2 form.controls.add btn3 form.controls.add btnMS3 --//Button actions dotNet.addEventHandler btn1 "click" ShowGroup1 dotNet.addEventHandler btn2 "click" ShowGroup2 dotNet.addEventHandler btn3 "click" ShowGroup3
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 10-26-2011, 12:08 AM   #11
JokerMartini
Expert
 
JokerMartini's Avatar
portfolio
John Martini
CG Supervisor, 3D, Maxscript, VFX
Ingenuity Engine
Los Angeles, USA
 
Join Date: Mar 2009
Posts: 1,307
Send a message via AIM to JokerMartini
functions + variable

Aside from the above post.....
How would I make the button even handler a function with a variable for example

I understand the basic fundamentals of coding in general. It's just a matter of translating it over to dotNet. Once I begin to understand those it will be smooth sailing for sure.

Once again I appreciate all the help from you guys in the community. Thanks a ton for your patience and help.


Code:
--//Universal Function function ShowGroup grp = ( if grp == 1 do ( btnMS1.visible = true btnMS2.visible = false btnMS3.visible = false ) if grp == 2 do ( btnMS1.visible = false btnMS2.visible = true btnMS3.visible = false ) if grp == 3 do ( btnMS1.visible = false btnMS2.visible = false btnMS3.visible = true ) ) --//Button actions dotNet.addEventHandler btn1 "click" (ShowGroup 1) dotNet.addEventHandler btn2 "click" (ShowGroup 2) dotNet.addEventHandler btn3 "click" (ShowGroup 3)
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 10-26-2011, 06:41 AM   #12
lo
the frequentest!
portfolio
Rotem Shiffman
Tel Aviv, Israel
 
Join Date: Jul 2005
Posts: 2,837
1) Store all child buttons in an array
2) set the .Tag property of all buttons (including the control buttons) to the index of their group
3) define the event handler function as myFunction sender e = ...
4) within the function, you can query s.tag to determine which group was activated
5) for c in allButtons do c.visible = c.tag == s.tag

I only have a few minutes, otherwise I'd post an example code for you
 
Old 10-26-2011, 07:54 AM   #13
TimHawker
Frequenter
portfolio
Tim Hawker
CGI Artist
RTT AG
Germany
 
Join Date: May 2007
Posts: 142
I would add all your dotNet objects into a struct so you can access them with only one global variable.

Also, no, you cannot send custom parameters to functions via dotNetEventHandlers. You can only access the sender and the event.

Please have a look at the code below:

Code:
--Create a form and display it in Max. --Read about this process in the form & MaxForm tutorial. global dotNetForm --Create a struct to access every dotNet object from one global variable struct dotNetFormStruct ( form=dotNetObject "form", --A comma is required at the end of every function/variable except the very last one. btn1 = dotNetObject "system.windows.forms.button", btn2 = dotNetObject "system.windows.forms.button" height:50, btn3 = dotNetObject "system.windows.forms.button", btnMS1 = dotNetObject "system.windows.forms.button" , btnMS2 = dotNetObject "system.windows.forms.button" , btnMS3 = dotNetObject "system.windows.forms.button", btnMSGroup = #() ) dotNetForm = dotNetFormStruct() --Customise the dotNet objects dotNetForm.btn1.bounds=dotNetObject "System.drawing.rectangle" 10 10 36 36 dotNetForm.btn1.flatStyle=dotNetForm.btn1.flatStyl e.flat dotNetForm.btn1.backColor=dotNetForm.btn1.backColo r.darkRed dotNetForm.btn1.text="1" dotNetForm.btn2.bounds=dotNetObject "System.drawing.rectangle" 48 10 36 36 dotNetForm.btn2.flatStyle=dotNetForm.btn2.flatStyl e.flat dotNetForm.btn2.backColor=dotNetForm.btn2.backColo r.darkGreen dotNetForm.btn2.text="2" dotNetForm.btn3.bounds=dotNetObject "System.drawing.rectangle" 86 10 36 36 dotNetForm.btn3.flatStyle=dotNetForm.btn3.flatStyl e.flat dotNetForm.btn3.backColor=dotNetForm.btn3.backColo r.darkBlue dotNetForm.btn3.text="3" dotNetForm.btnMS1.bounds=dotNetObject "System.drawing.rectangle" 10 48 112 24 dotNetForm.btnMS1.flatStyle=dotNetForm.btn1.flatSt yle.flat dotNetForm.btnMS1.backColor=dotNetForm.btn1.backCo lor.darkRed dotNetForm.btnMS1.text="MaxScript1.ms" dotNetForm.btnMS1.visible = false dotNetForm.btnMS2.bounds=dotNetObject "System.drawing.rectangle" 10 48 112 24 dotNetForm.btnMS2.flatStyle=dotNetForm.btn1.flatSt yle.flat dotNetForm.btnMS2.backColor=dotNetForm.btn1.backCo lor.darkGreen dotNetForm.btnMS2.text="MaxScript2.ms" dotNetForm.btnMS2.visible = false dotNetForm.btnMS3.bounds=dotNetObject "System.drawing.rectangle" 10 48 112 24 dotNetForm.btnMS3.flatStyle=dotNetForm.btn1.flatSt yle.flat dotNetForm.btnMS3.backColor=dotNetForm.btn1.backCo lor.darkBlue dotNetForm.btnMS3.text="MaxScript3.ms" dotNetForm.btnMS3.visible = false sysPointer=dotNetObject "system.intPtr" (windows.getMaxHWND()) maxHandle=dotNetObject "maxCustomControls.win32HandleWrapper" sysPointer dotNetForm.form.show maxHandle dotNetForm.form.bounds=dotNetObject "system.drawing.rectangle" 10 90 400 400 dotNetForm.form.text="DotNet UI" --Functions (These can also be added to the stuct, but if you add them an event handler can not access them directly. Instead you must link to them through a function. See below) -- function showGroup1Link sender e = dotNetForm.showGroup1 sender e -- dotNet.addEventHandler showGroup1Link function ShowGroup1 sender e = ( print sender --this will give you access to the button that caused the event print e --this will give you the event with various things you can do, such as cancel the event. dotNetForm.btnMS1.visible = true dotNetForm.btnMS2.visible = false dotNetForm.btnMS3.visible = false ) function ShowGroup2 sender e= ( dotNetForm.btnMS1.visible = false dotNetForm.btnMS2.visible = true dotNetForm.btnMS3.visible = false ) function ShowGroup3 sender e = ( dotNetForm.btnMS1.visible = false dotNetForm.btnMS2.visible = false dotNetForm.btnMS3.visible = true ) --Add the pictureBox to the form dotNetForm.form.controls.add dotNetForm.btn1 dotNetForm.form.controls.add dotNetForm.btnMS1 dotNetForm.form.controls.add dotNetForm.btn2 dotNetForm.form.controls.add dotNetForm.btnMS2 dotNetForm.form.controls.add dotNetForm.btn3 dotNetForm.form.controls.add dotNetForm.btnMS3 --//Button actions dotNet.addEventHandler dotNetForm.btn1 "click" ShowGroup1 dotNet.addEventHandler dotNetForm.btn2 "click" ShowGroup2 dotNet.addEventHandler dotNetForm.btn3 "click" ShowGroup3

Last edited by TimHawker : 10-26-2011 at 07:57 AM.
 
Old 10-26-2011, 08:02 AM   #14
TimHawker
Frequenter
portfolio
Tim Hawker
CGI Artist
RTT AG
Germany
 
Join Date: May 2007
Posts: 142
Hmm odd, when I paste in the code it adds a few spaces between some words. ".flatstyle" has become ".flatstyl e"! Has anyone seen this before?

I've attached it below. lol at having to put it in a zip to upload it! You would have thought .ms would be a valid file format
Attached Files
File Type: zip dotNetUIExample.zip (1.2 KB, 32 views)
 
Old 10-26-2011, 08:48 AM   #15
lo
the frequentest!
portfolio
Rotem Shiffman
Tel Aviv, Israel
 
Join Date: Jul 2005
Posts: 2,837
This is how I usually build my dotnet tools. I use a control factory to avoid all that long repetitive code.
Of course all the functions can be customized to your needs.

Code:
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 200 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 = #( \ #("Button", "Parent 1", red, 10, 10, 50, 50, 1), #("Button", "Parent 2", green, 70, 10, 50, 50, 2), #("Button", "Parent 3", blue, 130, 10, 50, 50, 3) ) local childBtnDefs = #( \ #("Button", "Child 1A", red, 10, 70, 50, 50, 1), #("Button", "Child 1B", red, 70, 70, 50, 50, 1), #("Button", "Child 2A", green, 10, 130, 50, 50, 2), #("Button", "Child 2B", green, 70, 130, 50, 50, 2), #("Button", "Child 3A", blue, 10, 190, 50, 50, 3), #("Button", "Child 3B", blue, 70, 190, 50, 50, 3) ) 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()
 
reply share thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 08:41 AM.


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