[Closed] adding numbered attributes
hello,
I want to add a number of custom attributes to a modifier, the thing is the number of attributes depends on the number of selected objects, so here is what I came up with
fn addAttributes =
(
for i in 1 to selection.count do
(
nn= i as string
namex="sppx"+nn
namey="sppy"+nn
namx="spx"+nn
namy="spy"+nn
ca = Attributes wires
(
parameters main rollout:params
(
namex type:#float ui:namx
namey type:#float ui:namy
)
rollout params "params"
(
local range=[0,200,200]
spinner namx "spx" type:#float range:range
spinner namy "spy" type:#float range:range
)
)
custAttributes.add $Circle02.modifiers[1] ca
)
)
addAttributes()
$Circle02 being the object I want to add the custom attributes to.
the main object of the script is I want to store the control object locations in a Pen Attribute holder modifier so I can use the presets function in there to ease facial animation, the next step would be to wire those attributes to the actual control objects but first I want to add the attributes.
the main problem I’m facing is I want each new parameter to have a unique name that’s why i made all the variables, but it doesn’t work.
I don’t know if this is the best way to do what i’m looking for so I’m open to any suggestion.
edit:I’m using max 2010
Try using just a single parameter and instead assign a float_list controller to it and then for however many controls you have just add a new controller to the list. You might have to write a few extra functions for management, but I’ve been down this road before and I found it to be a much easier way to go about it.
I’m not that good with maxscript, I only try my hand when I have a large repetitive task with macro recorder as my friend
if it’s not too much trouble, can you elaborate a bit…thanks
Oops, I apologize, I didn’t read your post carefully enough the first time. I saw you saying you were trying to do something that reminded me of something I had done before. Different situations though.
Unfortunately you’re not going to be able to create the caDef dynamically in the way you are hoping. The reason it is currently throwing an error is because you are trying to use a variable’s stored string value as the parameters’ and spinners’ internal names. This is not how it works. Instead of calling it “sppx1” like you are wanting to in your example, it is actually calling it “namex”.
You are going to have to figure out before hand how many control objects you are going to be using and actually write out all the parameters and spinners.
thank you very much both for your replies.
looks like I babbled too much in my first post that everyone is getting it wrong
let me iterate and explain what I’m trying to do.
I have a bunch of facial controls that I want to store their position in a Pen attribute holder modifier so I can benefit from the presets functions in the modifier to make the repetitive poses (like phonemes for example) easy to recreate while animation.
from what I gathered, I had to store some custom attributes in the modifiers equal to the number of selected controls times 3 for x,y,z then wire those custom attributes back to the x,y,z position tracks of the controls…problem is I have like 30 controls and it’ll be much work to do it by hand.
currently this is exactly my problem, if all fails, doing it the way you suggested isn’t much trouble, it’s a bunch of copy and paste, but if there’s a more “nicer” way to do it, it’ll be great
o look at me i babbled too much again
Hello Ahmad and Mathieson,
You might want to consider using something like a listbox control instead, as I think it’ll be easier to manage. You wouldn’t be able to actually ‘wire’ the listview’s values, but you can make everything works dynamically within their dialog’s open event and when they change their values. You can even include callbacks depending on how you want it to react.
Here’s an example where it’ll hopefully be the same behaviour you are looking for:
(
rollout dialog_listTest "List test"
(
local objs = #()
listBox lb_nodes "Nodes:"
button bt_refreshList "Refresh List" across:2 align:#left
spinner sp_scale "Scale:" align:#right
-- Function to get the selected object's scale value
fn getObjectScale index =
(
selectedObj = objs[index]
if (isValidNode selectedObj) do
(
sp_scale.value = ( (selectedObj.scale.x + selectedObj.scale.y + selectedObj.scale.z) / 3)
)
)
-- Function to gather selection, and put it in the list
fn getObjects =
(
objs = #()
objs_names = #()
for obj in selection do
(
append objs obj
append objs_names obj.name
)
lb_nodes.items = objs_names
if objs.count > 0 do
(
lb_nodes.selection = 1
getObjectScale 1
)
)
-- When the dialog opens, run the function to get the selection
on dialog_listTest open do getObjects()
-- Runs function to get object's scale, and change the spinner's value
on lb_nodes selected index do getObjectScale index
-- Gather current selection to refresh the list
on bt_refreshList pressed do getObjects()
-- When spinner is changed, changed the object's scale
on sp_scale changed val do
(
if lb_nodes.items.count > 0 do
(
index = lb_nodes.selection
selectedObj = objs[index]
if (isValidNode selectedObj) do selectedObj.scale = [val, val, val]
)
)
)
createDialog dialog_listTest 200 200
)
Refresh the list with objects selected, then you can control any one of those objects’ scale value with the spinner.
If you really do have your heart set on spinners though, you may want to check out subRollouts. I never tried going in this direction, but create a new subRollout based on how many objects are selected.
Hope the above info helps!
EDIT: After reading your posts again I’m not totally sure this is what you’re asking for