Notifications
Clear all

[Closed] wrestling with custom atts

Please forgive the MXS 101 question, but I am just not getting this. If you would, please take a look at the following:

(
ca = attributes Added
(
parameters main rollout:params
(
bleem type:#float ui:sld_blerp 
clem type:#boolean ui:btn_clem default:true
)
 
rollout params "Added atts"
(
slider sld_blerp "Blerp value" range:[1,100,50]
button btn_clem "Clem state"
 
on sld_blerp changed value do
(print blerp)
 
on btn_clem pressed do
(
clem = not clem
print clem
) 
)
)
 
rollout make "Make an Object"
(
button btn "Make one"
local b
on btn pressed do
(
b = box name:"testbox"
p = point()
custAttributes.add b ca 
fs = p.position.x_position.controller = float_script()
fs.addNode "testbox" $Box01
-- the next line has no effect
p.position.x_position.controller.script = "$testbox.pos.x = "+b.blerp as string
b.position.y_position.controller = Float_Script()
-- on creation, the box's y_pos is offset by 50, but it seems to be static
b.position.y_position.controller.script = "if clem == true then 50 else -50"
)
-- the following returns a value of "undefined"
on ca.params.sld_blerp changed value do
(b.pos.z = ca.params.sld_blerp.value)
)
createDialog make 200 50
)

I’m screwing up somehow on these float_scripts… just can’t dynamically wire the custom atts to the object. Can’t even access the params slider from the rollout. Can anyone give me hand, please? I seem to have come down with a case of Dumb.

18 Replies

There’s something oddly liberating about being in the dark. I seem to be making some progress, but in which direction I’m not sure…

(
local obj, obj1, obj2, r
ca = attributes New
(
parameters main rollout:params
(
clutch type:#integer ui:btn_clutch default:1
diag type:#float ui:sld_diag range:[-100,100,1]
)
rollout params "Wire Toggle"
(
button btn_clutch "Clutch Button"
slider sld_diag "Diagonal Move" range:[-100,100,1]
on btn_clutch pressed do
(
if (classof obj1 == box) and (classof obj2 == box) then \
paramWire.disconnect obj1.rotation.controller[#Z_rotation]
paramWire.connect obj1.rotation.controller[#Z_rotation] \
obj2.rotation.controller[#Z_Rotation] ("Z_Rotation*"+clutch as string)
if clutch == 1 then clutch = 0 else clutch = 1
print clutch
)
 
on sld_diag changed value do
(
xx = $.pos.x
$.pos = [xx,diag,diag]
)
)
) 
rollout test "Clutch test"
(
button btn "Do It"
 
on btn pressed do
(
b1 = box()
b2 = box pos:[50,0,0]
custAttributes.add b1 ca
custAttributes.add b2 ca
obj =selected
print obj
obj = $
obj1 = b1
obj2 = b2
print b2.clutch
print b1.diag
)
)
createDialog test 200 50
)

Much of the above seems to work. The only thing that doesn’t (which, predictably, is the thing I’m after) is that the clutch won’t animate; actually, the clutch value itself responds to keyframes, but the paramWire it’s associated with doesn’t respond to keyframes. Anybody got some advice on this? Many thanks.

I’m not 100% sure, but because the custom attributes are been decleared within a local context, it might not be possible to address them from within the rollout’s context…alought to be honest, I would have thought it possible…(this is just my first glance response…I will look deeper when I have more time)

Shane

I had a quick look and seems to work fine for me. It creates two objects with a custom attribute with a slider and button. The slider effects their z position and the clucth button prints out some numbers…as far as I can tell anyway

Tested in max 9

Can you elaberate on your problem?

Shane

I’d sure appreciate you’re looking at it, Shane. As I said, in the second version everything seems to work except that the paramWire’s not keyable… even though its value is tied to the clutch attribute.

Our posts must’ve crossed. What I’m trying to achieve is an animatable on/off switch for the paramWire. After you’ve created the boxes, select one and click the “Clutch” button in the modify panel. The second box’s rotation will be slaved to the first box. Click again and the connection is broken. The problem is that the on/off function doesn’t work in an animation. With the boxes linked, animate the first box rotating. Half way through the animation, insert a keyframe switching off the link. When you replay there’s no linking in any of the frames.

I have recently tackled this problem, if I read your problem right. When you keyframe your custom attributes then scrub through, the buttons may be animated but the actions associated don’t react to the button states.

What I did to fix this was to create a “watcher” object. a small point helper hidden somewhere in the scene with a float script associated the height or size or some other attribute on the point. In the script controller I associated a variable with the custom attribute button I want to watch. When the button changes states I have the float script issue the code associated with the button state from the custom attribute definition.

I hope that all makes sense. I can put up a sample later if you’re interested.

Dan

Thank you, Dan. I had been headed toward the same line of thinking. If you don’t mind sharing how you coded the watcher I’d really appreciate it. Here’s the latest iteration of my routine…

(
local obj, obj1, obj2, r
ca = attributes New
(
parameters main rollout:params
(
clutch type:#integer ui:btn_clutch default:1
diag type:#float ui:sld_diag range:[-100,100,1]
)
rollout params "Wire Toggle"
(
button btn_clutch "Clutch Button"
slider sld_diag "Diagonal Move" range:[-100,100,1]
on btn_clutch pressed do
(
if (classof obj1 == box) and (classof obj2 == box) then \
paramWire.disconnect obj1.rotation.controller[#Z_rotation]
paramWire.connect obj1.rotation.controller[#Z_rotation] \
obj2.rotation.controller[#Z_Rotation] ("Z_Rotation*"+clutch as string)
if clutch == 1 then clutch = 0 else clutch = 1
print clutch
)
 
on sld_diag changed value do
(
xx = $.pos.x
$.pos = [xx,diag,diag]
)
)
) 
rollout test "Clutch test"
(
button btn "Do It"
 
on btn pressed do
(
b1 = box()
b2 = box pos:[50,0,0]
custAttributes.add b1 ca
custAttributes.add b2 ca
obj =selected
print obj
obj = $
obj1 = b1
obj2 = b2
-- new stuff: add a script-holding point
p = point()
fs = float_script()
fs.addNode "thisone" $Box01
p.position.X_position.controller = fs
fs.script = "if thisone.clutch == 0 then thisone.pos.z = 50 else thisone.pos.z = 0"
)
)
createDialog test 200 50
)

I’m wondering if the actual paramWiring can be left in the rollout, or if it has to be part of the float script. Also wondering if it’s possible to add a node to the float_list just by selecting it, or referencing the selected object somehow.

I also noticed some weird stuff when I tried animating with the AutoKey… http://www.e-nimation.com/turbosquid/f_sAnim/f_sAnim.htm . Gotta get back to some non-related deadlines right now, dammit. Thanks again.

1 Reply
 JHN
(@jhn)
Joined: 11 months ago

Posts: 0

To fix that you should put the actual code that does the operation in a


with animate off
(
   your code here...
)

That makes sure no keyframes get put on the tracks.
-Johan

Sweet! Thanks, Johan.

Sorry for the late response.

I didn’t study your code to intensly, so I’m not sure whether you want to disconnect and then reconnect wires based on the clutch button. You’ll have to fill in the script for the float script assigned to the axis tripod. Basically whatever you do within the if statement there, when the clutch button changes states, that code will be issued regardless of whether you set keys or scrub through the timeline. Also, I didn’t test this, but it should work.

The idea is basically:

 
-- add a boolean controller to the clutch button (true/1 or false/0)
$Box01.clutch.controller = boolean_float() 
 
-- create a point helper
watchObj = point size:5 name:"box01Watcher"
 
-- create a float script for the watcher
fs = float_script()
 
-- add the clutch button to the float script so it can be tracked
fs.addTarget "box01Watcher" $Box01.clutch.controller
 
-- add the float script to the watcher
watchObj.axistripod.controller = fs
 
-- add script to the new float script to do something based on the state of the clutch button
watchObj.axistripod.controller.script = "if (box01Watcher == 1) then
(
 Print "Box01 clutch button pressed"
-- YOUR WIRE DISCONNECT CODE HERE
)
else
(
 Print "Box01 clutch button depressed"
-- YOUR WIRE CONNECT CODE HERE?
 )
"

Page 1 / 2