PDA

View Full Version : How to make a simple button ?


BOY1DA
08-26-2006, 03:36 AM
I have never done any max script before, and would like to know how
I would script a simple button. I have a basic idea of how to do it but not sure.

As an example ... If I click on a box, it will set a value of another object or multiple objects to a value I choose.

I want to set the hight of box B to 100 by clicking on box A ?

Any help will be appreciated.

THANKS.

Bobo
08-26-2006, 05:22 AM
I have never done any max script before, and would like to know how
I would script a simple button. I have a basic idea of how to do it but not sure.

As an example ... If I click on a box, it will set a value of another object or multiple objects to a value I choose.

I want to set the hight of box B to 100 by clicking on box A ?

Any help will be appreciated.

THANKS.

You want to click on a box to change other boxes? Why would you want to do that?
Some more info would be useful. I thought you wanted a simple button. What you describe is at the edge of advanced scripting and probably requires a lot more knowledge...

Do you want to run a script before that? Or do you want it to be a callback monitoring what you are doing and changing things as you go? How do you want to specify which objects to affect? Selection? How do you specify the value? A spinner? Or via the height of the Box A? Or something else?

Please try to write down step by step what you think the workflow of your tool would be.
Then you (and we all) can try to find the right commands to do what you want.

If you have just a vague idea what you want, or cannot describe your idea to others, chances are that writing the script will not be very easy...

BOY1DA
08-26-2006, 05:32 AM
Well .. I wanted to make a button for morph sliders.
for a face rig.

you would click on an object "the button" in the script you would hard code what
values would change on what objects "morphs" I want it to set all targets to "0"
except for the morph that button represents. that morph target will then be set to "100"

It is just easier to key morphs without having to set them all to 0 then ramp back up the one you want.

I hope that is clear ? I just tried to simplify the concept by using boxes for the test.

LoneRobot
08-27-2006, 11:11 PM
I have used for years a system for lipsync which does exactly what you suggest. I always thought it is better to set all the targets at 0 and then set the one you want to the value you need. As im not at my work computer i cant post you the script file, but i'll tell you how i do it.

I created a function called "zeromorph" , which uses a simple for/loop to step through the channels of the selected objects morpher modifier. This lives in startup/scripts and is called by the button press in max. the reason for this is it simplifies the code and doesn't matter how many morph targets you add.

on button MBP pressed do
(
zeromorph()
-- >> set morph value in this line <<--
)

this is much less code than listing the morpher channel and the value on every button. sorry i cant give you the exact code, but its sunday evening and i dont have access to the MXS help file.

BOY1DA
08-28-2006, 02:04 AM
Thanks pudgerboy...

That is a step in the right direction. how would I apply that to an object in the scene like
a box. What I mean is the box will be the button that controls the morpher.
I want to add it to a floating interface made out of max objects.

THANKS !

omega3d
08-28-2006, 04:10 AM
Okay Omar, did a little DVD for your chronicles.. lol. Check it out... I have an object (rectangle)

It has a edit spline modifier (that I made a check in)

And an attribute holder (which holds the "open" attribute thingy)

http://omega3d.boy1da.com/CheckObject.zip



ca = attributes checkobject
(
parameters objs rollout:adjust
(
requestValue type:#float ui:morpherValue
)
rollout adjust "Adjust value"
(
-- Runs if the object is selected
fn checkstatus =
(
if $Rectangle01.modifiers[2].enabled == false then
(
$Sphere01.morpher[1].value = checkobj.modifiers[1].requestValue
$Rectangle01.modifiers[2].enabled = true
) else (
if $Rectangle01.modifiers[2].enabled == true then
(
$Sphere01.morpher[1].value = 0
$Rectangle01.modifiers[2].enabled = false
)
)
)
on adjust open do checkStatus()

spinner morpherValue "MorphValue:" range:[0,100,100] type:#integer
)
)

custattributes.add $Rectangle01.modifiers[1] ca
(THIS IS A ROUGH PIECE.. you need the maxfile to use it.. or else its bananas.. lol

BOY1DA
08-28-2006, 05:23 AM
I tried something like this , so that I can click a box to change the radius of the teapot
as a test. but it didn't work....


on pickObject $Box04 then $Teapot01 .radius = 100

BOY1DA
08-28-2006, 06:18 AM
I got this much to work BUT it only does it once. then if i click it again it does nothing
I have to run the script again to get it to work again . How do I keep it active ?




(

pickObject $Box04

( $Teapot01 .radius = 100 )

)

omega3d
08-28-2006, 06:31 AM
Here is a better -- more explained version of the script thingy.. I will check your code in a sec.

http://omega3d.boy1da.com/CheckObjectRevised.zip

BOY1DA
08-28-2006, 06:45 AM
Here is a video of what I got to work so far..... 6.56 MB


http://omega3d.boy1da.com/BOX_CLICK.zip

Zbuffer
08-29-2006, 01:55 PM
Hi,

try this:

(
deleteAllChangeHandlers id:#foo
when select $Box01 changes id:#foo do
(
if selection[1]==$Box01 do $teapot01.radius+=50
)
)

Also, I would recommend Paul Neale's attribute holder to make pressets of the slider values
of a morpher
so you could reset all values of a morpher with a simple button

BOY1DA
08-29-2006, 03:29 PM
Thanks Zbuffer..

yea that does work , now the question is.. if I have 2 boxes.

how do I get them both to work to change the value of another object ?

I will need to make more then one button but with the same idea.

BOY1DA
09-06-2006, 09:43 PM
I still can't seem to get the script to stay active. any help would be appreciated .

BOY1DA
09-08-2006, 04:07 PM
I have got the script to work how I wanted it to.
I had to bastardize the code to get it to work.
I still don't fully understand all the syntax,
but was able to understand it enough to get it to do what I wanted.

I'm sure there is a much better way to streamline the code.
Once again beyond my skill level.

My last question is how do I get the script to run when
I run the max file ? I don't want to have to run it manually every time
I open the file....

The key thing that I wanted is to make the button a floating interface
NOT a button that was embedded in max.

Here is a video showing how it works as intended on an actually model with morphs. (http://www.hardwired.boy1da.com/videos/BUTTON_ACTION.zip)

Here is how I did the script based on the code that "Zbuffer" posted.

THANK YOU FOR YOUR HELP !


(
deleteAllChangeHandlers id:#foo

when select $Sphere01 changes id:#foo do

(

if selection[1]==$Sphere01 do

$FaceControl01/FaceControlHandle01.controller[1].position = [0,3.9,0]

$FaceControl02/FaceControlHandle02.controller[1].position = [0,-3.9,0]

$FaceControl03/FaceControlHandle03.controller[1].position = [0,-3.9,0]

)





deleteAllChangeHandlers id:#fo2

when select $Sphere02 changes id:#fo2 do

(

if selection[1]==$Sphere02 do

$FaceControl02/FaceControlHandle02.controller[1].position = [0,3.9,0]

$FaceControl01/FaceControlHandle01.controller[1].position = [0,-3.9,0]

$FaceControl03/FaceControlHandle03.controller[1].position = [0,-3.9,0]

)





deleteAllChangeHandlers id:#fo3

when select $Sphere03 changes id:#fo3 do

(

if selection[1]==$Sphere03 do

$FaceControl03/FaceControlHandle03.controller[1].position = [0,3.9,0]

$FaceControl02/FaceControlHandle02.controller[1].position = [0,-3.9,0]

$FaceControl01/FaceControlHandle01.controller[1].position = [0,-3.9,0]

)

)

supremepizza
02-04-2007, 11:45 AM
I wrote a script in max to make a object into a button.
but i don't know how to get the script to stay active
once i restart max.. check out this thread I did.
And let me know if you know how to make it work.

http://forums.cgsociety.org/showthread.php?f=98&t=397632 (http://forums.cgsociety.org/showthread.php?f=98&t=397632)

Sorry I had to cut this short I'm doing allot of rendering right now
so my system is too slow to really work on.

I'll talk to you later.

Omar.

Throw it in your scripts/startup folder for now since you're using it. I'm working on a version that asks if you want to run it on startup but it isn't working right now.

supremepizza
02-11-2007, 10:23 PM
Sorry it took so long to find the solution you're looking for. The past week I've been swamped. There is a script at ScriptSpot that will load the script and run it each time you load the scene. Called Autoexec 0.11. This way you don't need to run it every time Max starts.
I haven't used it myself but from it's description you should be able to distribute your scene anywhere without needing to distribute the script seperately. However according to the description you can also just have the scene point to the external script if you want to go that route.

Link (http://www.scriptspot.com/start.asp?p=download&ID=2424)

Enjoy,
Bill

BOY1DA
02-11-2007, 10:34 PM
Thanks for your response Bill.


I may also try to embed it into a custom attribute on an object in the scene....
but I have no idea if that will even work I would have to test it.

If all fails I will just use the buttons and sliders that can be scripted in max.

CGTalk Moderation
02-11-2007, 10:34 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.