Notifications
Clear all

[Closed] maxscript changehandler local transformations

Hello,

You see I have this weird problem with the change handler.


deleteAllChangeHandlers()
when transform #($point001,$point002) changes do
(
p1 = $Point001
p2 = $Point002
perc = 40.0 –%
dist = distance $point001 $point002
elevate = dist * (perc/100)
format “% ” elevate

v1 = normalize (p2.pos-p1.pos)
$Pyramid001.dir = v1
$Pyramid001.pos = p1.pos
in coordsys local $Pyramid001.pos.z = elevate
format "wthefu


)

Basicly the script is meant to keep the pyramid between the two points at given length and ‘lookat’ point002 via vector direction.

The problem is that when I’m trying to move the pyramid via local coordinate system the pyramid is not following the position I’ve set it for. However if I move the pyramid in viewport myself it gets repositioned to the correct location yet everytime the points are changed, and the changehandler gets invoked again, the pyramid gets the wrong position like if the handler is skipping the local coordsys line of code until I touch the object myself.

When Compiling the code without the “when transform changes” handler the code works perfectly fine.

Any idea what could be causing the problem? Maybe I’ve missed something trivial.

Max 2017

5 Replies

is any specific reason to use ‘when context’ instead of script controllers for example?

Hi,

Well in script controllers I dont see the highlights of the code.
Yet I think change handlers should work noneless

‘when construct’ solution is NOT animatable and NOT renderable.

the preferred way is to use controllers… script or expression.

for example:

delete objects
d = dummy name:#source

p0 = point name:#start pos:[0,0,0] wirecolor:orange
p1 = point name:#end pos:[20,0,0] wirecolor:yellow

c = d.controller = transform_script()
c.addnode "start" p0
c.addnode "end" p1

c.setexpression "translate (matrixfromnormal (normalize (p1.pos - p0.pos))) (0.25*p0.pos + 0.75*p1.pos)"


  

just run the code

Okay, thanks.

It works great, however… what “when construct” is used for then? If its not used for animation nor rendering.

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

it’s more like a real-time or user-interface solution. some sort of a system hook or callback…