[Closed] IN/Out Tangent Buttons
Is there some way I can incorporate… the in and out tangent types buttons which pops up when we right click on any key … in a rollout?
where exactly do I need this:
I am working on a script which allows the user to create a key by pressing a button.
I’d like to give him additional control of also selecting the ease in-out type for this keyframe.
I know how to give him a drop down list using which he can make his preference, but I would like this to look and function the same as it does with any max keyframe.
Thanks … all helping efforts appreciated
shibu
Check out the Tangent Util R4 script by Grant Adam:
http://members.optushome.com.au/ghra/scripts.htm
He uses those tangent buttons, perhaps that will give some insight.
Hi,
here’s another option. it’s not perfect, but might be good enough…
try(destroyDialog roTest)catch()
rollout roTest "Test"
(
-- This function (createIconDropDown) dynamically creates a rollout with icons to use as a dropdown.
-- It uses the rolloutCreator struct that comes with max.
-- The createIconDropDown takes one mandatory parameter (icons) and two optional ones (roName and action)
-- The icons parameter is an array of icons (the format of each icon is the format of a button's "images" attribute).
-- The roName parameter is the name of the rollout.
-- The action parameter is a string of maxscript commands to be executed when one of the buttons
-- is pressed in the dropdown rollout. Use %index% to refer to the index number of the pressed
-- button (the text %index% will be replaced with the actual index number).
fn createIconDropDown icons roName:"myRollout" action:"" =
(
-- This function replaces all instances of "findStr" in "str" with "replaceStr".
fn replaceString str findStr replaceStr =
(
local tmpStr = copy str
local outStr = ""
local i
while (i = findString tmpStr findStr) != undefined do (
outStr += subString tmpStr 1 (i - 1) + replaceStr as string
tmpStr = subString tmpStr (i + findStr.count) (tmpStr.count - (i + findStr.count) + 1)
)
outStr += tmpStr
outStr
)
-- Create a rolloutCreator instance and initiate it.
local rci = rolloutCreator roName ""
rci.begin()
-- The rolloutCreator has a filter mode in which it uses @ instead of " for strings, so,
-- we replace all occurances of " with @ in action.
action = replaceString action "\"" "@"
-- Loop through all the icons that were passed to the function, and create a button for each one.
for i = 1 to icons.count do (
-- Define the button name
local bnName = ("bnIcon" + i as string) as name
-- Calculate the button position.
local pos = if i == 1 then "[0,0]" else ("(" + ("bnIcon" + (i-1) as string) + ".pos + [0,26])")
-- Parse the images array.
local images = "" as stringStream
format "#(\"%\", %, %, %, %, %, %)" icons[i][1] undefined icons[i][3] icons[i][4] icons[i][5] icons[i][6] icons[i][7] to:images
images = images as string
-- Add a button control to the rolloutCreator.
rci.addControl #button bnName "" paramStr:("width:26 height:26 images:" + images + " pos:" + pos)
-- Replace %index% in the actoin string with the current button number.
indexedAction = replaceString action "%index%" (i as string)
-- Create the event handler for the button.
rci.addHandler bnName #pressed filter:on codeStr:("try(" + indexedAction + ")catch()")
)
-- Create and return the rollout.
rci.end()
)
-- Create a variable to hold the icon image name (this is just to shorten the array definition below)
local iconImage = getDir #ui + "\\icons\\" + "TrackViewKeyTangents_24i.bmp"
-- Create a variable that will hold the icons used in the dropdown. The format is the format of
-- a button's "images" attribute (see "button ui element" in the maxscript help).
local icons = #(
#(iconImage, undefined, 21, 1, 1, 1, 1),
#(iconImage, undefined, 21, 2, 2, 2, 2),
#(iconImage, undefined, 21, 3, 3, 3, 3),
#(iconImage, undefined, 21, 4, 4, 4, 4),
#(iconImage, undefined, 21, 5, 5, 5, 5)
)
local dropdownIndex = 1 -- this var will hold the icon dropdown index
local roIconDropDown -- this var will hold the dynamically created dropdown rollout
-- Create the dropdown button. A checkbutton is used so we can use the checked state to
-- either create or destroy the dropdown rollout.
checkButton cbDropDown "" width:26 height:26 images:icons[dropdownIndex]
-- In the dropdown checkbutton's handler we create the dropdown rollout dynamically and create the dialog
-- if the checkbutton's state is true (checked), and destroy the dropdown rollout if it's false (unchecked).
on cbDropDown changed state do (
if state then (
-- First, try to close the dropdown rollout, if an old one is still open.
try(destroyDialog roIconDropDown)catch()
-- Then, create the new dropdown rollout with the createIconDropDown function.
-- The createIconDropDown takes one mandatory parameter (icons) and two optional ones (roName and action)
-- The icons parameter is an array of icons (the format of each icon is the format of a button's "images" attribute).
-- The roName parameter is the name of the rollout.
-- The action parameter is a string of maxscript commands to be executed when one of the buttons
-- is pressed in the dropdown rollout. Use %index% to refer to the index number of the pressed
-- button (the text %index% will be replaced with the actual index number).
-- In this example, the action will first update the dropdownIndex variable, then change the image on
-- the checkbutton to reflect the newly selected mode, then close the dropdown dialog and uncheck the checkbutton.
roIconDropDown = createIconDropDown icons roName:roTmpIconDropDown action:"roTest.dropdownIndex = %index%; roTest.cbDropDown.images = roTest.icons[%index%]; roTest.cbDropDown.checked = false; try(destroyDialog roTest.roIconDropDown)catch()"
-- Calculate the position of the dropdown rollout dialog.
-- NOTE: the constant at the end ([3,48]) is just what I found right for this example,
-- and you'll probably need to tweak it when used with you own dialogs.
local p = getDialogPos roTest + cbDropDown.pos + [3,48]
-- Now create the dropdown dialog.
createDialog roIconDropDown width:26 height:(26*5) style:#() pos:p
) else (
-- If the checkbutton is checked off, the close the dropdown dialog.
try(destroyDialog roIconDropDown)catch()
)
)
-- If the dropdown is ued in a dialog, use the mousemove handler to close the dropdown rollout.
-- NOTE: this will not work if it used in a rollout floater, in which case the user can still
-- close the dropdown by pressing the dropdown checkbutton again (to turn it off).
on roTest mousemove pos do (
try(destroyDialog roIconDropDown)catch()
cbDropDown.state = false
)
on roTest close do (
-- When closing the host dialog or rollout floater, make sure you clean un,
-- so you're not left with a floating dropdown dialog.
try(destroyDialog roIconDropDown)catch()
)
)-- end of roTest rollout
createDialog roTest
hOpe this helps,
o