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 11-01-2011, 06:07 PM   #46
lo
the frequentest!
portfolio
Rotem Shiffman
Tel Aviv, Israel
 
Join Date: Jul 2005
Posts: 2,839
Quote:
Originally Posted by denisT
incredible set of tools... incredible is a strong word in this context.


Ok, well... A set of tools.
 
Old 11-01-2011, 08:25 PM   #47
lo
the frequentest!
portfolio
Rotem Shiffman
Tel Aviv, Israel
 
Join Date: Jul 2005
Posts: 2,839
Quote:
Originally Posted by JokerMartini
I went ahead and made an example file.
Just extract and check it out. Run the masterDialog.ms


Firstly, an unrelated comment on your example:
The first time you run the script you will get an exception (start max afresh and run masterDialog.ms). This is because of scope issues.
Consider the following two lines:
Code:
fileIn "rlOffset.ms" AddSubRollout rlMasterDialog.srContainer rlOffset

The exception occurs because rlOffset is undefined. Intuitively, you'd expect it to be fine as you just defined it a line before within the rlOffset.ms script.
Unfortunately, this is not how maxscript works. Upon entering the event handler, it evaluates all the variable withing the handler, and determines not their value, but what they are referring to.
So when the event handler is entered, if tries to determine what the variable rlOffset is, and does not find any such variable, so it determines it is an undefined local variable.
You must specifically tell maxscript to look for this variable in the global scope. There are two ways to do this:
1) explicitly declare the variable global: ("global rlOffset")
2) use the special :: prefix to declare it global:
Code:
fileIn "rlOffset.ms" AddSubRollout rlMasterDialog.srContainer ::rlOffset

A more technical explanation on how maxscript handles scope is given by Bobo in a thread I can't find at the moment.

To try to answer your actual question, A possible solution is to declare a panel control within the files, containing all the child controls, and simply use the form.controls.add and form.controls.remove to switch between them.
This is what I did recently in the stamping module of my frame buffer tool, you can see how it works there if you wish (though it's implemented in c# there).
I think the optimal method of implementation and structure depend on the intended use of the subpanels.

Last edited by lo : 11-01-2011 at 08:28 PM.
 
Old 11-01-2011, 09:47 PM   #48
JokerMartini
Expert
 
JokerMartini's Avatar
portfolio
John Martini
CG Supervisor, 3D, Maxscript, VFX
Ingenuity Engine
Los Angeles, USA
 
Join Date: Mar 2009
Posts: 1,313
Send a message via AIM to JokerMartini
Thank you lo for the explanation of things. I'll look into you frame buffer and see what is written and how its written.
I'm going to do some tests on the remove and add as you mentioned above as well.

I think I had a semi-revelation today on grasping and understanding the help file for this stuff.

I built out a ui today and I was wondering if you could take a look at it and let me know how or what would be a good way to condense or better write the code. It seems a bit redundant and maybe there is an easier way to make a table or form with dropdown lists in the rows.
All the dropdown lists consist of variable defined or gathered using functions.

check it out.

Code:
fn dotnetcolor r g b = ( (dotNetClass "System.Drawing.Color").fromARGB r g b ) TheFont = dotnetobject "System.Drawing.Font" "Arial" 9 lbProjects = dotnetobject "System.Windows.Forms.label" --width:130 height:24 lbProjects.bounds=dotNetObject "system.drawing.rectangle" 0 0 130 24 lbProjects.forecolor = lbProjects.forecolor.fromARGB 255 255 255 lbProjects.backcolor = lbProjects.backcolor.fromARGB 31 29 28 lbProjects.TextAlign = (getProperty lbProjects.TextAlign "MiddleLeft") lbProjects.text = " Projects" lbProjects.font = TheFont lbProjects.location = dotNetObject "System.Drawing.Point" 15 15 dlProjects = dotnetobject "System.Windows.Forms.ComboBox" dlProjects.bounds=dotNetObject "system.drawing.rectangle" 0 0 130 24 dlProjects.location = dotNetObject "System.Drawing.Point" 15 39 projectsArr = #("Nice","Cool","Bunnies") dlProjects.items.addrange projectsArr lbWorkspaces = dotnetobject "System.Windows.Forms.label" --width:130 height:24 lbWorkspaces.bounds=dotNetObject "system.drawing.rectangle" 0 0 210 24 lbWorkspaces.forecolor = lbWorkspaces.forecolor.fromARGB 255 255 255 lbWorkspaces.backcolor = lbWorkspaces.backcolor.fromARGB 31 29 28 lbWorkspaces.TextAlign = (getProperty lbWorkspaces.TextAlign "MiddleLeft") lbWorkspaces.text = " Workspaces" lbWorkspaces.font = TheFont lbWorkspaces.location = dotNetObject "System.Drawing.Point" 146 15 dlWorkspaces = dotnetobject "System.Windows.Forms.ComboBox" dlWorkspaces.bounds=dotNetObject "system.drawing.rectangle" 0 0 210 24 dlWorkspaces.location = dotNetObject "System.Drawing.Point" 146 39 workSpaceArr = #("Here","There","Everywhere") dlWorkspaces.items.addrange workSpaceArr lbJobName = dotnetobject "System.Windows.Forms.label" --width:130 height:24 lbJobName.bounds=dotNetObject "system.drawing.rectangle" 0 0 100 24 lbJobName.forecolor = lbJobName.forecolor.fromARGB 255 255 255 lbJobName.backcolor = lbJobName.backcolor.fromARGB 31 29 28 lbJobName.TextAlign = (getProperty lbJobName.TextAlign "MiddleLeft") lbJobName.text = " Job Name" lbJobName.font = TheFont lbJobName.location = dotNetObject "System.Drawing.Point" 357 15 dlJobName = dotnetobject "System.Windows.Forms.ComboBox" dlJobName.bounds=dotNetObject "system.drawing.rectangle" 0 0 100 24 dlJobName.location = dotNetObject "System.Drawing.Point" 358 39 jobNameArr = #("James","Mike","Kevin") dlJobName.items.addrange jobNameArr lbFileType = dotnetobject "System.Windows.Forms.label" --width:130 height:24 lbFileType.bounds=dotNetObject "system.drawing.rectangle" 0 0 75 24 lbFileType.forecolor = lbFileType.forecolor.fromARGB 255 255 255 lbFileType.backcolor = lbFileType.backcolor.fromARGB 31 29 28 lbFileType.TextAlign = (getProperty lbFileType.TextAlign "MiddleLeft") lbFileType.text = " File Type" lbFileType.font = TheFont lbFileType.location = dotNetObject "System.Drawing.Point" 458 15 dlFileType = dotnetobject "System.Windows.Forms.ComboBox" dlFileType.bounds=dotNetObject "system.drawing.rectangle" 0 0 75 24 dlFileType.location = dotNetObject "System.Drawing.Point" 459 39 fileTypeArr = #(".exr",".tga") dlFileType.items.addrange fileTypeArr TheForm = dotNetObject "System.Windows.Forms.Form" TheForm.controls.add lbProjects TheForm.controls.add dlProjects TheForm.controls.add lbWorkspaces TheForm.controls.add dlWorkspaces TheForm.controls.add lbJobName TheForm.controls.add dlJobName TheForm.controls.add lbFileType TheForm.controls.add dlFileType TheForm.bounds = dotNetObject "system.drawing.rectangle" 0 0 560 200 TheForm.backColor = TheForm.backColor.fromARGB 153 153 153 TheForm.show()
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 11-01-2011, 10:31 PM   #49
lo
the frequentest!
portfolio
Rotem Shiffman
Tel Aviv, Israel
 
Join Date: Jul 2005
Posts: 2,839
There is a way to make a table with comboboxes as cells, it's called DataGridView.
If you have one row and only 4 comboboxes though, I find it a bit redundant, but I guess it's a matter of taste.

Tips regarding your code:
1) There's no need to specify bounds and a location, the first two coordinates of the bounds rectangle are the location (X,Y,W,H).
2) The "System.Windows.Forms" prefix is not necessary
3) Use factory functions to create large amounts of similar controls.

Here's the same code you wrote but somewhat shorter.

Code:
theFont = dotnetobject "System.Drawing.Font" "Arial" 9 fn labelFactory X Y W H fCol bCol txt = ( local theLab = dotNetObject "Label" theLab.Font = theFont theLab.Bounds = dotNetObject "System.Drawing.Rectangle" X Y W H theLab.BackColor = (dotNetClass "System.Drawing.Color").fromARGB bCol[1] bCol[2] bCol[3] theLab.ForeColor = (dotNetClass "System.Drawing.Color").fromARGB fCol[1] fCol[2] fCol[3] theLab.TextAlign = theLab.TextAlign.MiddleLeft theLab.Text = txt theLab ) fn cmbBoxFactory X Y W H items = ( local theCmb = dotNetObject "ComboBox" theCmb.Bounds = dotNetObject "System.Drawing.Rectangle" X Y W H theCmb.DropDownStyle = theCmb.DropDownStyle.DropDownList theCmb.items.addRange items theCmb ) lbProjects = labelFactory 15 15 130 24 [255,255,255] [31,29,28] "Projects" dlProjects = cmbBoxFactory 15 39 130 24 #("Nice","Cool","Bunnies") lbWorkspaces = labelFactory 146 15 210 24 [255,255,255] [31,29,28] "Workspaces" dlWorkspaces = cmbBoxFactory 146 39 210 24 #("Here","There","Everywhere") lbJobName = labelFactory 358 15 100 24 [255,255,255] [31,29,28] " Job Name" dlJobName = cmbBoxFactory 358 39 100 24 #("James","Mike","Kevin") lbFileType = labelFactory 459 15 75 24 [255,255,255] [31,29,28] " File Type" dlFileType = cmbBoxFactory 459 39 75 24 #(".exr",".tga") TheForm = dotNetObject "Form" TheForm.controls.addRange #(lbProjects,dlProjects,lbWorkspaces,dlWorkspaces, lbJobName,dlJobName,lbFileType,dlFileType) TheForm.bounds = dotNetObject "system.drawing.rectangle" 0 0 560 200 TheForm.backColor = TheForm.backColor.fromARGB 153 153 153 TheForm.show()
 
Old 11-02-2011, 12:55 AM   #50
JokerMartini
Expert
 
JokerMartini's Avatar
portfolio
John Martini
CG Supervisor, 3D, Maxscript, VFX
Ingenuity Engine
Los Angeles, USA
 
Join Date: Mar 2009
Posts: 1,313
Send a message via AIM to JokerMartini
Great stuff

This stuff is exciting to mess with. I'm diving in head first just messing around with all kinds of stuff. Very cool stuff. You've been super helpful through all of this. Thanks for your patience Lo.

Now is it easy to modifier the head and dialog style?
I looked through the help file on here http://www.scriptspot.com/bobo/mxs9...Forms.Form.html

Wasn't sure exactly what settings I would be looking to adjust to do so.




Next I'm going to be working on what would be a dotNet subrollout example and then I'll post it for everyone to see.
Attached Images
File Type: jpg dialog.jpg (22.8 KB, 216 views)
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 11-02-2011, 12:41 PM   #51
lo
the frequentest!
portfolio
Rotem Shiffman
Tel Aviv, Israel
 
Join Date: Jul 2005
Posts: 2,839
I don't think there is a simple way of changing the colors and fonts of the window frame, that is, without handling the frame painting yourself.
 
Old 11-02-2011, 02:03 PM   #52
JokerMartini
Expert
 
JokerMartini's Avatar
portfolio
John Martini
CG Supervisor, 3D, Maxscript, VFX
Ingenuity Engine
Los Angeles, USA
 
Join Date: Mar 2009
Posts: 1,313
Send a message via AIM to JokerMartini
Got it

No worries.
It's not to that important really.

So when I create a button and attempt to make it a flat style button it still seems to take on a border color being white?
How do I remove the border of the button so its just flat.

Code:
theFont = dotnetobject "System.Drawing.Font" "Arial" 9 fn buttonFactory X Y W H fCol bCol txt = ( local theBut = dotNetObject "button" theBut.Font = theFont theBut.flatStyle=theBut.flatStyle.flat theBut.Bounds = dotNetObject "System.Drawing.Rectangle" X Y W H theBut.BackColor = (dotNetClass "System.Drawing.Color").fromARGB bCol[1] bCol[2] bCol[3] theBut.ForeColor = (dotNetClass "System.Drawing.Color").fromARGB fCol[1] fCol[2] fCol[3] theBut.TextAlign = theBut.TextAlign.MiddleCenter theBut.Text = txt theBut ) --//Buttons btnGrind = buttonFactory 308 135 74 24 [255,255,255] [61,148,178] "Grind" TheForm = dotNetObject "Form" TheForm.controls.addRange #(btnGrind) TheForm.bounds = dotNetObject "system.drawing.rectangle" 500 500 565 225 TheForm.backColor = TheForm.backColor.fromARGB 153 153 153 --Set the parent of the form to be Max. --Get the max handle pointer. maxHandlePointer=(Windows.GetMAXHWND()) --Convert the HWND handle of Max to a dotNet system pointer sysPointer = DotNetObject "System.IntPtr" maxHandlePointer --Create a dotNet wrapper containing the maxHWND maxHwnd = DotNetObject "MaxCustomControls.Win32HandleWrapper" sysPointer --Show the Max form using the wrapper. TheForm.Show (maxHwnd)
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 11-02-2011, 02:10 PM   #53
lo
the frequentest!
portfolio
Rotem Shiffman
Tel Aviv, Israel
 
Join Date: Jul 2005
Posts: 2,839
Code:
theBut.flatAppearance.BorderSize = 0
 
Old 11-02-2011, 08:28 PM   #54
JokerMartini
Expert
 
JokerMartini's Avatar
portfolio
John Martini
CG Supervisor, 3D, Maxscript, VFX
Ingenuity Engine
Los Angeles, USA
 
Join Date: Mar 2009
Posts: 1,313
Send a message via AIM to JokerMartini
Completing first script

So I wanted to work on complete a first script to get a feel for how things work and see a script from start to finish.
This script simply takes the values in the spinners and calculates the even spacing between the number of objects set.

I've got few questions for you guys.

What's the best way to handle the values updating when the spinner value is changed? Right now its a mouseover which is way to intense considering the users mouse may hover but never change the value

The users can change to make the script dependant on the objects width or the spacing width by clicking on the label/button. The function that controls the states of those checkbuttons could probably be written a bit more efficiently. It seems redundant.

Lastly overall the code, could it be written a bit more efficiently, if so in what parts and how?

Thanks guys.

Once this is finished i'll begin working on putting together a subrollout reference.

Code:
--//Font 1 theFont = dotnetobject "System.Drawing.Font" "Arial" 9 --//Font h2 H2FontStyle = dotNetClass "System.Drawing.FontStyle" H2Font = dotnet.combineenums H2FontStyle.bold --//Preview array previewArr = #("O - O - O - O - O - O","- O - O - O - O - O - O -","- O O O O O O -") enableAccelerators=false --This is needed so that we can type in the values as well as use the spinner. fn fnUpdateValues = ( print "Calculating" if cbObjectWidth.checked == true do (--//ObjectWidth based if dlSpaceType.SelectedIndex + 1 == 1 do (--//Betweens Only newVal = (spTotalWidth.value-(spSpaceWidth.value*(spNumObjects.value-1)))/spNumObjects.value spObjectWidth.value = newVal ) if dlSpaceType.SelectedIndex + 1 == 2 do (--//Ends/Betweens newVal = (spTotalWidth.value-(spSpaceWidth.value*(spNumObjects.value+1)))/spNumObjects.value spObjectWidth.value = newVal ) ) if cbSpaceWidth.checked == true do (--//SpaceWidth based if dlSpaceType.SelectedIndex + 1 == 1 do (--//Betweens Only newVal = (spTotalWidth.value-(spNumObjects.value*spObjectWidth.value))/(spNumObjects.value-1) spSpaceWidth.value = newVal ) if dlSpaceType.SelectedIndex + 1 == 2 do (--//Ends/Betweens newVal = (spTotalWidth.value-(spNumObjects.value*spObjectWidth.value))/(spNumObjects.value+1) spSpaceWidth.value = newVal ) ) ) fn nudMouseMove sender arg = ( fnUpdateValues() ) fn PreviewFactory X Y W H fCol bCol txt = ( local theLab = dotNetObject "Label" theLab.Font = dotNetObject "System.Drawing.Font" "Arial" 12 H2Font theLab.Bounds = dotNetObject "System.Drawing.Rectangle" X Y W H theLab.BackColor = (dotNetClass "System.Drawing.Color").fromARGB bCol[1] bCol[2] bCol[3] theLab.ForeColor = (dotNetClass "System.Drawing.Color").fromARGB fCol[1] fCol[2] fCol[3] theLab.TextAlign = theLab.TextAlign.MiddleCenter theLab.Text = txt theLab ) fn labelFactory X Y W H fCol bCol txt = ( local theLab = dotNetObject "Label" theLab.Font = theFont theLab.Bounds = dotNetObject "System.Drawing.Rectangle" X Y W H theLab.BackColor = (dotNetClass "System.Drawing.Color").fromARGB bCol[1] bCol[2] bCol[3] theLab.ForeColor = (dotNetClass "System.Drawing.Color").fromARGB fCol[1] fCol[2] fCol[3] theLab.TextAlign = theLab.TextAlign.MiddleRight theLab.Text = txt theLab ) fn checkButtonFactory X Y W H fCol bCol txt enabled = ( local theBut = dotNetObject "CheckBox" theBut.Font = theFont theBut.flatAppearance.BorderSize = 0 theBut.flatStyle=theBut.flatStyle.flat theBut.appearance = theBut.appearance.button theBut.Bounds = dotNetObject "System.Drawing.Rectangle" X Y W H theBut.BackColor = (dotNetClass "System.Drawing.Color").fromARGB bCol[1] bCol[2] bCol[3] theBut.ForeColor = (dotNetClass "System.Drawing.Color").fromARGB fCol[1] fCol[2] fCol[3] theBut.TextAlign = theBut.TextAlign.MiddleRight theBut.Text = txt theBut.Checked = enabled --theBut.Enabled = NOT enabled theBut.tag = enabled theBut ) fn spinnerlFactory X Y W H minV maxV dec val enabled = ( local theSpn = dotNetObject "NumericUpDown" theSpn.Bounds = dotNetObject "System.Drawing.Rectangle" X Y W H theSpn.DecimalPlaces = dec theSpn.Increment = .1 theSpn.minimum = minV theSpn.maximum = maxV theSpn.value = val theSpn.ReadOnly = false theSpn.Enabled = enabled dotNet.addEventHandler theSpn "mouseDown" nudMouseDown dotNet.addEventHandler theSpn "mouseMove" nudMouseMove theSpn ) fn cmbBoxFactory X Y W H items = ( local theCmb = dotNetObject "ComboBox" theCmb.Bounds = dotNetObject "System.Drawing.Rectangle" X Y W H theCmb.DropDownStyle = theCmb.DropDownStyle.DropDownList theCmb.items.addRange items theCmb.SelectedIndex = 0 theCmb ) --//UI Items lbSpacerPreview= PreviewFactory 24 24 195 36 [255,255,255] [61,148,178] previewArr[1] lbTotalWidth = labelFactory 8 80 100 24 [0,0,0] [200,200,200] "Total Width:" spTotalWidth = spinnerlFactory 118 83 100 21 (-999999999) (999999999) 2 960.0 true lbNumObjects= labelFactory 8 114 100 24 [0,0,0] [200,200,200] "# Objects:" spNumObjects = spinnerlFactory 118 117 100 21 (-999999999) (999999999) 0 4 true cbObjectWidth = checkButtonFactory 12 148 100 24 [0,0,0] [200,200,200] "Object Width:" true spObjectWidth = spinnerlFactory 118 151 100 21 (-999999999) (999999999) 2 60.0 false cbSpaceWidth = checkButtonFactory 12 182 100 24 [0,0,0] [200,200,200] "Space Width:" false spSpaceWidth = spinnerlFactory 118 185 100 21 (-999999999) (999999999) 2 16.0 true lbSpaceType = labelFactory 8 216 100 24 [0,0,0] [200,200,200] "Space Type:" dlSpaceType = cmbBoxFactory 118 218 100 21 #("Betweens Only","Ends/Betweens","Ends Only") --//Actions fn fnSelectedTyped s e = ( type = dlSpaceType.SelectedIndex lbSpacerPreview.text = previewArr[type+1] fnUpdateValues() ) fn fnSpaceBased s e = ( if s.checked == true then ( cbObjectWidth.checked = false spObjectWidth.enabled = true spSpaceWidth.enabled = false )else( cbObjectWidth.checked = true spObjectWidth.enabled = false spSpaceWidth.enabled = true ) fnUpdateValues() ) fn fnObjectBased s e = ( if s.checked == true then ( cbSpaceWidth.checked = false spSpaceWidth.enabled = true spObjectWidth.enabled = false )else( cbSpaceWidth.checked = true spSpaceWidth.enabled = false spObjectWidth.enabled = true ) fnUpdateValues() ) --//Event Handlers dotnet.addEventHandler cbObjectWidth "CheckStateChanged" fnObjectBased dotnet.addEventHandler cbSpaceWidth "CheckStateChanged" fnSpaceBased dotnet.addEventHandler dlSpaceType "SelectedIndexChanged" fnSelectedTyped TheForm = dotNetObject "Form" TheForm.controls.addRange #(lbSpacerPreview,lbTotalWidth,spTotalWidth,lbNumO bjects,spNumObjects,cbObjectWidth,spObjectWidth,cb SpaceWidth,spSpaceWidth,lbSpaceType,dlSpaceType) TheForm.bounds = dotNetObject "system.drawing.rectangle" 500 500 260 300 TheForm.backColor = TheForm.backColor.fromARGB 200 200 200 TheForm.text = "Spacer v1.0" --Set the parent of the form to be Max. --Get the max handle pointer. maxHandlePointer=(Windows.GetMAXHWND()) --Convert the HWND handle of Max to a dotNet system pointer sysPointer = DotNetObject "System.IntPtr" maxHandlePointer --Create a dotNet wrapper containing the maxHWND maxHwnd = DotNetObject "MaxCustomControls.Win32HandleWrapper" sysPointer --Show the Max form using the wrapper. TheForm.Show (maxHwnd)
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 11-02-2011, 08:41 PM   #55
lo
the frequentest!
portfolio
Rotem Shiffman
Tel Aviv, Israel
 
Join Date: Jul 2005
Posts: 2,839
Quote:
Originally Posted by JokerMartini
What's the best way to handle the values updating when the spinner value is changed? Right now its a mouseover which is way to intense considering the users mouse may hover but never change the value


Use the numericUpDown control's ValueChanged event

There are some exceptions when running the code, the nudMouseDown function is undefined.
I'll try to have a more detailed look at the code tomorrow.
 
Old 11-02-2011, 08:45 PM   #56
JokerMartini
Expert
 
JokerMartini's Avatar
portfolio
John Martini
CG Supervisor, 3D, Maxscript, VFX
Ingenuity Engine
Los Angeles, USA
 
Join Date: Mar 2009
Posts: 1,313
Send a message via AIM to JokerMartini
Alright.
Ill look into that and change that so when you go over the code tomorrow it will have those newer operators included in it.
Thanks Lo!
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 11-03-2011, 10:19 AM   #57
Nysuatro
Veteran
portfolio
Robbert-Jan Brems
Leuven, Belgium
 
Join Date: Oct 2005
Posts: 80
Send a message via MSN to Nysuatro
Very interesting topic! Keep up the good work.
__________________
Portfolio
 
Old 11-03-2011, 02:20 PM   #58
JokerMartini
Expert
 
JokerMartini's Avatar
portfolio
John Martini
CG Supervisor, 3D, Maxscript, VFX
Ingenuity Engine
Los Angeles, USA
 
Join Date: Mar 2009
Posts: 1,313
Send a message via AIM to JokerMartini
update

Changed the code to have the value changed event.

Code:
--//Font 1 theFont = dotnetobject "System.Drawing.Font" "Arial" 9 --//Font h2 H2FontStyle = dotNetClass "System.Drawing.FontStyle" H2Font = dotnet.combineenums H2FontStyle.bold --//Preview array previewArr = #("O - O - O - O - O - O","- O - O - O - O - O - O -","- O O O O O O -") enableAccelerators=false --This is needed so that we can type in the values as well as use the spinner. fn fnUpdateValues = ( if cbObjectWidth.checked == true do (--//ObjectWidth based if dlSpaceType.SelectedIndex + 1 == 1 do (--//Betweens Only newVal = (spTotalWidth.value-(spSpaceWidth.value*(spNumObjects.value-1.0)))/spNumObjects.value spObjectWidth.value = newVal as float ) if dlSpaceType.SelectedIndex + 1 == 2 do (--//Ends/Betweens newVal = (spTotalWidth.value-(spSpaceWidth.value*(spNumObjects.value+1.0)))/spNumObjects.value spObjectWidth.value = newVal as float ) ) if cbSpaceWidth.checked == true do (--//SpaceWidth based if dlSpaceType.SelectedIndex + 1 == 1 do (--//Betweens Only newVal = (spTotalWidth.value-(spNumObjects.value*spObjectWidth.value))/(spNumObjects.value-1.0) spSpaceWidth.value = newVal as float ) if dlSpaceType.SelectedIndex + 1 == 2 do (--//Ends/Betweens newVal = (spTotalWidth.value-(spNumObjects.value*spObjectWidth.value))/(spNumObjects.value+1.0) spSpaceWidth.value = newVal as float ) ) ) fn fnSpinnerChanged s e = ( fnUpdateValues() ) fn PreviewFactory X Y W H fCol bCol txt = ( local theLab = dotNetObject "Label" theLab.Font = dotNetObject "System.Drawing.Font" "Arial" 12 H2Font theLab.Bounds = dotNetObject "System.Drawing.Rectangle" X Y W H theLab.BackColor = (dotNetClass "System.Drawing.Color").fromARGB bCol[1] bCol[2] bCol[3] theLab.ForeColor = (dotNetClass "System.Drawing.Color").fromARGB fCol[1] fCol[2] fCol[3] theLab.TextAlign = theLab.TextAlign.MiddleCenter theLab.Text = txt theLab ) fn labelFactory X Y W H fCol bCol txt = ( local theLab = dotNetObject "Label" theLab.Font = theFont theLab.Bounds = dotNetObject "System.Drawing.Rectangle" X Y W H theLab.BackColor = (dotNetClass "System.Drawing.Color").fromARGB bCol[1] bCol[2] bCol[3] theLab.ForeColor = (dotNetClass "System.Drawing.Color").fromARGB fCol[1] fCol[2] fCol[3] theLab.TextAlign = theLab.TextAlign.MiddleRight theLab.Text = txt theLab ) fn checkButtonFactory X Y W H fCol bCol txt enabled = ( local theBut = dotNetObject "CheckBox" theBut.Font = theFont theBut.flatAppearance.BorderSize = 0 theBut.flatStyle=theBut.flatStyle.flat theBut.appearance = theBut.appearance.button theBut.Bounds = dotNetObject "System.Drawing.Rectangle" X Y W H theBut.BackColor = (dotNetClass "System.Drawing.Color").fromARGB bCol[1] bCol[2] bCol[3] theBut.ForeColor = (dotNetClass "System.Drawing.Color").fromARGB fCol[1] fCol[2] fCol[3] theBut.TextAlign = theBut.TextAlign.MiddleRight theBut.Text = txt theBut.Checked = enabled --theBut.Enabled = NOT enabled theBut.tag = enabled theBut ) fn spinnerlFactory X Y W H minV maxV dec val enabled = ( local theSpn = dotNetObject "NumericUpDown" theSpn.Bounds = dotNetObject "System.Drawing.Rectangle" X Y W H theSpn.DecimalPlaces = dec theSpn.Increment = .1 theSpn.minimum = minV theSpn.maximum = maxV theSpn.value = val theSpn.ReadOnly = false theSpn.Enabled = enabled dotNet.addEventHandler theSpn "ValueChanged" fnSpinnerChanged theSpn ) fn cmbBoxFactory X Y W H items = ( local theCmb = dotNetObject "ComboBox" theCmb.Bounds = dotNetObject "System.Drawing.Rectangle" X Y W H theCmb.DropDownStyle = theCmb.DropDownStyle.DropDownList theCmb.items.addRange items theCmb.SelectedIndex = 0 theCmb ) --//UI Items lbSpacerPreview= PreviewFactory 24 24 195 36 [255,255,255] [61,148,178] previewArr[1] lbTotalWidth = labelFactory 8 80 100 24 [0,0,0] [200,200,200] "Total Width:" spTotalWidth = spinnerlFactory 118 83 100 21 (-999999999) (999999999) 2 960.0 true lbNumObjects= labelFactory 8 114 100 24 [0,0,0] [200,200,200] "# Objects:" spNumObjects = spinnerlFactory 118 117 100 21 (-999999999) (999999999) 0 4 true cbObjectWidth = checkButtonFactory 12 148 100 24 [0,0,0] [200,200,200] "Object Width:" true spObjectWidth = spinnerlFactory 118 151 100 21 (-999999999) (999999999) 2 60.0 false cbSpaceWidth = checkButtonFactory 12 182 100 24 [0,0,0] [200,200,200] "Space Width:" false spSpaceWidth = spinnerlFactory 118 185 100 21 (-999999999) (999999999) 2 16.0 true lbSpaceType = labelFactory 8 216 100 24 [0,0,0] [200,200,200] "Space Type:" dlSpaceType = cmbBoxFactory 118 218 100 21 #("Betweens Only","Ends/Betweens","Ends Only") --//Actions fn fnSelectedTyped s e = ( type = dlSpaceType.SelectedIndex lbSpacerPreview.text = previewArr[type+1] fnUpdateValues() ) fn fnSpaceBased s e = ( if s.checked == true then ( cbObjectWidth.checked = false spObjectWidth.enabled = true spSpaceWidth.enabled = false )else( cbObjectWidth.checked = true spObjectWidth.enabled = false spSpaceWidth.enabled = true ) fnUpdateValues() ) fn fnObjectBased s e = ( if s.checked == true then ( cbSpaceWidth.checked = false spSpaceWidth.enabled = true spObjectWidth.enabled = false )else( cbSpaceWidth.checked = true spSpaceWidth.enabled = false spObjectWidth.enabled = true ) fnUpdateValues() ) --//Event Handlers dotnet.addEventHandler cbObjectWidth "CheckStateChanged" fnObjectBased dotnet.addEventHandler cbSpaceWidth "CheckStateChanged" fnSpaceBased dotnet.addEventHandler dlSpaceType "SelectedIndexChanged" fnSelectedTyped TheForm = dotNetObject "Form" TheForm.controls.addRange #(lbSpacerPreview,lbTotalWidth,spTotalWidth,lbNumO bjects,spNumObjects,cbObjectWidth,spObjectWidth,cb SpaceWidth,spSpaceWidth,lbSpaceType,dlSpaceType) TheForm.bounds = dotNetObject "system.drawing.rectangle" 500 500 260 300 TheForm.backColor = TheForm.backColor.fromARGB 200 200 200 TheForm.text = "Spacer v1.0" --Set the parent of the form to be Max. --Get the max handle pointer. maxHandlePointer=(Windows.GetMAXHWND()) --Convert the HWND handle of Max to a dotNet system pointer sysPointer = DotNetObject "System.IntPtr" maxHandlePointer --Create a dotNet wrapper containing the maxHWND maxHwnd = DotNetObject "MaxCustomControls.Win32HandleWrapper" sysPointer --Show the Max form using the wrapper. TheForm.Show (maxHwnd)
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 11-03-2011, 02:57 PM   #59
lo
the frequentest!
portfolio
Rotem Shiffman
Tel Aviv, Israel
 
Join Date: Jul 2005
Posts: 2,839
three small things:
1) The increment of the number of objects spinner is 0.1, while the number of displayed decimal digits is 0, so you have to click it 10 times before it increments one number, making the user believe it is broken.

2) Just some syntactic sugar, I would write this:
Code:
if s.checked == true then ( cbObjectWidth.checked = false spObjectWidth.enabled = true spSpaceWidth.enabled = false )else( cbObjectWidth.checked = true spObjectWidth.enabled = false spSpaceWidth.enabled = true )

as this:
Code:
spObjectWidth.enabled = s.checked cbObjectWidth.enabled = spSpaceWidth.enabled = not s.checked

but I guess it's a matter of preference.

3) You might want to avoid having your form appear in the taskbar:
Code:
TheForm.showInTaskbar = off
 
Old 11-03-2011, 04:00 PM   #60
JokerMartini
Expert
 
JokerMartini's Avatar
portfolio
John Martini
CG Supervisor, 3D, Maxscript, VFX
Ingenuity Engine
Los Angeles, USA
 
Join Date: Mar 2009
Posts: 1,313
Send a message via AIM to JokerMartini
Finished Button Spacer 1.0

Here is the final code all put together. My first completed dotNet tool. Although it might not seem like a lot to many, its super exciting and a big learning experience for me. Next I'm moving onto the doing subRollouts in dotNet. That will be the next post here.

Special thanks to Rotem for the help.

Check it out.

Code:
--//Font 1 theFont = dotnetobject "System.Drawing.Font" "Arial" 9 --//Font h2 H2FontStyle = dotNetClass "System.Drawing.FontStyle" H2Font = dotnet.combineenums H2FontStyle.bold --//Preview array previewArr = #("O - O - O - O - O - O","- O - O - O - O - O - O -","- O O O O O O -") enableAccelerators=false --This is needed so that we can type in the values as well as use the spinner. fn fnUpdateValues = ( if cbObjectWidth.checked == true do (--//ObjectWidth based if dlSpaceType.SelectedIndex + 1 == 1 do (--//Betweens Only newVal = (spTotalWidth.value-(spSpaceWidth.value*(spNumObjects.value-1.0)))/spNumObjects.value spObjectWidth.value = newVal ) if dlSpaceType.SelectedIndex + 1 == 2 do (--//Ends/Betweens newVal = (spTotalWidth.value-(spSpaceWidth.value*(spNumObjects.value+1.0)))/spNumObjects.value spObjectWidth.value = newVal ) if dlSpaceType.SelectedIndex + 1 == 3 do (--//Ends Only newVal = (spTotalWidth.value-(spSpaceWidth.value*2))/spNumObjects.value spObjectWidth.value = newVal ) ) if cbSpaceWidth.checked == true do (--//SpaceWidth based if dlSpaceType.SelectedIndex + 1 == 1 do (--//Betweens Only newVal = (spTotalWidth.value-(spNumObjects.value*spObjectWidth.value))/(spNumObjects.value-1.0) spSpaceWidth.value = newVal ) if dlSpaceType.SelectedIndex + 1 == 2 do (--//Ends/Betweens newVal = (spTotalWidth.value-(spNumObjects.value*spObjectWidth.value))/(spNumObjects.value+1.0) spSpaceWidth.value = newVal ) if dlSpaceType.SelectedIndex + 1 == 3 do (--//Ends Only newVal = (spTotalWidth.value-(spObjectWidth.value*spNumObjects.value))/2 spSpaceWidth.value = newVal ) ) ) fn fnSpinnerChanged s e = ( fnUpdateValues() ) fn PreviewFactory X Y W H fCol bCol txt = ( local theLab = dotNetObject "Label" theLab.Font = dotNetObject "System.Drawing.Font" "Arial" 12 H2Font theLab.Bounds = dotNetObject "System.Drawing.Rectangle" X Y W H theLab.BackColor = (dotNetClass "System.Drawing.Color").fromARGB bCol[1] bCol[2] bCol[3] theLab.ForeColor = (dotNetClass "System.Drawing.Color").fromARGB fCol[1] fCol[2] fCol[3] theLab.TextAlign = theLab.TextAlign.MiddleCenter theLab.Text = txt theLab ) fn labelFactory X Y W H fCol bCol txt = ( local theLab = dotNetObject "Label" theLab.Font = theFont theLab.Bounds = dotNetObject "System.Drawing.Rectangle" X Y W H theLab.BackColor = (dotNetClass "System.Drawing.Color").fromARGB bCol[1] bCol[2] bCol[3] theLab.ForeColor = (dotNetClass "System.Drawing.Color").fromARGB fCol[1] fCol[2] fCol[3] theLab.TextAlign = theLab.TextAlign.MiddleRight theLab.Text = txt theLab ) fn checkButtonFactory X Y W H fCol bCol txt enabled = ( local theBut = dotNetObject "CheckBox" theBut.Font = theFont theBut.flatAppearance.BorderSize = 0 theBut.flatStyle=theBut.flatStyle.flat theBut.appearance = theBut.appearance.button theBut.Bounds = dotNetObject "System.Drawing.Rectangle" X Y W H theBut.BackColor = (dotNetClass "System.Drawing.Color").fromARGB bCol[1] bCol[2] bCol[3] theBut.ForeColor = (dotNetClass "System.Drawing.Color").fromARGB fCol[1] fCol[2] fCol[3] theBut.TextAlign = theBut.TextAlign.MiddleRight theBut.Text = txt theBut.Checked = enabled theBut.tag = enabled theBut ) fn spinnerlFactory X Y W H minV maxV dec val enabled = ( local theSpn = dotNetObject "NumericUpDown" theSpn.Bounds = dotNetObject "System.Drawing.Rectangle" X Y W H theSpn.DecimalPlaces = dec theSpn.Increment = 1.0 theSpn.minimum = minV theSpn.maximum = maxV theSpn.value = val theSpn.ReadOnly = false theSpn.Enabled = enabled dotNet.addEventHandler theSpn "ValueChanged" fnSpinnerChanged theSpn ) fn cmbBoxFactory X Y W H items = ( local theCmb = dotNetObject "ComboBox" theCmb.Bounds = dotNetObject "System.Drawing.Rectangle" X Y W H theCmb.DropDownStyle = theCmb.DropDownStyle.DropDownList theCmb.items.addRange items theCmb.SelectedIndex = 0 theCmb ) --//UI Items lbSpacerPreview= PreviewFactory 24 24 195 36 [255,255,255] [61,148,178] previewArr[1] lbTotalWidth = labelFactory 8 80 100 24 [0,0,0] [200,200,200] "Total Width:" spTotalWidth = spinnerlFactory 118 83 100 21 (-999999999) (999999999) 2 960.0 true lbNumObjects= labelFactory 8 114 100 24 [0,0,0] [200,200,200] "# Objects:" spNumObjects = spinnerlFactory 118 117 100 21 (-999999999) (999999999) 0 4 true cbObjectWidth = checkButtonFactory 12 148 100 24 [0,0,0] [200,200,200] "Object Width:" true spObjectWidth = spinnerlFactory 118 151 100 21 (-999999999) (999999999) 2 60.0 false cbSpaceWidth = checkButtonFactory 12 182 100 24 [0,0,0] [200,200,200] "Space Width:" false spSpaceWidth = spinnerlFactory 118 185 100 21 (-999999999) (999999999) 2 16.0 true lbSpaceType = labelFactory 8 216 100 24 [0,0,0] [200,200,200] "Space Type:" dlSpaceType = cmbBoxFactory 118 218 100 21 #("Betweens Only","Ends/Betweens","Ends Only") --//Actions fn fnSelectedTyped s e = ( type = dlSpaceType.SelectedIndex lbSpacerPreview.text = previewArr[type+1] fnUpdateValues() ) fn fnSpaceBased s e = ( spObjectWidth.enabled = s.checked cbObjectWidth.checked = spSpaceWidth.enabled = not s.checked fnUpdateValues() ) fn fnObjectBased s e = ( spSpaceWidth.enabled = s.checked cbSpaceWidth.checked = spObjectWidth.enabled = not s.checked fnUpdateValues() ) --//Event Handlers dotnet.addEventHandler cbObjectWidth "CheckStateChanged" fnObjectBased dotnet.addEventHandler cbSpaceWidth "CheckStateChanged" fnSpaceBased dotnet.addEventHandler dlSpaceType "SelectedIndexChanged" fnSelectedTyped TheForm = dotNetObject "Form" TheForm.controls.addRange #(lbSpacerPreview,lbTotalWidth,spTotalWidth,lbNumO bjects,spNumObjects,cbObjectWidth,spObjectWidth,cb SpaceWidth,spSpaceWidth,lbSpaceType,dlSpaceType) TheForm.bounds = dotNetObject "system.drawing.rectangle" 500 500 260 300 TheForm.backColor = TheForm.backColor.fromARGB 200 200 200 TheForm.text = "Spacer v1.0" --Set the parent of the form to be Max. --Get the max handle pointer. maxHandlePointer=(Windows.GetMAXHWND()) --Convert the HWND handle of Max to a dotNet system pointer sysPointer = DotNetObject "System.IntPtr" maxHandlePointer --Create a dotNet wrapper containing the maxHWND maxHwnd = DotNetObject "MaxCustomControls.Win32HandleWrapper" sysPointer --Show the Max form using the wrapper. TheForm.showInTaskbar = off TheForm.Show (maxHwnd)
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
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 10:41 AM.


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