Notifications
Clear all

[Closed] Script Controllers to be executed when certain objects exist?

The code below works as I want, but when the plane is deleted max gives me an error. If 1000 objects are attached to the plane there will be 1000 error messages.
The isValidNode checking not helps.
What I have to do, so when the position script to be executed only when the plane exist.


(
	objToAttach = $Teapot001
	curO = $Plane001
	script_controller = objToAttach.pos.controller = position_script ()
	script_controller.AddNode "miauuRefObj" curO
	posCmdStr = "if isValidNode miauuRefObj do (miauuRefObj.pos + [100,100,100])"
	script_controller.script = posCmdStr	
)

9 Replies

how is about to use “if not isdeleted” check?

edited… it doesn’t work.

simply use “if thing != undefined”

1 Reply
(@miauu)
Joined: 11 months ago

Posts: 0

This not works:


(
	objToAttach = $Teapot001
	curO = $Plane001
	script_controller = objToAttach.pos.controller = position_script ()
	script_controller.AddNode "miauuRefObj" curO
	posCmdStr = "format \"miauuRefObj: % 
\"  miauuRefObj
"
	posCmdStr += "if miauuRefObj != undefined do (miauuRefObj.pos + [100,100,100])"
	script_controller.script = posCmdStr	
)

In the listener is printed:


miauuRefObj: undefined 
>> MAXScript Script Controller Exception:
-- Unable to convert: undefined to type: Point3 <<

miauuRefObj is undefined but this not stops Max to execute the “do” statement.

position_script has to return point3 anyway… so the expression has to be:

"if miauuRefObj != undefined then (miauuRefObj.pos + [100,100,100]) else [0,0,0]"
2 Replies
(@miauu)
Joined: 11 months ago

Posts: 0

It works. Thank you.
But, the [0,0,0] will move the attached object to the world [0,0,0] when the miauuRefObj is deleted. I want it to stay in place.
The attached object can’t be moved. I want to move it.
Maybe I have to use #nodePreDelete / #nodePostDelete callbacks ato avoid such a behavior(which is expected) of the miauuRefObject?

(@denist)
Joined: 11 months ago

Posts: 0

using callbacks is wrong idea. you can create static value of the same position_script and put there last evaluated position. if your driver not is deleted use that stored value

what are 1000 nodes doing being attached? maybe a using of position_script is not right ides

2 Replies
(@miauu)
Joined: 11 months ago

Posts: 0

The 1000 objects must be attached to 1000 faces. When a face is moved, the attached object must move with it.

I will try that. Thank you.

(@denist)
Joined: 11 months ago

Posts: 0

attachment controller is not good?

Is good, but

  • some of the attached objects will be rotated without changing their position
  • some of the objects will be scaled, but not rotated when the face is scaled/rotated
    I’ve use position, rotation and scale scripts for different cases and the only problem that I have is when the surface objects is deleted.