Notifications
Clear all

[Closed] A couple questions about when construct usage

Okay, so say I am trying to make something happen whenever any object in the scene is moved/rotated/scaled.
If I am working with a single selected object that has no children, I can use this:

when transform objects change id:#transform handleAt:#redrawViews do
(
format "Transform changed
"
)

And it will tell me every time I adjust that object.

However, if I have 2 or more objects selected, or if I am adjusting an object that has other objects parented to it, the construct will run separately for every single one of them affected.

I’m aware that I can attach a separate construct to each object in the scene, but I want to know if there is any way to prevent multiple occurrences on a scene-wide check for transform changes.

I also have another question, whether the above is doable or not. Is there any way to make a when construct identify the object it is operating on?

19 Replies

of course if you know the node which you want to monitor it’s better to construct only this node.
if you want to listen all nodes transform changes it’s probably better to use the NodeEventCallback mechanism by checking #controllerOtherEvent

That’s actually what I’ve been doing up to now, and may continue to do so. I’m just looking at all the possibilities.

Okay, so… when I run the following:

delete objects
deleteAllChangeHandlers id:#test

for i = 1 to 5 do
	b = box pos:[i*10,i*10,i*10]

for o in objects where classOf o == box do
(
	when transform o changes id:#test handleAt:#redrawViews do
	(
		if not mouse.buttonStates[1] do format "$% transform changed
" o.name
	)
)

I get the error

-- Compile error: No outer local variable references permitted here:  o
--  In line: 		if not mouse.buttonStates[1] do format "$% transform changed
" o.

Now, when working with the delete form, you get “when o deleted id:#id obj do…” Instead of working with o as a local variable, is there ANY way to similarly force the construct to recognize the node it is operating on??

1 Reply
(@denist)
Joined: 2 years ago

Posts: 0

you can do it as:


 for o in objects where classOf o == box do
 (
 	when transform o changes id:#test handleAt:#redrawViews o do
 	(
 		if not mouse.buttonStates[1] do format "$% transform changed
" o.name
 	)
 )
 

but better is:


objs = for obj in objects where classOf obj == box collect obj
 when transform objs change id:#test handleAt:#redrawViews obj do
 (
 	if not mouse.buttonStates[1] do format "$% transform changed
" obj.name
 )
 

Trying to get this working with my ca script. In this case obj is returning a value of “ReferenceTarget:ParamBlock2”

I have absolutely no idea what I’m supposed to do with that and the documentation is pretty much useless on the subject.

Any way to get it to point to the referenced nodes?

(Also, this script still crashes Max after 6 or 7 times reloading it. Am I doing something wrong?)

delete objects
deleteAllChangeHandlers id:#tf

ca = attributes ca
(
	parameters ca rollout:ca
	(
		nodes type:#nodeTab tabSize:0 tabSizeVariable:on

		on nodes tabChanged do
		(
			when transform this.nodes change id:#tf handleAt:#redrawViews obj do
			(
				format "obj: %
" obj
			) -- end construct (transform)
		)
	) -- end parameters

	rollout ca "ca"
	(
	)
) -- end ca

theSphere = sphere()
custAttributes.add theSphere ca #unique
theSphere.nodes = #()

for i = 1 to 5 do
(
	b = box pos:[i*10,i*10,i*10]
	append theSphere.nodes b
)

when theSphere deleted id:#del obj do
(
	nodes = obj.nodes
	for i = nodes.count to 1 by -1 where nodes[i] != undefined do	delete nodes[i]
)

I haven’t been able to figure out what I’m supposed to do.

when parameters nodes change handleAt:#redrawViews obj do
format "obj: %
" obj

always returns

obj: ReferenceTarget:ParamBlock2

I don’t know how to get access to anything using that. ParamBlock2 has no name, id, properties methods, or anything that I can figure out how to access. All I can get from it is its class, “ParamBlock2ParamBlock2”.

Everything I’ve been able to find online relating to ParamBlock2 refers strictly to SDK usage. Since custom attributes work along the same lines as scripted plugins I can see where that might be the case, but there is absolutely nothing I can find showing how to get at it from Maxscript.

In your CA… nodes is an array of nodes. So to see if a node’s transform has changed don’t you need to index into nodes? Just my uneducated guess.

So how do I do that? I’d considered the possibility that obj was somehow referring to the nodes array, or the custom attribute, or the owner of said attribute, but it has no attributes, no parameters, no index or anything that I am able to get at.

How do I paramblock2?

Try a for loop to iterate thru your nodes array… and use the index operator: nodes[i]

Where do I do that, how do I call it, and how will that give me what I need?

I’ve been trying to get this figured out for a week and my brain is fried. I’m sure what you’re saying has some basis in something but right now I’m at the point where nothing makes any sense at all.

Page 1 / 2