[Closed] Q – Can you assign a script to a custom att
Hi there,
Just wondering if it is possible to make a custom attribute button that when pressed runs a script. I have been looking through the various options in the parameter editor and I can’t seem to find anything so i thought I’d see if anyone here knows?
thanks
Pete
You just want to run a script with a button? Well, you can either do it via a macroscript:
MacroScript MyScript category:“My scripts” tooltip:“My script” Icon:#(“Yay”,1)
(
Include “$scripts/myscript.ms”
)
Which you install in the UI/macroscripts folder as a mymacro.mcr, or you can just select all your code, and drag it to the toolbar!
I can do them on the toolbar ok but I wanted to add one to a characters attribute holder modifier, you know like how you can add sliders and stuff?
Sorry that must have seemed like the most daft question…
Oh, I see! Completely misunderstood. Hm… I’ll have to get back to you on that one!
You’ll have to write your own custom attributes, ie. don’t use the Custom Attributes dialog.
If you tell me exactly what you want to do I may be able to help you.
Well i’ve never wriien my own custom attributes before, it seems kinda scarey.
But i’d basicly like to have a button that would run a standard macroscript sitting in an objects custom attributes. it’s a bummer that they don’t have one as standard.
Do you know how I could make basic template for this?
by the way, i’m using the Wahooney smart transform and it rocks!
Thank’s pete,
Writing a script that adds a custom attribute is deceptively easy, here is an example:
catTest = attributes CAT_Test -- define your attribute names
(
parameters main rollout:roTest
(
-- define a float for the distance
dist type:#float ui:spnDist default:10.0
)
rollout roTest "Parameters" -- create a rollout
(
spinner spnDist "Distance:" range:[0.001, 100000.0, 10.0] type:#float
button btnRand "Randomize Position" -- create a button
button btnReset "Reset Position" -- create a button
on btnRand pressed do
(
-- add an event that is triggered
-- when the button is pressed
f = spnDist.value
$.pos += random [-f, -f, -f] [f, f, f]
)
on btnReset pressed do
(
-- add an event that is triggered
-- when the button is pressed
$.pos = [0,0,0]
)
)
)
-- add the attributes to the selected object's current modifier
custAttributes.add (modPanel.getCurrentObject()) catTest
Just copy and paste this script into a new script window, select an object and execute.
If you want an indepth description of this, just gimme a holler.
Hey there wahooney,
Just tried out that script, it works fine and your right it is easy!
I’ve been using that as a bit of a template and editing it a bit in visual max script. (I know it’s evil but if you don’t do anything too crazy it can hold together)
Thanks again bud.
Ahh, wahoony, one more question if you have the time. Is it difficult to add some extra bits and pieces to an existing rollout/custom attribute. I only ask because as I add different buttons they pop up in new rollouts and it could get a bit messy…