[Closed] How to remove position_script()?
I want the centerPoint to stay in the meddle of the point01 and point02 when they are moved. To do this I use this code:
(
point01 = point wirecolor:red pos:[-100,0,0]
point02 = point wirecolor:green pos:[100,0,0]
centerPoint = point wirecolor:white
--
posScript = position_script()
posScript.addnode "point01" point01
posScript.addnode "point02" point02
posScript.script = "((point01.pos+point02.pos)/2.0)"
centerPoint.position.controller = posScript
)
What I need is:
- when I select point01 or point02, the position script will be applied to the centerPoint and the centerPoint will stay in the middle of the point01 and point02
- when I select the centerPoint the position_script will be “removed” and I can move the centerPoint without restrictions.
I found in the forum that position_script() cannot be removed, once it is added to the Track
How I can overcome this restriction?
P.S. I can do this with when construct, but I want to use the position_script… or something else
that was the wrong forum
for sure you can change any controller including position_script using a direct assignment as LO showed or replaceinstances.
but…
in you case i would make a setup with position_list, like:
delete objects
p1 = point name:"p1" pos:[-20,0,0]
p2 = point name:"p1" pos:[20,0,0]
p0 = dummy name:"p0" pos:[0,0,0]
p = p0.pos.controller = position_script()
p.addobject "p1" (NodeTransformMonitor node:p1)
p.addobject "p2" (NodeTransformMonitor node:p2)
p.setexpression "(p1.pos + p2.pos)/2"
p = p0.pos.controller = position_list()
p.available.controller = createinstance Position_XYZ
p.active = p.count
p.weights[1].controller = Boolean_Float()
p.weights[2].controller = Boolean_Float()
paramWire.connect p[#weights][#Weight__Position_XYZ] p[#weights][#Weight__Position_Script] "if Weight__Position_XYZ > 0 then 0 else 1"
p.weights[2].value = 0
so you can control the weight of second position controller to toggle the way of animation. it’s easy.
the more interesting thing is how to make the weight controller not keyable. that’s the challenge, and i will not show it yet
lo, Denis, thank you.
About this:
I found in the forum that position_script() cannot be removed, once it is added to the Track
which also is not correct… you can’t delete (set to undefined) the subanim’s controller.
Also, once you have assigned a controller to a track, either directly or by animating it, you cannot remove the controller…you can only replace it with another controller. In other words, you cannot successfully assigned the value of “undefined” to a track once a controller has existed on that track.
That is 100% correct and that’s exactly what we’re doing.
Denis, I will not use animation. I need to move one object and other to stay in the proper position depending of the movement. I tried with when transform construct, but sometimes, moving one object move other objects, that have to stay in place. Link the centerPoint to point01 or point02 also is not a solution in this case.
Another question.
Why this code not work?
(
global rol_test
try(destroyDialog rol_test)catch()
rollout rol_test ""
(
local pXplus = undefined
local pXminus = undefined
local pYplus = undefined
local pYminus = undefined
local pZplus = undefined
local pZminus = undefined
button btn_start "Start"
function AddPositionScript centerObj obj01 obj02 lock:#xyz =
(
posScript = position_script()
posScript.addnode "obj01" obj01
posScript.addnode "obj02" obj02
case lock of
(
(#x): (posScript.script = "[((obj01.pos.x+obj02.pos.x)/2.0),centerObj.pos.y,centerObj.pos.z]")
(#xy): (posScript.script = "[((obj01.pos.x+obj02.pos.x)/2.0),((obj01.pos.y+obj02.pos.y)/2.0),centerObj.pos.z]")
(#xyz): (posScript.script = "((obj01.pos+obj02.pos)/2.0)")
)
centerObj.position.controller = posScript
)
function ObjPosChanged =
(
deleteAllChangeHandlers id:#ObjPosChangedID
if selection.count == 1 do
(
case selection[1] of
(
(pXplus):
(
-- THIS NOT WORK
for m in #(pYplus,pYminus,pZplus,pZminus) do
AddPositionScript m pXplus pXminus lock:#x
-- THIS WORK
-- for m in #(pYplus,pYminus,pZplus,pZminus) do
-- AddPositionScript m pXplus pXminus lock:#xyz
)
)
)
)
on btn_start pressed do
(
pXplus = point name:"pXplus" pos:[50,0,25]
pXminus = point name:"pXminus" pos:[-50,0,25]
pYplus = point name:"pYplus" pos:[0,50,25]
pYminus = point name:"pYminus" pos:[0,-50,25]
pZplus = point name:"pZplus" pos:[0,0,0]
pZminus = point name:"pZminus" pos:[0,0,50]
deleteAllChangeHandlers id:#ObjPosChangedID
callbacks.removescripts id:#ObjPosChangedID
callbacks.addscript #selectionSetChanged "rol_test.ObjPosChanged()" id:#ObjPosChangedID
)
on rol_test close do
(
deleteAllChangeHandlers id:#ObjPosChangedID
callbacks.removescripts id:#ObjPosChangedID
)
)
createdialog rol_test
)
I tried this
posY = centerObj.pos.y
posZ = centerObj.pos.z
posScript.script = "[((obj01.pos.x+obj02.pos.x)/2.0),posY,posZ ]"
but the script not works.
I want to add position_script only for X, Y, Z, XY, XZ, ZY axis. Is this possible, or position_script works with XYZ axies only?
"[((obj01.pos.x+obj02.pos.x)/2.0),centerObj.pos.y,centerObj.pos.z]"
it has two problems:
#1 centerObj has to be a name of a script_controller’s target
#2 if you fix #1 it will make anyway self-reference dependency
the way how you do (shown above) is correct. but the better way is to assign float_script controller to specific X-Y-Z float controller depending on axis that you want to constraint.
Adding this seems to solve the problem(for now)
posScript.addConstant "centerObjPosY" (centerObj.pos.y)
posScript.addConstant "centerObjPosZ" (centerObj.pos.z)
case lock of
(
(#x): (posScript.script = "[((obj01.pos.x+obj02.pos.x)/2.0),centerObjPosY,centerObjPosZ]")
(#xy): (posScript.script = "[((obj01.pos.x+obj02.pos.x)/2.0),((obj01.pos.y+obj02.pos.y)/2.0),centerObj.pos.z]")
(#xyz): (posScript.script = "((obj01.pos+obj02.pos)/2.0)")
)
Is this correct?
(
global rol_test
try(destroyDialog rol_test)catch()
rollout rol_test ""
(
local pXplus = undefined
local pXminus = undefined
local pYplus = undefined
local pYminus = undefined
local pZplus = undefined
local pZminus = undefined
button btn_start "Start"
function AddPositionScript centerObj obj01 obj02 lock:#xyz =
(
posScript = float_script()
posScript.addNode "obj01" obj01
posScript.addNode "centerObj" centerObj
posScript.addNode "obj02" obj02
posScript.script = "centerObj.pos.x = ((obj01.pos.x + obj02.pos.x)/2.0)"
centerObj.position.x_position.controller = posScript
)
function ObjPosChanged =
(
deleteAllChangeHandlers id:#ObjPosChangedID
if selection.count == 1 do
(
case selection[1] of
(
(pXplus):
(
for m in #(pYplus,pYminus,pZplus,pZminus) do
AddPositionScript m pXplus pXminus lock:#x
)
)
)
)
on btn_start pressed do
(
pXplus = point name:"pXplus" pos:[50,0,25]
pXminus = point name:"pXminus" pos:[-50,0,25]
pYplus = point name:"pYplus" pos:[0,50,25]
pYminus = point name:"pYminus" pos:[0,-50,25]
pZplus = point name:"pZplus" pos:[0,0,0]
pZminus = point name:"pZminus" pos:[0,0,50]
deleteAllChangeHandlers id:#ObjPosChangedID
callbacks.removescripts id:#ObjPosChangedID
callbacks.addscript #selectionSetChanged "rol_test.ObjPosChanged()" id:#ObjPosChangedID
)
on rol_test close do
(
deleteAllChangeHandlers id:#ObjPosChangedID
callbacks.removescripts id:#ObjPosChangedID
)
)
createdialog rol_test
)
the assign function has to look like:
(
posScript = float_script()
posScript.addNode "obj01" obj01
posScript.addNode "obj02" obj02
posScript.setexpression "(obj01.pos.x + obj02.pos.x)/2.0"
centerObj.position.x_position.controller = posScript
)
also don’t use direct assignment of the script (controller.script = …). Use .SetExpression. Sometimes the direct assignment doesn’t automatically update the controller.
If I want to constraint on XY axis the float_script() does not work, or I do not know how to use it.
delete objects
p1 = point name:"p1" pos:[-20,0,0]
p2 = point name:"p1" pos:[20,0,0]
p0 = dummy name:"p0" pos:[0,0,0]
-- XY constraint:
p = p0.pos.controller = position_xyz()
x = p[1].controller = float_script()
x.addobject "p1" (NodeTransformMonitor node:p1)
x.addobject "p2" (NodeTransformMonitor node:p2)
x.setexpression "(p1.pos.x + p2.pos.x)/2"
y = p[2].controller = float_script()
y.addobject "p1" (NodeTransformMonitor node:p1)
y.addobject "p2" (NodeTransformMonitor node:p2)
y.setexpression "(p1.pos.y + p2.pos.y)/2"
Is it possible position_xyz()/float_script() to work in local coordinates of the objects?
The example below work only with world coordinates. If I rotate the objects, then select $pXplus and move it in local space the rest of the objects move in the world space.
This addition does not work:
x.addConstant "centerObjTM" (centerObj.transform)
x.setexpression "in coordsys centerObjTM (obj01.pos.x + obj02.pos.x)/2"
(
global rol_test
try(destroyDialog rol_test)catch()
rollout rol_test ""
(
local pXplus = undefined
local pXminus = undefined
local pYplus = undefined
local pYminus = undefined
local pZplus = undefined
local pZminus = undefined
button btn_start "Start"
function AddPositionScript centerObj obj01 obj02 lock:#xyz =
(
p = centerObj.pos.controller = position_xyz()
x = p[1].controller = float_script()
x.addobject "obj01" (NodeTransformMonitor node:obj01)
x.addobject "obj02" (NodeTransformMonitor node:obj02)
x.addConstant "centerObjTM" (centerObj.transform)
x.setexpression "in coordsys centerObjTM (obj01.pos.x + obj02.pos.x)/2"
)
function ObjPosChanged =
(
deleteAllChangeHandlers id:#ObjPosChangedID
if selection.count == 1 do
(
case selection[1] of
(
(pXplus):
(
for m in #(pYplus,pYminus,pZplus,pZminus) do
AddPositionScript m pXplus pXminus lock:#x
)
)
)
)
on btn_start pressed do
(
pXplus = point name:"pXplus" pos:[50,0,25]
pXminus = point name:"pXminus" pos:[-50,0,25]
pYplus = point name:"pYplus" pos:[0,50,25]
pYminus = point name:"pYminus" pos:[0,-50,25]
pZplus = point name:"pZplus" pos:[0,0,0]
pZminus = point name:"pZminus" pos:[0,0,50]
deleteAllChangeHandlers id:#ObjPosChangedID
callbacks.removescripts id:#ObjPosChangedID
callbacks.addscript #selectionSetChanged "rol_test.ObjPosChanged()" id:#ObjPosChangedID
)
on rol_test close do
(
deleteAllChangeHandlers id:#ObjPosChangedID
callbacks.removescripts id:#ObjPosChangedID
)
)
createdialog rol_test
)
i don’t understand what you want to get.
post a picture that shows how the nodes should move, it might make the issue clearer.