Notifications
Clear all

[Closed] On-Off switch for wire parameter

Here’s a little routine to switch a wire parameter on and off:


rollout ewire "Engage/Disengage"
(
button btn_boxes "Make Boxes"
spinner spn_amt "Rotation Ratio: "
button btn_connect "Create Wire Parameter"
button btn_disre "Disengage/Reengage"
 
local b1, b2, a, v = 1
 
on btn_boxes pressed do
(
b1 = box()
b2 = box pos:[50,0,0]
)
 
on spn_amt changed value do
(a = spn_amt.value)
 
on btn_connect pressed do
(
paramWire.connect2way b1.rotation.controller[#Z_Rotation]\
b2.rotation.controller[#Z_Rotation] ("Z_Rotation/"+a as string + "*-1") \
("Z_Rotation*"+ a as string + "*-1")
b1.rotation.controller = rotation_list()
b1.rotation.controller.Available.controller = Euler_XYZ()
b2.rotation.controller = rotation_list()
b2.rotation.controller.Available.controller = Euler_XYZ()
)
 
on btn_disre pressed do
(
if v==1 then v=2 else v=1
b1.rotation.controller.setActive v
b2.rotation.controller.setActive v
) 
)
createDialog ewire 200 110

Question 1: This does work, but it seems like a bit of hack to me. Does anyone know of a more elegant solution?

Question 2: I’d like the value of v to change with the z_position of box2, rather than using a button. Something like…

if b2.pos.z != b1.pos.z then v=2 else v=1

But where would that line go? Many thanks.

2 Replies

I’d probably use a callback script to see if the object exists and then if the position has changed since last viewport draw.

Here’s the solution (or one solution, at least) to the on/off switch by object position…

(
box pos: [ 0,0,0] name: "Box01" wirecolor: Red
box pos: [50,0,0] name: "Box02" wirecolor: Blue
point() -- this could be a shape, an object or another type of helper
local a = 1
print a
sc = float_script()
sc.addNode "b1" $Box01
sc.addNode "b2" $Box02
$Point01.position.Y_position.controller = sc
sc.script = "if (b1.pos.z == b2.pos.z) then a = 1 else a = 2"
)

Deepest thanks to Steve Curley over at the Area forums for his able guidance.

Also, here’s a more streamlined variant on the first bit of code posted in this thread…

rollout ewire "Engage/Disengage"
(
button btn_boxes "Make Boxes"
spinner spn_amt "Rotation Ratio: " range:[0,50,1]
button btn_cd "Connect/Disconnect"
 
local b1, b2, p=paramWire, a=1, v=2
 
on btn_boxes pressed do
(
	 b1 = box()
	 b2 = box pos:[50,0,0]
)
 
on spn_amt changed value do
(a = spn_amt.value)
 
on btn_cd pressed do
(
	 if v==1 then v=2 else v=1 
	 if v==1 then p.connect2way b1.rotation.controller[#Z_Rotation]\
	 b2.rotation.controller[#Z_Rotation] ("Z_Rotation/"+a as string + "*-1") \
	 ("Z_Rotation*"+ a as string + "*-1") \
	 else p.disconnect2Way b1.rotation.controller.Z_Rotation.controller \
	 b2.rotation.controller.Z_Rotation.controller
) 
)
createDialog ewire 200 85

The original code is OK for connecting/disconnecting two objects, but if you’re linking a series of objects in a daisy-chain fashion, the increasing number of controllers rapidly turns into spaghetti.