[Closed] MAXSCRIPT: option box
As Bobo suggests, a dialog is prettier than a rollout floater. I just want to add a tip from my own little bag of tricks. When you declare your dialog, try using this construct:
createDialog someRollout someRollout.width someRollout.height
This allows you to redefine the width and height of the rollout without having to remember to update the createDialog statement as well. So it’s a bit of a timesaver:)
RH
thanks bobo, that did the trick.
so now i have the script to do what i want, if all values are entered in the appropriate edittext boxes. but if they are not, then it just read the global variables for each. this wouldnt be so bad, if i could keep those values displayed in their editext boxes. i thought of doing an if then else statement, but ran into some problems.
i cant declare a variable in the if statement that references the entered text for that edittext box. man i hope this is making sense. basically what i want it to do is each edittext be given a default value and store that as newLength, etc. then if the user enters a new value, then the variable newLength will be given the newly entered value. then hit the apply button and presto, u have your object with parameters entered. basically what maya has for each of its objects. seems like it should be easy enough to accomplish.
this is what i have so far
–start script–
macroscript PolyCube
category:“Polygon Objects”
(
on execute do
(
Box lengthsegs:1 widthsegs:1 heightsegs:1 length:10 width:10 height:10 mapCoords:off pos:[0,0,0] isSelected:on
)
–define altExecute rollout–
on altExecute type do
(
rollout hello "hello"
(
edittext length "Length" text:"10" pos:[40,8] width:110 height:20
edittext width "Width" pos:[40,32] width:110 height:20
edittext height "Height" pos:[40,56] width:110 height:20
edittext lengthSegs "Length Segs" pos:[40,88] width:110 height:20
edittext widthSegs "Width Segs" pos:[40,112] width:110 height:20
edittext heightSegs "Height Segs" pos:[40,136] width:110 height:20
button apply "Apply"
--define event handlers for rollout--
global initLength = length.text
on length entered text do
(
global newLength = length.text as float
)
on width entered text do
(
global newWidth = width.text as float
)
on height entered text do
(
global newHeight = height.text as float
)
on lengthSegs entered text do
(
global newLengthSegs = lengthSegs.text as float
)
on widthSegs entered text do
(
global newWidthSegs = widthSegs.text as float
)
on heightSegs entered text do
(
global newHeightSegs = heightSegs.text as float
)
on apply pressed do
(
Box lengthsegs:newLengthSegs widthsegs:newWidthSegs heightsegs:newHeightSegs length:newLength width:newWidth height:newHeight mapCoords:off pos:[0,0,0] isSelected:on
)
)
createDialog hello 400 400
)
)
–end script–
Holy Crap it works!
–script–
– Adds the Maya option box
– to Polygon Primatives
macroScript PolyCube
category:“Polygon Objects”
(
global newLength = 10
global newWidth = 10
global newHeight = 10
global newLengthSegs = 1
global newWidthSegs = 1
global newHeightSegs = 1
on execute do
(
Box lengthsegs:1 widthsegs:1 heightsegs:1 length:10 width:10 height:10 mapCoords:off pos:[0,0,0] isSelected:on
macros.run "Modifier Stack" "Convert_to_Poly"
)
--define altExecute rollout--
on altExecute type do
(
rollout cube "cube" width:268 height:159
(
edittext edLength "Length" text:(newLength as string)pos:[27,35] width:109 height:20
edittext edWidth "Width " text:(newWidth as string)pos:[26,59] width:110 height:20
edittext edHeight "Height" text:(newHeight as string)pos:[29,83] width:107 height:20
edittext edLengthSegs "Length Segs " text:(newLengthSegs as string)pos:[163,35] width:90 height:20
edittext edWidthSegs "Width Segs " text:(newWidthSegs as string)pos:[168,59] width:85 height:20
edittext edHeightSegs "Height Segs" text:(newHeightSegs as string)pos:[168,83] width:85 height:20
button apply "Apply" pos:[20,117] width:66 height:21
button ok "OK" pos:[101,117] width:66 height:21
button cancel "Cancel" pos:[182,117] width:66 height:21
GroupBox lblParam "Parameters" pos:[4,4] width:260 height:149
--define event handlers for rollout--
on edLength entered text do
(
global newLength = edLength.text as float
)
on edWidth entered text do
(
global newWidth = edWidth.text as float
)
on edHeight entered text do
(
global newHeight = edHeight.text as float
)
on edLengthSegs entered text do
(
global newLengthSegs = edLengthSegs.text as float
)
on edWidthSegs entered text do
(
global newWidthSegs = edWidthSegs.text as float
)
on edHeightSegs entered text do
(
global newHeightSegs = edHeightSegs.text as float
)
on apply pressed do
(
Box lengthsegs:newLengthSegs widthsegs:newWidthSegs heightsegs:newHeightSegs length:newLength width:newWidth height:newHeight mapCoords:off pos:[0,0,0] isSelected:on
macros.run "Modifier Stack" "Convert_to_Poly"
)
on ok pressed do
(
Box lengthsegs:newLengthSegs widthsegs:newWidthSegs heightsegs:newHeightSegs length:newLength width:newWidth height:newHeight mapCoords:off pos:[0,0,0] isSelected:on
macros.run "Modifier Stack" "Convert_to_Poly"
destroyDialog cube
)
on cancel pressed do
(
destroyDialog cube
)
)
createDialog cube cube.width cube.height
)
)
–end script–
i kno its probably one of the messiest scripts, but hey, it does the job i need it to do. thanks to orpheo, bobo, and lfshade.
i learned a great deal in this little adventure, now on to the other primatives.
dammit, after looking through Carl’s script, i find that edittext is probably not the best rollout element to use. so i will redo it.
plus his a butt load cleaner than mine.
back to the drawing board
ok, i rewrote it, using carls script for some reference. i tried not to blatantly rip it off. there is a part in there about using a defualt name in there, i still hav to figure out befor ei can put that in, because now it just gives the object an empty name, just a small thing to correct. but the Cube, Sphere, Plane, Cylinder, and Cone are all done.
anyways, here is the script, hope someone finds at least a little use for it. thanks to carl knight, lfshade, bobo, and orpheo.